diff --git a/plugins/Dfusion/luafiles/init.lua b/plugins/Dfusion/luafiles/init.lua index 45d328c5c..a5ca70c6c 100644 --- a/plugins/Dfusion/luafiles/init.lua +++ b/plugins/Dfusion/luafiles/init.lua @@ -44,5 +44,6 @@ table.insert(plugins,{"adv_tools","some tools for (mainly) advneturer hacking"}) table.insert(plugins,{"tools","some misc tools"}) table.insert(plugins,{"triggers","a function calling plug (discontinued...)"}) table.insert(plugins,{"migrants","multi race imigrations"}) +table.insert(plugins,{"onfunction","run lua on some df function"}) mainmenu(plugins) diff --git a/plugins/Dfusion/luafiles/onfunction/compile.bat b/plugins/Dfusion/luafiles/onfunction/compile.bat new file mode 100644 index 000000000..f06fb8c4c --- /dev/null +++ b/plugins/Dfusion/luafiles/onfunction/compile.bat @@ -0,0 +1 @@ +as -anl --32 -o functions.o functions.asm \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/onfunction/functions.asm b/plugins/Dfusion/luafiles/onfunction/functions.asm new file mode 100644 index 000000000..75cc03327 --- /dev/null +++ b/plugins/Dfusion/luafiles/onfunction/functions.asm @@ -0,0 +1,19 @@ +.intel_syntax +push eax +push edx +push ecx +push ebx +push eax +mov eax,[esp+24] +push eax +function: +call 0xdeadbeef +function2: +mov [0xdeadbeef],eax #self modifying code... :/ +pop eax +function3: +call [0xdeadbeef] + + + + diff --git a/plugins/Dfusion/luafiles/onfunction/functions.o b/plugins/Dfusion/luafiles/onfunction/functions.o new file mode 100644 index 000000000..ec7310e1c Binary files /dev/null and b/plugins/Dfusion/luafiles/onfunction/functions.o differ diff --git a/plugins/Dfusion/luafiles/onfunction/plugin.lua b/plugins/Dfusion/luafiles/onfunction/plugin.lua new file mode 100644 index 000000000..cf26bc88a --- /dev/null +++ b/plugins/Dfusion/luafiles/onfunction/plugin.lua @@ -0,0 +1,36 @@ +onfunction={} +function onfunction.install() + ModData=engine.installMod("dfusion/onfunction/functions.o","functions") + modpos=ModData.pos + modsize=ModData.size + onfunction.pos=modpos + trgpos=engine.getpushvalue() + print(string.format("Function installed in:%x function to call is: %x",modpos,trgpos)) + local firstpos=modpos+engine.FindMarker(ModData,"function") + engine.poked(firstpos,trgpos-firstpos) --call first function + engine.poked(modpos+engine.FindMarker(ModData,"function2"),modpos+engine.FindMarker(ModData,"function3")) -- function table start + +end +function OnFunction(values) + print("Onfunction called!") + print("Data:") + for k,v in pairs(values) do + print(string.format("%s=%x",k,v)) + end + return 0 --todo return real address +end +function onfunction.patch(addr) + + if(engine.peekb(addr)~=0xe8) then + error("Incorrect address, not a function call") + else + --todo add to list of functions after patch + engine.poked(addr+1,onfunction.pos-addr-1) + end +end +mypos=engine.getmod("functions") +if mypos then + print("Onfunction already installed") +else + onfunction.install() +end \ No newline at end of file diff --git a/plugins/Dfusion/src/lua_Misc.cpp b/plugins/Dfusion/src/lua_Misc.cpp index aacf65e2b..768957c7a 100644 --- a/plugins/Dfusion/src/lua_Misc.cpp +++ b/plugins/Dfusion/src/lua_Misc.cpp @@ -129,6 +129,32 @@ static int GetMod(lua_State *L) st.push(pos); return 1; } +static size_t PushValue(size_t ret,uint32_t eax,uint32_t ebx,uint32_t ecx,uint32_t edx) +{ + lua::state st=lua::glua::Get(); + st.getglobal("OnFunction"); + if(st.is()) + return 0; + st.newtable(); + st.push(eax); + st.setfield("eax"); + st.push(ebx); + st.setfield("ebx"); + st.push(ecx); + st.setfield("ecx"); + st.push(edx); + st.setfield("edx"); + st.push(ret); + st.setfield("ret"); + st.pcall(1,1); + return st.as(); +} +static int Get_PushValue(lua_State *L) +{ + lua::state st(L); + st.push((uint32_t)&PushValue); + return 1; +} const luaL_Reg lua_misc_func[]= { {"loadmod",LoadMod}, @@ -137,6 +163,7 @@ const luaL_Reg lua_misc_func[]= {"loadobjsymbols",LoadObjSymbols}, {"findmarker",FindMarker}, {"newmod",NewMod}, + {"getpushvalue",Get_PushValue}, {NULL,NULL} }; void lua::RegisterMisc(lua::state &st)