From b29c71953802cdbf73568c7b1c5c225d6d2eb9b6 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 20 Aug 2011 01:12:30 +0300 Subject: [PATCH] Started working on new plugin --- plugins/Dfusion/luafiles/init.lua | 1 + .../Dfusion/luafiles/onfunction/compile.bat | 1 + .../Dfusion/luafiles/onfunction/functions.asm | 19 +++++++++ .../Dfusion/luafiles/onfunction/functions.o | Bin 0 -> 400 bytes .../Dfusion/luafiles/onfunction/plugin.lua | 36 ++++++++++++++++++ plugins/Dfusion/src/lua_Misc.cpp | 27 +++++++++++++ 6 files changed, 84 insertions(+) create mode 100644 plugins/Dfusion/luafiles/onfunction/compile.bat create mode 100644 plugins/Dfusion/luafiles/onfunction/functions.asm create mode 100644 plugins/Dfusion/luafiles/onfunction/functions.o create mode 100644 plugins/Dfusion/luafiles/onfunction/plugin.lua 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 0000000000000000000000000000000000000000..ec7310e1cac460d3c10928d43a974624630bc20b GIT binary patch literal 400 zcmeZaWM%+?O+d^IX0b5pm84dbfY}g221xY)@d~IIBal{LFi6l#Ni0c(is7Oh7z_^R zB^4Lrl81>m0M!Kq1qKInyQoM6y!f?m?Y+hCfkecAQ4lo&Rhpg7ExMsSuf0{{z(HCO-u literal 0 HcmV?d00001 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)