source: thomson/tools/binxploder.cpp@ 69ec89a

main
Last change on this file since 69ec89a was 69ec89a, checked in by Adrien Destugues <pulkomandy@…>, 10 years ago

Add missing include.

git-svn-id: svn://localhost/thomson@54 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/* BinXPloder - split a Thomson binary file in separate sections
2 * Copyright 2013, Adrien Destugues <pulkomandy@pulkomandy.tk>
3 * This file is distributed under the terms of the MIT Licence.
4 */
5
6#include <arpa/inet.h>
7
8#include <stdint.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13struct __attribute__((packed)) Header {
14 uint8_t type;
15 uint16_t length;
16 uint16_t addr;
17};
18
19int main(int argc, char* argv[])
20{
21 FILE* f1, * f2;
22 Header h;
23
24 if (argc < 2)
25 {
26 fprintf(stderr, "%s file.bin\n", argv[0]);
27 return 1;
28 }
29
30 f1 = fopen(argv[1], "rb");
31
32 char* buf = (char*)malloc(strlen(argv[1] + 3));
33 uint8_t i;
34
35 while(fread(&h, sizeof(h), 1, f1))
36 {
37 // 6809 is little endian, take that into account...
38 h.length = ntohs(h.length);
39 h.addr = ntohs(h.addr);
40
41 printf("Type: %02x - Size: %04x - Load: %04x\n", h.type, h.length, h.addr);
42
43 sprintf(buf, "%s.%02x", argv[1], i++);
44 f2 = fopen(buf, "wb");
45
46 char* b2 = (char*)malloc(h.length);
47 fread(b2, h.length, 1, f1);
48 fwrite(b2, h.length, 1, f2);
49
50 free(b2);
51 fclose(f2);
52 }
53
54 free(buf);
55
56 fclose(f1);
57
58 return 0;
59}
Note: See TracBrowser for help on using the repository browser.