Debian Codegraph @

android/app/jni/scripts/patch_xp.c

raw
1 // patch GetTickCount64 for running on Windows XP
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5
6 int main(int argc, char** argv) {
7 unsigned char* buf;
8 FILE* f=fopen(argv[1],"rb");
9 if (f==NULL) {
10 perror("open");
11 return 1;
12 }
13
14 fseek(f,0,SEEK_END);
15
16 size_t size=ftell(f);
17 buf=malloc(size);
18
19 fseek(f,0,SEEK_SET);
20
21 fread(buf,1,size,f);
22 fclose(f);
23
24 // patch
25 size_t remain=size;
26 unsigned char* buf1=buf;
27 while (size>=14) {
28 unsigned char* where=memchr(buf1,'G',remain);
29 if (where==NULL) {
30 printf("GetTickCount64 not found\n");
31 break;
32 }
33
34 if (memcmp(where,"GetTickCount64",14)==0) {
35 printf("found GetTickCount64 - patching...\n");
36 where[12]=0;
37 where[13]=0;
38 break;
39 }
40
41 buf1=where+1;
42 remain=size-(buf1-buf);
43 }
44
45 // write
46 FILE* of=fopen(argv[1],"wb");
47 if (f==NULL) {
48 perror("open write");
49 return 1;
50 }
51
52 fwrite(buf,1,size,of);
53 fclose(of);
54
55 return 0;
56 }