/
main.cpp
73 lines (61 loc) · 2.7 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
#include <string>
//////////////////////////////////////////////////
// declaration of functions in frida
extern "C" void frida_log_callback(const char*);
extern "C" void frida_hexdump_callback(void*, unsigned int);
//////////////////////////////////////////////////
// declaration of functions in libMyGame.so
namespace cocos2d{
struct Application {
static Application* getInstance();
std::string& getVersion();
};
};
extern "C" void fun(void)
{
frida_log_callback("Hello World from so");
frida_log_callback("cocos2d application version:");
const std::string& version = cocos2d::Application::getInstance()->getVersion();
frida_log_callback(version.c_str());
return ;
}
int showThumbRegs(void* sp)
{
char buf[PATH_MAX];
sprintf(buf, " CPSR 0x%08x", ((unsigned int*)sp)[0 ]); frida_log_callback(buf);
sprintf(buf, " R8 0x%08x", ((unsigned int*)sp)[1 ]); frida_log_callback(buf);
sprintf(buf, " R9 0x%08x", ((unsigned int*)sp)[2 ]); frida_log_callback(buf);
sprintf(buf, " R10 0x%08x", ((unsigned int*)sp)[3 ]); frida_log_callback(buf);
sprintf(buf, " R11 0x%08x", ((unsigned int*)sp)[4 ]); frida_log_callback(buf);
sprintf(buf, " R12 0x%08x", ((unsigned int*)sp)[5 ]); frida_log_callback(buf);
sprintf(buf, " LR 0x%08x", ((unsigned int*)sp)[6 ]); frida_log_callback(buf);
sprintf(buf, " R0 0x%08x", ((unsigned int*)sp)[7 ]); frida_log_callback(buf);
sprintf(buf, " R1 0x%08x", ((unsigned int*)sp)[8 ]); frida_log_callback(buf);
sprintf(buf, " R2 0x%08x", ((unsigned int*)sp)[9 ]); frida_log_callback(buf);
sprintf(buf, " R3 0x%08x", ((unsigned int*)sp)[10]); frida_log_callback(buf);
sprintf(buf, " R4 0x%08x", ((unsigned int*)sp)[11]); frida_log_callback(buf);
sprintf(buf, " R5 0x%08x", ((unsigned int*)sp)[12]); frida_log_callback(buf);
sprintf(buf, " R6 0x%08x", ((unsigned int*)sp)[13]); frida_log_callback(buf);
sprintf(buf, " R7 0x%08x", ((unsigned int*)sp)[14]); frida_log_callback(buf);
return 0;
}
extern "C" void hook_fun(void* baseaddress, void* sp)
{
frida_log_callback("#################### Hook Begin ##############################");
char buf[PATH_MAX];
frida_log_callback("hook function from so");
// show parameter 1
sprintf(buf, "baseaddress %p", baseaddress); frida_log_callback(buf);
// show registers
showThumbRegs(sp);
frida_log_callback("#################### Hook end ##############################");
return ;
}
__attribute__((constructor))
static void constructor_test0() {
frida_log_callback("call constructor_test0 ");
}
__attribute__((destructor))
static void destructor_test0() {
frida_log_callback("call destructor_test0 ");
}