source: thomson/tools/binxploder.cpp@ 6b23e9a

main
Last change on this file since 6b23e9a was 6b23e9a, checked in by Adrien Destugues <pulkomandy@…>, 11 years ago

Add binxploder, a tool to extract raw data from Thomson chunked binary files.

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

  • Property mode set to 100644
File size: 1.0 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
12struct __attribute__((packed)) Header {
13 uint8_t type;
14 uint16_t length;
15 uint16_t addr;
16};
17
18int main(int argc, char* argv[])
19{
20 FILE* f1, * f2;
21 Header h;
22
23 if (argc < 2)
24 {
25 fprintf(stderr, "%s file.bin\n", argv[0]);
26 return 1;
27 }
28
29 f1 = fopen(argv[1], "rb");
30
31 char* buf = (char*)malloc(strlen(argv[1] + 3));
32 uint8_t i;
33
34 while(fread(&h, sizeof(h), 1, f1))
35 {
36 // 6809 is little endian, take that into account...
37 h.length = ntohs(h.length);
38 h.addr = ntohs(h.addr);
39
40 printf("Type: %02x - Size: %04x - Load: %04x\n", h.type, h.length, h.addr);
41
42 sprintf(buf, "%s.%02x", argv[1], i++);
43 f2 = fopen(buf, "wb");
44
45 char* b2 = (char*)malloc(h.length);
46 fread(b2, h.length, 1, f1);
47 fwrite(b2, h.length, 1, f2);
48
49 free(b2);
50 fclose(f2);
51 }
52
53 free(buf);
54
55 fclose(f1);
56
57 return 0;
58}
Note: See TracBrowser for help on using the repository browser.