source: thomson/tools/binxploder.cpp@ 2366419

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

binxploder: allow to list only, without dumping to file.

git-svn-id: svn://localhost/thomson@67 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 <stdint.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10
11#include "decb.cpp"
12
13int main(int argc, char* argv[])
14{
15 bool listOnly = false;
16
17 if (argc < 2 || strcmp(argv[1], "--help") == 0)
18 {
19 fprintf(stderr,
20 "%s file.bin [-l]\n(-l: list only, don't write sections)\n",
21 argv[0]);
22 return 1;
23 }
24
25 if (argc > 2)
26 listOnly = true; // FIXME use getopt or something
27
28 FILE* f1, * f2;
29 uint8_t i = 0;
30 DECB_Chunk h;
31 char* buf = NULL;
32
33 f1 = fopen(argv[1], "rb");
34
35 if (f1 < 0)
36 {
37 perror("Could not open input file");
38 exit(-1);
39 }
40
41 if (!listOnly)
42 buf = (char*)malloc(strlen(argv[1] + 3));
43
44 while(DECB_ReadChunk(f1, h))
45 {
46 printf("Type: %02x - Size: %04x - %s: %04x\n", h.type, h.length,
47 h.type == 0xFF ? "Exec" : "Load", h.addr);
48
49 if (!listOnly)
50 {
51 sprintf(buf, "%s.%02x", argv[1], i++);
52 f2 = fopen(buf, "wb");
53
54 fwrite(&h.data[0], h.length, 1, f2);
55
56 fclose(f2);
57 }
58 }
59
60 free(buf);
61 fclose(f1);
62 return 0;
63}
Note: See TracBrowser for help on using the repository browser.