Skip to content

Instantly share code, notes, and snippets.

@lionello
Created Mar 12, 2014
Embed
What would you like to do?
/* patchbin.c, Patch a binary file, by Lionello Lunesu, placed in the public domain */
struct FILE;
extern struct FILE* fopen(char*, char*);
extern int fwrite(void*, int, int, struct FILE*);
extern int fread(void*, int, int, struct FILE*);
extern int fseek(struct FILE*, long int, int);
#define SEEK_SET 0
extern int memcmp(void*, void*, int);
int main(int argc, char** argv)
{
long int OFFSET = 0x0002de70;
unsigned TEST[] = { 0xe5903010, 0xe92d4070, 0xe3530000, 0xe1a04000, 0xe590500c, 0x1a00000a };
unsigned PATCH[] = { 0xe3a00000 };
struct FILE * f = fopen(argv[1], "r+");
if (!f)
return 1;
if (fseek(f, OFFSET, SEEK_SET))
return 2;
char buf[sizeof(TEST)];
if (1 != fread(buf, sizeof(TEST), 1, f))
return 3;
if (memcmp(buf, TEST, sizeof(TEST)))
return 4;
if (1 != fwrite(PATCH, sizeof(PATCH), 1, f))
return 5;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment