-
Notifications
You must be signed in to change notification settings - Fork 0
/
patcher.c
40 lines (30 loc) · 887 Bytes
/
patcher.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv) {
char *orig = argv[1];
unsigned int patchoffset;
char *patch = argv[3];
char *dest = argv[4];
unsigned char *buffer;
int origsize;
int readed;
sscanf(argv[2], "%x", &patchoffset);
printf ("patching %s at %0x(%s) with %s to %s\n", orig, patchoffset, argv[2], patch, dest);
FILE* f = fopen(orig, "r");
fseek(f, 0, SEEK_END);
origsize=ftell(f);
fseek(f, 0, SEEK_SET);
buffer = malloc(origsize);
readed = fread(buffer, 1, origsize, f);
printf ("orig %s (%d bytes)\n", orig, readed);
fclose(f);
f = fopen(patch, "r");
readed = fread(buffer + patchoffset, 1, origsize - patchoffset, f);
printf ("patch %s (%d bytes)\n", patch, readed);
fclose(f);
f = fopen(dest, "w");
readed = fwrite(buffer, 1, origsize, f);
printf ("desc %s (%d bytes)\n", dest, readed);
fclose(f);
free(buffer);
}