-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcommon.cpp
71 lines (65 loc) · 1.79 KB
/
common.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
#include "stdafx.h"
#include "common.h"
#include "util.h"
#include "mhook.h"
bool IsSupportedWxVersion(
const SuppWxCfg* cfg,
INT cfg_count,
DWORD* offset/* = NULL*/,
BYTE* orig_code/* = NULL*/,
DWORD* orig_code_count/* = NULL*/,
BYTE* fake_code/* = NULL*/,
DWORD* fake_code_count/* = NULL*/)
{
TCHAR tszDllPath[MAX_PATH] = { 0 };
GetModuleFileName(NULL, tszDllPath, MAX_PATH);
PathRemoveFileSpec(tszDllPath);
PathAppend(tszDllPath, WECHATWINDLL);
TCHAR version[100] = { 0 };
if (!GetFileVersion(tszDllPath, version))
{
return false;
}
for (int i = 0; i < cfg_count; i++) {
if (!_tcsicmp(cfg[i].version, version)) {
if (offset) {
*offset = cfg[i].revoke_offset;
}
if (orig_code) {
memcpy(orig_code, cfg[i].code.orig_code, cfg[i].code.orig_code_count);
}
if (fake_code) {
memcpy(fake_code, cfg[i].code.fake_code, cfg[i].code.fake_code_count);
}
if (orig_code_count) {
*orig_code_count = cfg[i].code.orig_code_count;
}
if (fake_code_count) {
*fake_code_count = cfg[i].code.fake_code_count;
}
return true;
}
}
return false;
}
int HookTemplate(HMODULE hMod, const SuppWxCfg* OffArray, int len, PVOID* orig, PVOID fake)
{
DWORD offset = 0;
if (IsSupportedWxVersion(
OffArray,
len,
&offset))
{
*orig = (PVOID)((DWORD)hMod + offset);
if (!Mhook_SetHook((PVOID*)orig, fake)) {
*orig = NULL;
return ERROR_INVALID_ADDRESS;
}
else {
return ERROR_SUCCESS;
}
}
else {
return ERROR_NOT_SUPPORTED;
}
}