-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
97 lines (80 loc) · 2.54 KB
/
main.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include "func.h"
using namespace std;
int crackChrome(const string &path);
int main(int argc, char *argv[]) {
if (argc != 2) {
cout << "Usage:" << endl;
cout << " " << baseName(argv[0]) << " " << "chrome.dll" << endl;
return -1;
}
string targetFilename = fullPath(argv[1]);
int backupResult = backupFile(targetFilename);
if (backupResult != 0) return backupResult;
if (crackChrome(targetFilename) == 0) {
return 0;
} else {
cerr << "Something went wrong lol." << endl;
return -1;
}
}
int crackChrome(const string &path) {
unsigned char *byteData = nullptr;
unsigned int fileSize = 0;
readFileIntoArray(byteData, fileSize, path);
if (byteData == nullptr) {
showError();
return -2;
}
short searchFor[] = {
0x84, 0xc0, // test al,al
0x75, -1, // jne chrome.xxx
0xe8, -1, -1, -1, -1, // call chrome.xxx
0x83, 0xf8, -1, // cmp eax, 2|3 ***
0x7f, -1, // jg chrome.xxx
0x83, 0x3d, -1, -1, -1, -1, 0x01, // cmp dword ptr ds:[xxx], 1
};
const unsigned char PatchTarget[] = {0x7f};
const unsigned int PatchTargetLen = sizeof(PatchTarget) / sizeof(PatchTarget[0]);
unsigned int searchLen = sizeof(searchFor) / sizeof(searchFor[0]);
long searchIdx = indexOfData(
byteData, fileSize,
searchFor, searchLen
);
if (searchIdx != -1) {
// Make sure just one pattern matched.
if (indexOfData(byteData, fileSize, searchFor, searchLen, (unsigned int) searchIdx + 1) >= 0)
searchIdx = -9;
}
delete[] byteData;
if (searchIdx == -1) {
cerr << "Pattern not found" << endl;
return -1;
} else if (searchIdx == -9) {
cerr << "Pattern too many" << endl;
return -9;
} else {
cout << "Find pattern at 0x" << flush;
printf("%016X", (unsigned int) searchIdx);
cout << endl;
//Do patch
cout << "Patching" << endl;
FILE *target = fopen(path.c_str(), "r+");
if (target == nullptr) {
showError();
return -3;
}
fseek(target, (long) (searchIdx + 0xb), SEEK_SET);
if (fwrite(PatchTarget, sizeof(PatchTarget[0]), PatchTargetLen, target) <= 0) {
showError();
fclose(target);
return -4;
} else {
cout << "Patch done." << endl;
}
fclose(target);
return 0;
}
}