| 1 | //BinPatcher 3.0\r |
| 2 | //by: Harvie 2oo7\r |
| 3 | \r |
| 4 | /* This code is very useful, if you are cracking software and you need\r |
| 5 | to share your cracks without whole binary (because of size or copyright).\r |
| 6 | This is simple way to patch binaries at users home.\r |
| 7 | Warning: You need to know some things about PE (probably) architecture to use this.\r |
| 8 | But there is still some automatic computing with addreses,\r |
| 9 | so you have to know only bit about yours binary...\r |
| 10 | */\r |
| 11 | /*Note: this is patch used to crack free version of CPULower (remove NAG screen),\r |
| 12 | and you have to edit it for any file, that you want to patch.\r |
| 13 | */\r |
| 14 | \r |
| 15 | #include <stdio.h>\r |
| 16 | #include <stdlib.h>\r |
| 17 | \r |
| 18 | int main(int argc, char *argv[])\r |
| 19 | {\r |
| 20 | //Basic informations\r |
| 21 | char file[] = "cpulower.exe";\r |
| 22 | char this_file[] = "BinPatcher.exe";\r |
| 23 | char title[] = "CPU Lower - NAG screen remover - patcher";\r |
| 24 | char author[] = "<-Harvie 2oo7";\r |
| 25 | //You can get these from debuger, disassembler, etc...:\r |
| 26 | long int image_base = 0x400000; //ImageBase of binary\r |
| 27 | long int section_rva = 0x1000; //Virtual addres of patched section\r |
| 28 | long int section_offset = 0x400; //Offset of patched section\r |
| 29 | long int size = 0, needed_size = 317440; //Size in Bytes (Compressed size for PE compressors)\r |
| 30 | \r |
| 31 | //File declaration\r |
| 32 | FILE *bin;\r |
| 33 | \r |
| 34 | //Banner\r |
| 35 | printf("%s\nby: %s\n\nThis will patch %s\n\n", title, author, file);\r |
| 36 | \r |
| 37 | //Arguments\r |
| 38 | if(argc != 2) {\r |
| 39 | printf("Incorrect number of arguments!!!\n");\r |
| 40 | printf("Usage: %s %s\n", this_file, file);\r |
| 41 | printf("You can simply Drag&Drop file \"%s\" on this (%s)\n\n", file, this_file);\r |
| 42 | system("pause");\r |
| 43 | return(0); \r |
| 44 | }\r |
| 45 | \r |
| 46 | //Size check\r |
| 47 | int c;\r |
| 48 | printf("Checking file size of %s...\n", argv[1]);\r |
| 49 | bin = fopen(argv[1], "rb");\r |
| 50 | if(bin == NULL) { printf("Error while opening %s\n", argv[1]); return 0; }\r |
| 51 | while( (c = fgetc(bin)) != EOF ) {\r |
| 52 | size++;\r |
| 53 | }\r |
| 54 | fclose(bin);\r |
| 55 | printf("File size = %d B\n", size);\r |
| 56 | if(size != needed_size) {\r |
| 57 | printf("Incorrect file size (%d B) !!!\nContinue?\n", size);\r |
| 58 | system("pause");\r |
| 59 | } else {\r |
| 60 | printf("File size OK!\n\n"); \r |
| 61 | }\r |
| 62 | \r |
| 63 | //Backup\r |
| 64 | char backup[1024];\r |
| 65 | printf("Backuping to %s.crkbak\n", argv[1]);\r |
| 66 | sprintf(backup, "copy /B /Y \"%s\" \"%s.crkbak\" > nul", argv[1], argv[1]);\r |
| 67 | printf("Backup done.\n\n");\r |
| 68 | system(backup);\r |
| 69 | \r |
| 70 | //UnCompress example for upx (Use this only if you know what it is)\r |
| 71 | /*\r |
| 72 | printf("Uncompressing...\n");\r |
| 73 | char uncs[1024];\r |
| 74 | sprintf(uncs, "upx -d \"%s\"", argv[1]);\r |
| 75 | system(uncs); //THis needs upx binary\r |
| 76 | printf("Uncompressed!\n\n");\r |
| 77 | */\r |
| 78 | \r |
| 79 | //Patching\r |
| 80 | long int virtual_addres = 0x437069; //Virtual addres from debuger - Example: 0x00437069\r |
| 81 | unsigned char patch[] = "\x90\x90\x90\x90\x90"; //Patch to apply - Example: "\x90" (== NOP)\r |
| 82 | bin = fopen(argv[1], "rb+");\r |
| 83 | if(bin == NULL) { printf("Error while opening %s\n", argv[1]); return 0; }\r |
| 84 | \r |
| 85 | long int offset = virtual_addres - image_base - section_rva + section_offset; //Vypocitame offset v souboru\r |
| 86 | printf("Patching code @ D: %d H: 0x%x\n", offset, offset);\r |
| 87 | fseek(bin, offset, SEEK_SET); //Seek code\r |
| 88 | fwrite(&patch, (sizeof(patch)-1), 1, bin); //Patch code\r |
| 89 | \r |
| 90 | //GO HOME ;}}\r |
| 91 | fclose(bin);\r |
| 92 | \r |
| 93 | printf("File was successfully patched!!!\n\n"); \r |
| 94 | system("PAUSE"); \r |
| 95 | return 0;\r |
| 96 | }\r |