FreeCalypso > hg > freecalypso-reveng
comparison miscprog/cinitdump.c @ 268:e493fcff28ab
cinitdump program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 19 Jan 2018 06:19:59 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
267:ace3136d0601 | 268:e493fcff28ab |
---|---|
1 /* | |
2 * This program dumps the cinit section records from a firmware image | |
3 * sans symbols, given just the cinit start address and knowing the | |
4 * record structure. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 | |
11 FILE *inf; | |
12 u_long offset; | |
13 | |
14 u_long | |
15 get_word() | |
16 { | |
17 u_char bytes[4]; | |
18 u_long word; | |
19 | |
20 fread(bytes, 1, 4, inf); | |
21 word = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); | |
22 printf("%8lx:\t%08lx\n", offset, word); | |
23 offset += 4; | |
24 return word; | |
25 } | |
26 | |
27 main(argc, argv) | |
28 char **argv; | |
29 { | |
30 u_long len, count; | |
31 | |
32 if (argc != 3) { | |
33 fprintf(stderr, "usage: %s filename start-addr\n", argv[0]); | |
34 exit(1); | |
35 } | |
36 inf = fopen(argv[1], "r"); | |
37 if (!inf) { | |
38 perror(argv[1]); | |
39 exit(1); | |
40 } | |
41 offset = strtoul(argv[2], 0, 0); | |
42 fseek(inf, offset, SEEK_SET); | |
43 | |
44 for (;;) { | |
45 len = get_word(); | |
46 if (!len) | |
47 break; | |
48 len = (len + 3) & ~3; | |
49 get_word(); /* bss address */ | |
50 for (count = 0; count < len; count += 4) | |
51 get_word(); | |
52 putchar('\n'); | |
53 } | |
54 exit(0); | |
55 } |