+//BinPatcher 3.0\r
+//by: Harvie 2oo7\r
+\r
+/* This code is very useful, if you are cracking software and you need\r
+to share your cracks without whole binary (because of size or copyright).\r
+This is simple way to patch binaries at users home.\r
+Warning: You need to know some things about PE (probably) architecture to use this.\r
+But there is still some automatic computing with addreses,\r
+so you have to know only bit about yours binary...\r
+*/\r
+/*Note: this is patch used to crack free version of CPULower (remove NAG screen),\r
+and you have to edit it for any file, that you want to patch.\r
+*/\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+int main(int argc, char *argv[])\r
+{\r
+ //Basic informations\r
+ char file[] = "cpulower.exe";\r
+ char this_file[] = "BinPatcher.exe";\r
+ char title[] = "CPU Lower - NAG screen remover - patcher";\r
+ char author[] = "<-Harvie 2oo7";\r
+ //You can get these from debuger, disassembler, etc...:\r
+ long int image_base = 0x400000; //ImageBase of binary\r
+ long int section_rva = 0x1000; //Virtual addres of patched section\r
+ long int section_offset = 0x400; //Offset of patched section\r
+ long int size = 0, needed_size = 317440; //Size in Bytes (Compressed size for PE compressors)\r
+ \r
+ //File declaration\r
+ FILE *bin;\r
+\r
+ //Banner\r
+ printf("%s\nby: %s\n\nThis will patch %s\n\n", title, author, file);\r
+ \r
+ //Arguments\r
+ if(argc != 2) {\r
+ printf("Incorrect number of arguments!!!\n");\r
+ printf("Usage: %s %s\n", this_file, file);\r
+ printf("You can simply Drag&Drop file \"%s\" on this (%s)\n\n", file, this_file);\r
+ system("pause");\r
+ return(0); \r
+ }\r
+ \r
+ //Size check\r
+ int c;\r
+ printf("Checking file size of %s...\n", argv[1]);\r
+ bin = fopen(argv[1], "rb");\r
+ if(bin == NULL) { printf("Error while opening %s\n", argv[1]); return 0; }\r
+ while( (c = fgetc(bin)) != EOF ) {\r
+ size++;\r
+ }\r
+ fclose(bin);\r
+ printf("File size = %d B\n", size);\r
+ if(size != needed_size) {\r
+ printf("Incorrect file size (%d B) !!!\nContinue?\n", size);\r
+ system("pause");\r
+ } else {\r
+ printf("File size OK!\n\n"); \r
+ }\r
+ \r
+ //Backup\r
+ char backup[1024];\r
+ printf("Backuping to %s.crkbak\n", argv[1]);\r
+ sprintf(backup, "copy /B /Y \"%s\" \"%s.crkbak\" > nul", argv[1], argv[1]);\r
+ printf("Backup done.\n\n");\r
+ system(backup);\r
+ \r
+ //UnCompress example for upx (Use this only if you know what it is)\r
+ /*\r
+ printf("Uncompressing...\n");\r
+ char uncs[1024];\r
+ sprintf(uncs, "upx -d \"%s\"", argv[1]);\r
+ system(uncs); //THis needs upx binary\r
+ printf("Uncompressed!\n\n");\r
+ */\r
+ \r
+ //Patching\r
+ long int virtual_addres = 0x437069; //Virtual addres from debuger - Example: 0x00437069\r
+ unsigned char patch[] = "\x90\x90\x90\x90\x90"; //Patch to apply - Example: "\x90" (== NOP)\r
+ bin = fopen(argv[1], "rb+");\r
+ if(bin == NULL) { printf("Error while opening %s\n", argv[1]); return 0; }\r
+ \r
+ long int offset = virtual_addres - image_base - section_rva + section_offset; //Vypocitame offset v souboru\r
+ printf("Patching code @ D: %d H: 0x%x\n", offset, offset);\r
+ fseek(bin, offset, SEEK_SET); //Seek code\r
+ fwrite(&patch, (sizeof(patch)-1), 1, bin); //Patch code\r
+ \r
+ //GO HOME ;}}\r
+ fclose(bin);\r
+ \r
+ printf("File was successfully patched!!!\n\n"); \r
+ system("PAUSE"); \r
+ return 0;\r
+}\r