-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmemUtils.cpp
More file actions
43 lines (35 loc) · 922 Bytes
/
memUtils.cpp
File metadata and controls
43 lines (35 loc) · 922 Bytes
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
#include "memUtils.h"
#include "Logging.h"
#include <substrate.h>
uint g_libAddress = NULL;
uint getLibraryAddress(const char* libName) {
FILE* fp = fopen("/proc/self/maps", "rt");
if (fp == NULL) {
perror("fopen");
return 0;
}
uint addr = 0;
char line[1024];
while (fgets(line, sizeof(line), fp) != NULL) {
if (strstr(line, libName) != NULL) {
addr = strtoul(line, NULL, 16);
LOGI("%s at 0x%x", libName, addr);
break;
}
}
fclose(fp);
return addr;
}
uint getActualOffset(uint offset)
{
if (g_libAddress == 0)
{
g_libAddress = getLibraryAddress("libPVZ2.so");
}
return g_libAddress + offset;
}
void PVZ2HookFunction(uint offset, void* replace, void** result, const char* funcName)
{
MSHookFunction((void*)getActualOffset(offset), replace, result);
LOGI("Hooked %s", funcName);
}