diff 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
line wrap: on
line diff
--- /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);
+}