-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch.c
More file actions
71 lines (55 loc) · 1.21 KB
/
patch.c
File metadata and controls
71 lines (55 loc) · 1.21 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
typedef struct { unsigned long offset; size_t size; char data[]; } patch;
size_t modify(FILE *f, const patch *p);
const char filename[] = "MSRGS.exe";
const int filesize = 1355776;
const patch p00001D97 = {0x00001D97, 1, {0xEB}};
const patch *modif[] = {&p00001D97};
int main(int argc, char *argv[])
{
FILE *f;
int i;
long size;
printf("Patch is for MS Research GroupShot 1.03\n\n");
f = fopen(filename, "rb+");
if (!f )
{
fprintf(stderr, "Unable to open '%s' for writing!\n\n", filename);
return EXIT_FAILURE;
}
fseek(f, 0L, SEEK_END);
size = ftell(f);
if (size != filesize)
{
fprintf(stderr, "Wrong file size.", filename);
return EXIT_FAILURE;
}
for(i=0; i < (sizeof(modif)/sizeof(patch*)); i++)
{
printf("Patching...step %i...", i);
if (modify(f, modif[i]) == modif[i]->size)
{
printf("ok!\n");
}
else
{
printf("error! (file may be corrupt)\n");
}
}
fclose(f);
return EXIT_SUCCESS;
}
size_t modify(FILE *f, const patch *p)
{
fseek(f, p->offset, SEEK_SET);
if (errno)
{
return 0;
}
else
{
return fwrite(p->data, 1, p->size, f);
}
}