FreeCalypso > hg > freecalypso-reveng
changeset 52:103d996ed2d5
factdiff utility written
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 25 Jul 2013 17:06:23 +0000 |
parents | e516128db432 |
children | 00dedefbdfd1 |
files | .hgignore Makefile factdiff.c |
diffstat | 3 files changed, 83 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Wed Jul 24 21:52:09 2013 +0000 +++ b/.hgignore Thu Jul 25 17:06:23 2013 +0000 @@ -2,6 +2,7 @@ \.[oa]$ +^factdiff$ ^mokosrec2bin$ ^mpffs/mpffs-cat$
--- a/Makefile Wed Jul 24 21:52:09 2013 +0000 +++ b/Makefile Thu Jul 25 17:06:23 2013 +0000 @@ -1,12 +1,13 @@ CC= gcc CFLAGS= -O2 -PROGS= mokosrec2bin +PROGS= factdiff mokosrec2bin all: ${PROGS} ${PROGS}: ${CC} ${CFLAGS} -o $@ $@.c +factdiff: factdiff.c mokosrec2bin: mokosrec2bin.c clean:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/factdiff.c Thu Jul 25 17:06:23 2013 +0000 @@ -0,0 +1,80 @@ +/* + * The 64 KiB "factory block" at the end of the 2nd flash chip select on + * Pirelli DP-L10 phones is believed to contain juicy info (IMEI and RF + * calibration data), but the format is yet to be cracked. + * + * This program compares Pirelli factory block images that have been read + * out of several phones, seeking to determine which bytes are always the + * same and which bytes change from specimen to specimen. + * + * Written by Spacefalcon the Outlaw. + */ + +#include <sys/types.h> +#include <sys/file.h> +#include <stdio.h> +#include <stdlib.h> + +u_char specimen0[65536]; +char is_diff[65536]; + +read_specimen_file(filename, buf) + char *filename; + u_char *buf; +{ + int fd, cc; + + fd = open(filename, O_RDONLY); + if (fd < 0) { + perror(filename); + exit(1); + } + cc = read(fd, buf, 65536); + close(fd); + if (cc != 65536) { + fprintf(stderr, "%s: unable to read 64 KiB\n", filename); + exit(1); + } +} + +process_comp_specimen(filename) + char *filename; +{ + u_char this_spec[65536]; + int i; + + read_specimen_file(filename, this_spec); + for (i = 0; i < 65536; i++) + if (this_spec[i] != specimen0[i]) + is_diff[i] = 1; +} + +output() +{ + int off, state, cstart; + + for (off = 0; off < 65536; ) { + state = is_diff[off]; + cstart = off; + while (off < 65536 && is_diff[off] == state) + off++; + printf("%04X-%04X: %s\n", cstart, off-1, + state ? "varying" : "constant"); + } +} + +main(argc, argv) + char **argv; +{ + char **ap; + + if (argc < 3) { + fprintf(stderr, "usage: %s specimen0 specimen1 ...\n", argv[0]); + exit(1); + } + read_specimen_file(argv[1], specimen0); + for (ap = argv + 2; *ap; ap++) + process_comp_specimen(*ap); + output(); + exit(0); +}