Skip to content

Instantly share code, notes, and snippets.

@lionello
Created March 12, 2014 09:18
Show Gist options
  • Save lionello/9503506 to your computer and use it in GitHub Desktop.
Save lionello/9503506 to your computer and use it in GitHub Desktop.
/* 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