blob: 0ca4f84fb155c41c7917fd491394a2727c688c36 [file] [log] [blame]
Adrien Destugues6b23e9a2013-03-09 14:45:45 +00001/* 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
Adrien Destugues6b23e9a2013-03-09 14:45:45 +00006#include <stdint.h>
7#include <stdio.h>
8#include <stdlib.h>
Adrien Destugues69ec89a2014-08-09 21:07:35 +00009#include <string.h>
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000010
Adrien Destugues5095d402015-03-13 21:12:59 +000011#include "decb.cpp"
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000012
13int main(int argc, char* argv[])
14{
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000015 if (argc < 2)
16 {
17 fprintf(stderr, "%s file.bin\n", argv[0]);
18 return 1;
19 }
20
Adrien Destugues5095d402015-03-13 21:12:59 +000021 FILE* f1, * f2;
22 uint8_t i = 0;
23 DECB_Chunk h;
24
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000025 f1 = fopen(argv[1], "rb");
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000026 char* buf = (char*)malloc(strlen(argv[1] + 3));
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000027
Adrien Destugues5095d402015-03-13 21:12:59 +000028 while(DECB_ReadChunk(f1, h))
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000029 {
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000030 printf("Type: %02x - Size: %04x - Load: %04x\n", h.type, h.length, h.addr);
31
32 sprintf(buf, "%s.%02x", argv[1], i++);
33 f2 = fopen(buf, "wb");
34
Adrien Destugues5095d402015-03-13 21:12:59 +000035 fwrite(&h.data[0], h.length, 1, f2);
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000036
Adrien Destugues6b23e9a2013-03-09 14:45:45 +000037 fclose(f2);
38 }
39
40 free(buf);
41
42 fclose(f1);
43
44 return 0;
45}