Cleaned up directory a bit...
[mirrors/Programs.git] / misc / BinCracking / hexcmp.c
... / ...
CommitLineData
1#include <stdio.h>\r
2#include <stdlib.h>\r
3\r
4int main(int argc, char *argv[])\r
5{\r
6 printf("HEXCMP 0.3\nHexadecimal Comparator\n<-Harvie 2oo7\n\n");\r
7 if(argc < 3) {\r
8 printf("Usage: hexcmp oldfile newfile [decimal_offset_to_start_at]\n");\r
9 printf("This will show what is new in \"newfile\",\n");\r
10 printf("this can be useful, when making binary patchers.\n\n");\r
11 system("pause");\r
12 return 0;\r
13 }\r
14 \r
15 printf("Comparing old \"%s\" with new \"%s\"\n", argv[1], argv[2]); \r
16 \r
17 FILE *forig, *fcrac;\r
18 forig = fopen(argv[1], "rb");\r
19 if(forig == NULL) { printf("Error while opening %s\n", argv[1]); return 0; }\r
20 fcrac = fopen(argv[2], "rb");\r
21 if(fcrac == NULL) { printf("Error while opening %s\n", argv[2]); return 0; }\r
22 \r
23 short found = 0;\r
24 unsigned long int offset = 0, last = 0, end = 0, dlen = 0;\r
25 int corig = 0, ccrac = 0;\r
26 \r
27 if(argc > 3) {\r
28 offset = atof(argv[3]);\r
29 printf("Comparing from offset D: %d H: 0x%x\n", offset, offset);\r
30 }\r
31 printf("\n");\r
32 \r
33 //Seek\r
34 fseek(forig, offset, SEEK_SET);\r
35 fseek(fcrac, offset, SEEK_SET);\r
36 \r
37 while((ccrac = fgetc(fcrac)) != EOF) {\r
38 if( (corig = fgetc(forig)) == EOF ) {\r
39 corig == -9999;\r
40 if(end == 0) {\r
41 end = 1; \r
42 }\r
43 }\r
44 if(corig != ccrac) {\r
45 \r
46 if(end == 1) {\r
47 if(dlen != 0) {\r
48 printf("\nLenght: %d Bytes", dlen);\r
49 dlen = 0;\r
50 }\r
51 printf("\n\n--- END OF OLDER FILE ---\n\n"); \r
52 end = 2;\r
53 }\r
54 \r
55 if(offset != (last+1)) {\r
56 if(dlen != 0) {\r
57 printf("\nLenght: %d Bytes", dlen);\r
58 dlen = 0;\r
59 printf("\n\n");\r
60 }\r
61 printf("Difference @ D: %d H: 0x%x\n", offset, offset);\r
62 }\r
63 \r
64 printf("\\x%x", ccrac);\r
65 \r
66 dlen++;\r
67 last = offset;\r
68 found = 1;\r
69 }\r
70 \r
71 offset++;\r
72 }\r
73 \r
74 if(dlen != 0) {\r
75 printf("\nLenght: %d Bytes", dlen);\r
76 }\r
77 \r
78 fclose(forig);\r
79 fclose(fcrac);\r
80 \r
81 if(found == 0) {\r
82 printf("No difference found!!!");\r
83 }\r
84 printf("\n");\r
85 //system("PAUSE"); //Debug\r
86 return 0;\r
87}\r
This page took 0.149403 seconds and 4 git commands to generate.