4 /* This code is very useful, if you are cracking software and you need
5 to share your cracks without whole binary (because of size or copyright).
6 This is simple way to patch binaries at users home.
7 Warning: You need to know some things about PE (probably) architecture to use this.
8 But there is still some automatic computing with addreses,
9 so you have to know only bit about yours binary...
11 /*Note: this is patch used to crack free version of CPULower (remove NAG screen),
12 and you have to edit it for any file, that you want to patch.
18 int main(int argc
, char *argv
[])
21 char file
[] = "cpulower.exe";
22 char this_file
[] = "BinPatcher.exe";
23 char title
[] = "CPU Lower - NAG screen remover - patcher";
24 char author
[] = "<-Harvie 2oo7";
25 //You can get these from debuger, disassembler, etc...:
26 long int image_base
= 0x400000; //ImageBase of binary
27 long int section_rva
= 0x1000; //Virtual addres of patched section
28 long int section_offset
= 0x400; //Offset of patched section
29 long int size
= 0, needed_size
= 317440; //Size in Bytes (Compressed size for PE compressors)
35 printf("%s\nby: %s\n\nThis will patch %s\n\n", title
, author
, file
);
39 printf("Incorrect number of arguments!!!\n");
40 printf("Usage: %s %s\n", this_file
, file
);
41 printf("You can simply Drag&Drop file \"%s\" on this (%s)\n\n", file
, this_file
);
48 printf("Checking file size of %s...\n", argv
[1]);
49 bin
= fopen(argv
[1], "rb");
50 if(bin
== NULL
) { printf("Error while opening %s\n", argv
[1]); return 0; }
51 while( (c
= fgetc(bin
)) != EOF
) {
55 printf("File size = %d B\n", size
);
56 if(size
!= needed_size
) {
57 printf("Incorrect file size (%d B) !!!\nContinue?\n", size
);
60 printf("File size OK!\n\n");
65 printf("Backuping to %s.crkbak\n", argv
[1]);
66 sprintf(backup
, "copy /B /Y \"%s\" \"%s.crkbak\" > nul", argv
[1], argv
[1]);
67 printf("Backup done.\n\n");
70 //UnCompress example for upx (Use this only if you know what it is)
72 printf("Uncompressing...\n");
74 sprintf(uncs, "upx -d \"%s\"", argv[1]);
75 system(uncs); //THis needs upx binary
76 printf("Uncompressed!\n\n");
80 long int virtual_addres
= 0x437069; //Virtual addres from debuger - Example: 0x00437069
81 unsigned char patch
[] = "\x90\x90\x90\x90\x90"; //Patch to apply - Example: "\x90" (== NOP)
82 bin
= fopen(argv
[1], "rb+");
83 if(bin
== NULL
) { printf("Error while opening %s\n", argv
[1]); return 0; }
85 long int offset
= virtual_addres
- image_base
- section_rva
+ section_offset
; //Vypocitame offset v souboru
86 printf("Patching code @ D: %d H: 0x%x\n", offset
, offset
);
87 fseek(bin
, offset
, SEEK_SET
); //Seek code
88 fwrite(&patch
, (sizeof(patch
)-1), 1, bin
); //Patch code
93 printf("File was successfully patched!!!\n\n");
This page took 1.135911 seconds and 4 git commands to generate.