FreeCalypso > hg > freecalypso-reveng
view miscprog/ftmdump.c @ 264:e4a596bbb2bf
dsample-fw-disasm: ARMIO functions located
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 18 Jan 2018 05:39:53 +0000 |
parents | 9f2e0c34fe33 |
children |
line wrap: on
line source
/* * This program parses the record structure in Compal's FTM sector (or at least * that's what I *think* it is called) and dumps each record in hex for further * human analysis. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> char *infname; FILE *inf; u_char header[8]; u_char endmarker[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned hdr_words[4]; main(argc, argv) char **argv; { if (argc < 2 || argc > 3) { fprintf(stderr, "usage: %s binfile [offset]\n", argv[0]); exit(1); } infname = argv[1]; inf = fopen(infname, "r"); if (!inf) { perror(infname); exit(1); } if (argc == 3) fseek(inf, strtoul(argv[2], 0, 0), SEEK_SET); for (;;) { fread(header, 1, 8, inf); if (!bcmp(header, endmarker, 8)) break; process_record(); } exit(0); } process_record() { u_char readbuf[16]; int pos, chunk, i, c; for (i = 0; i < 4; i++) hdr_words[i] = header[i*2] | (header[i*2+1] << 8); printf("%04X %04X %04X %04X:\n\n", hdr_words[0], hdr_words[1], hdr_words[2], hdr_words[3]); for (pos = 0; pos < hdr_words[3]; pos += chunk) { chunk = hdr_words[3] - pos; if (chunk > 16) chunk = 16; fread(readbuf, 1, chunk, inf); printf("%04X:", pos); for (i = 0; i < 16; i++) { if (i == 0 || i == 8) putchar(' '); if (i < chunk) printf(" %02X", readbuf[i]); else fputs(" ", stdout); } fputs(" ", stdout); for (i = 0; i < chunk; i++) { c = readbuf[i]; if (c < ' ' || c > '~') c = '.'; putchar(c); } putchar('\n'); } putchar('\n'); }