1 /* generates hex code from game binary
3 * (C) 2018 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 int main(int argc, char *argv[])
29 fprintf(stderr, "Usage: %s <binary> <souce code> <array name>\n", argv[0]);
33 ifp = fopen(argv[1], "r");
35 fprintf(stderr, "Failed to open input file: %s\n", argv[1]);
38 ofp = fopen(argv[2], "w");
40 fprintf(stderr, "Failed to open output file: %s\n", argv[2]);
44 fprintf(ofp, "\n#include <stdint.h>\n");
45 fprintf(ofp, "\n/* Data is stored as 'big endian' and must be converted to host machine's endianess. */\n");
46 fprintf(ofp, "const uint32_t %s[] = {", argv[3]);
47 while ((a = fgetc(ifp)) != EOF) {
51 if (b == EOF || c == EOF || d == EOF) {
52 fprintf(stderr, "Short read of input file. Input file's size must be a multiple of 4!\n");
57 fprintf(ofp, "0x%02x%02x%02x%02x,", a, b, c, d);
60 fprintf(ofp, "\n};\n\n");
61 fprintf(ofp, "int %s_size = %d;\n\n", argv[3], n);