FreeCalypso > hg > freecalypso-reveng
comparison miscprog/factdiff.c @ 129:597143ba1c37
miscellaneous C programs moved out of the top level directory
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 06 Apr 2014 20:20:39 +0000 |
parents | factdiff.c@00dedefbdfd1 |
children |
comparison
equal
deleted
inserted
replaced
128:03f8a618689e | 129:597143ba1c37 |
---|---|
1 /* | |
2 * The 64 KiB "factory block" at the end of the 2nd flash chip select on | |
3 * Pirelli DP-L10 phones is believed to contain juicy info (IMEI and RF | |
4 * calibration data), but the format is yet to be cracked. | |
5 * | |
6 * This program compares Pirelli factory block images that have been read | |
7 * out of several phones, seeking to determine which bytes are always the | |
8 * same and which bytes change from specimen to specimen. | |
9 * | |
10 * Written by Spacefalcon the Outlaw. | |
11 */ | |
12 | |
13 #include <sys/types.h> | |
14 #include <sys/file.h> | |
15 #include <stdio.h> | |
16 #include <stdlib.h> | |
17 | |
18 u_char specimen0[65536]; | |
19 char is_diff[65536]; | |
20 | |
21 read_specimen_file(filename, buf) | |
22 char *filename; | |
23 u_char *buf; | |
24 { | |
25 int fd, cc; | |
26 | |
27 fd = open(filename, O_RDONLY); | |
28 if (fd < 0) { | |
29 perror(filename); | |
30 exit(1); | |
31 } | |
32 cc = read(fd, buf, 65536); | |
33 close(fd); | |
34 if (cc != 65536) { | |
35 fprintf(stderr, "%s: unable to read 64 KiB\n", filename); | |
36 exit(1); | |
37 } | |
38 } | |
39 | |
40 process_comp_specimen(filename) | |
41 char *filename; | |
42 { | |
43 u_char this_spec[65536]; | |
44 int i; | |
45 | |
46 read_specimen_file(filename, this_spec); | |
47 for (i = 0; i < 65536; i++) | |
48 if (this_spec[i] != specimen0[i]) | |
49 is_diff[i] = 1; | |
50 } | |
51 | |
52 output() | |
53 { | |
54 int off, state, cstart, num; | |
55 | |
56 for (off = 0; off < 65536; ) { | |
57 state = is_diff[off]; | |
58 cstart = off; | |
59 while (off < 65536 && is_diff[off] == state) | |
60 off++; | |
61 printf("%04X-%04X: %s", cstart, off-1, | |
62 state ? "varying" : "constant"); | |
63 if (state) { | |
64 num = off - cstart; | |
65 printf(" (%d byte%s)", num, num != 1 ? "s" : ""); | |
66 } | |
67 putchar('\n'); | |
68 } | |
69 } | |
70 | |
71 main(argc, argv) | |
72 char **argv; | |
73 { | |
74 char **ap; | |
75 | |
76 if (argc < 3) { | |
77 fprintf(stderr, "usage: %s specimen0 specimen1 ...\n", argv[0]); | |
78 exit(1); | |
79 } | |
80 read_specimen_file(argv[1], specimen0); | |
81 for (ap = argv + 2; *ap; ap++) | |
82 process_comp_specimen(*ap); | |
83 output(); | |
84 exit(0); | |
85 } |