forked from cseagle/sk3wldbg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
android_memory.cpp
72 lines (60 loc) · 2.09 KB
/
android_memory.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
#include "android_memory.h"
#include <ida.hpp>
#include "sk3wldbg.h"
extern sk3wldbg *g_sk3wl_uc;
android_memory::android_memory()
{
memmgr = nullptr;
}
void android_memory::set_memmgr(mem_mgr * mgr)
{
memmgr = mgr;
}
void* android_memory::handle_mmap2(uc_engine* uc, syscall_args& args)
{
//void *mmap2(void *addr, size_t length, int prot, int flags, int fd, off_t pgoffset);
// MAP_FILE 0
// MAP_SHARED 0x01
// MAP_PRIVATE 0x02
// MAP_FIXED 0x10
// MAP_ANONYMOUS 0x20
//
map_block *pblock = nullptr;
uint64_t base = args.arg[0];
if ((pblock = memmgr->mmap(args.arg[0], args.arg[1], args.arg[2], base ? SDB_MAP_FIXED : 0)))
{
qstring seg_name = "mmap_";
seg_name.sprnt("mmap_%llX", pblock->guest);
uint32_t bitness = 1; //default to 32
if (g_sk3wl_uc->debug_mode & UC_MODE_16) {
bitness = 0;
}
else if (g_sk3wl_uc->debug_mode & UC_MODE_64) {
bitness = 2;
}
createNewSegment(seg_name.c_str(), (ea_t)pblock->guest, args.arg[1], args.arg[2], bitness, false);
return reinterpret_cast<void*>(pblock->guest);
}
return nullptr;
}
void* android_memory::handle_mprotect(uc_engine* uc, syscall_args& args)
{
//int mprotect(void *addr, size_t len, int prot);
memmgr->mprotect(args.arg[0], args.arg[1], args.arg[2]);
return nullptr;
}
void* android_memory::handle_munmap(uc_engine* uc, syscall_args& args)
{
memmgr->munmap(args.arg[0], args.arg[1]);
return nullptr;
}
void android_memory::init_hook(XSyscall_handle* psyshandle)
{
auto fn_munmap = std::bind(&android_memory::handle_munmap, this, std::placeholders::_1, std::placeholders::_2);
auto fn_mprotect = std::bind(&android_memory::handle_mprotect, this, std::placeholders::_1, std::placeholders::_2);
auto fn_mmap2 = std::bind(&android_memory::handle_mmap2, this, std::placeholders::_1, std::placeholders::_2);
psyshandle->set_handle(0x5B, syscall_handle(0x5B, "munmap", 2, fn_munmap));
psyshandle->set_handle(0x7D, syscall_handle(0x7D, "mprotect", 3, fn_mprotect));
psyshandle->set_handle(0xC0, syscall_handle(0xC0, "mmap2", 6, fn_mmap2));
//psyshandle->set_handle(0xDC, syscall_handle(0xDC, "madvise", 3, _handle_munmap));
}