Reverse Engineering RET Homepage RET Members Reverse Engineering Projects Reverse Engineering Papers Reversing Challenges Reverser Tools RET Re-Search Engine Reverse Engineering Forum Reverse Engineering Links

Go Back   Reverse Engineering Team Board > Reverse Engineering Board > Reverse Code Engineering
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Thread Tools Display Modes
Old 03-10-2014, 04:51 PM
madior-3211 madior-3211 is offline
Join Date: Oct 2011
Posts: 12
Default Source code for patch?

I need help with making a patch for .exe file. I can patch it with OllyDbg. I need to write a patch to automate the process. I am just asking for example source code in c.
For example: change a conditional jump to nops (0X90h) on 2 addresses.
Reply With Quote
Old 03-11-2014, 02:44 AM
sverox sverox is offline
Senior Member
Join Date: Jan 2008
Posts: 80

Use any of ready patch builder softwares available (Diablo universal patcher is good enough).

If you insist for source code here one very simple (any decent compiler should compile it):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main()
	FILE *pFile = NULL;

	char inp_file[256] = "MyOriginalFile.exe";
	char out_file[256] = "";

	unsigned char *file_buffer = NULL;

	pFile = fopen(inp_file, "rb");

	if(pFile == NULL)

	// obtain file size
	fseek(pFile, 0, SEEK_END);
	long file_size = ftell(pFile);

	// note this example require at least file_size memory!!!!
	file_buffer = (unsigned char*)malloc(sizeof(unsigned char) * file_size);
	fread (file_buffer, 1, file_size, pFile);
	fclose (pFile);

	unsigned int offset_to_patch_1 = 0x10000;
	unsigned int offset_to_patch_2 = 0x20000;

	unsigned char patch_data[] = { 0x90, 0x90 }; // nop, nop

	memcpy(&file_buffer[offset_to_patch_1], patch_data, sizeof(patch_data));
	memcpy(&file_buffer[offset_to_patch_2], patch_data, sizeof(patch_data));

	// outfile name
	sprintf(out_file, "%s_patch.exe", inp_file);

	// and write as new file
	pFile = fopen(out_file, "wb");
	fwrite (file_buffer, 1, file_size, pFile);
	fclose (pFile);

Reply With Quote
Old 03-11-2014, 04:33 PM
madior-3211 madior-3211 is offline
Join Date: Oct 2011
Posts: 12
Thumbs up

Thanks for your help and the source code that you provided. I appreciate your time and help.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.