-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmhook.py
54 lines (44 loc) · 1.65 KB
/
smhook.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
import frida
session = frida.attach("ScrapMechanic.exe")
script = session.create_script("""
var gettop = new NativeFunction(Module.getExportByName(null,"lua_gettop"),'int', ['pointer']);
var pcall = new NativeFunction(Module.getExportByName(null,"lua_pcall"),'int', ['pointer','int','int','int']);
var loadstring = new NativeFunction(Module.getExportByName(null,"luaL_loadstring"),'int', ['pointer','pointer']);
function luaexec(luastateindex,payload){
var rets=[]
rets[0]=loadstring(ptr(luastates[luastateindex]),Memory.allocUtf8String(payload))
rets[1]=pcall(ptr(luastates[luastateindex]),0,0,0)
return rets
}
var lua_newstate_addr=Module.findExportByName(null,"lua_newstate")
console.log("lua_newstate@")
console.log(lua_newstate_addr)
var luastates=[]
function enhanceluaenv(stateindex){ // export ffi to lua (sm.ffi)
luaexec(stateindex,'unsafe_env.sm.ffi = require("ffi")')
//preload some functions
luaexec(stateindex,"unsafe_env.sm.ffi.cdef[[int MessageBoxA(void *w, const char *txt, const char *cap, int type);]]")
//Example usage sm.ffi.C.MessageBoxA(nil, "Hello world!", "Test", 0)
luaexec(stateindex,"unsafe_env.sm.ffi.cdef[[unsigned short GetKeyState(int nVirtKey);]]")
//Example usage:
//if(sm.ffi.C.GetKeyState(79)==65409)then
//sm.gui.chatMessage("O key is pressed")
//end
}
Interceptor.attach(lua_newstate_addr,{
onEnter: function ( args) {
},
onLeave: function (retval) {
luastates.push(retval.toString())
console.log('lua_newstate() = '+retval);
enhanceluaenv(0) // hacky, but works
}
})
rpc.exports = {
luaexec: luaexec
};
""")
script.load()
while(True):
pass
#script.exports.luaexec