FreeCalypso > hg > freecalypso-reveng
comparison factdiff.c @ 52:103d996ed2d5
factdiff utility written
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 25 Jul 2013 17:06:23 +0000 |
parents | |
children | 00dedefbdfd1 |
comparison
equal
deleted
inserted
replaced
51:e516128db432 | 52:103d996ed2d5 |
---|---|
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; | |
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\n", cstart, off-1, | |
62 state ? "varying" : "constant"); | |
63 } | |
64 } | |
65 | |
66 main(argc, argv) | |
67 char **argv; | |
68 { | |
69 char **ap; | |
70 | |
71 if (argc < 3) { | |
72 fprintf(stderr, "usage: %s specimen0 specimen1 ...\n", argv[0]); | |
73 exit(1); | |
74 } | |
75 read_specimen_file(argv[1], specimen0); | |
76 for (ap = argv + 2; *ap; ap++) | |
77 process_comp_specimen(*ap); | |
78 output(); | |
79 exit(0); | |
80 } |