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