forked from celophi/ToS-IDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-renameLuaFunc.py
94 lines (83 loc) · 2.26 KB
/
4-renameLuaFunc.py
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
#!/usr/bin/python
"""
Tree of Savior IDAPython Script
Automatic rename of Lua related functions
"""
import idaapi
import idc
if GetStrucIdByName ("lua_State") == BADADDR:
print "ERROR : Add definition of lua_State first.";
print '''
union LuaValue {
void *gc;
void *p;
double n;
int b;
};
struct lua_TValue
{
LuaValue value;
int tt;
};
typedef struct lua_TValue LuaTValue;
typedef LuaTValue *StkId;
struct lua_State
{
void *next;
unsigned __int8 tt;
unsigned __int8 marked;
unsigned __int8 status;
StkId top;
StkId base;
void *l_G;
void *ci;
void *savedpc;
StkId stack_last;
StkId stack;
void *end_ci;
void *base_ci;
int stacksize;
int size_ci;
unsigned __int16 nCcalls;
unsigned __int16 baseCcalls;
unsigned __int8 hookmask;
unsigned __int8 allowhook;
int basehookcount;
int hookcount;
void *hook;
LuaTValue l_gt;
LuaTValue env;
void *openupval;
void *gclist;
void *errorJmp;
int errfunc;
};
'''.strip();
else:
# Tip : GetSessionObject is already defined with 5-ToSrenameDebugFunctions.py for discovery
# Just look for XRef of GetSessionObject and you'll find LuaExtern__declGlobalFunction
LuaExtern__declGlobalFunction = 0x0064C540; # i233292
LuaExtern__useTable = 0x0064C270;
def MakeNameForce (address, name):
x = 2;
newName = name;
while (MakeNameEx (address, newName, SN_NOWARN) == 0):
newName = "%s_%d" % (name, x);
x = x + 1;
return newName;
# Rename all functions declared with LuaExtern__declGlobalFunction
occ = RfirstB (LuaExtern__declGlobalFunction);
while (occ != BADADDR):
routineAddress = Dword (occ - 5 - 5);
routineName = GetString (Dword (occ - 5));
#iterate to find table
prevAddr = PrevHead(occ)
while (prevAddr != BADADDR):
if (GetOperandValue(prevAddr, 0) == LuaExtern__useTable):
tableName = GetString(Dword(prevAddr - 5));
break;
prevAddr = PrevHead(prevAddr)
occ = RnextB (LuaExtern__declGlobalFunction, occ);
routineName = tableName + "::" + routineName + "::L";
name = MakeNameForce (routineAddress, routineName);
SetType (routineAddress, "int __cdecl %s (lua_State * luaState)" % name);