Almost working onfunction plugin... need to work out few bugs

develop
Warmist 2011-08-20 02:33:57 +03:00
parent b29c719538
commit e901f615c9
3 changed files with 16 additions and 10 deletions

@ -4,10 +4,10 @@ push edx
push ecx push ecx
push ebx push ebx
push eax push eax
mov eax,[esp+24] mov eax,[esp+20]
push eax push eax
function: function:
call 0xdeadbeef call 0xdeadbee4
function2: function2:
mov [0xdeadbeef],eax #self modifying code... :/ mov [0xdeadbeef],eax #self modifying code... :/
pop eax pop eax

@ -1,15 +1,18 @@
onfunction={} onfunction=onfunction or {}
function onfunction.install() function onfunction.install()
ModData=engine.installMod("dfusion/onfunction/functions.o","functions") ModData=engine.installMod("dfusion/onfunction/functions.o","functions",4)
modpos=ModData.pos modpos=ModData.pos
modsize=ModData.size modsize=ModData.size
onfunction.pos=modpos onfunction.pos=modpos
trgpos=engine.getpushvalue() trgpos=engine.getpushvalue()
print(string.format("Function installed in:%x function to call is: %x",modpos,trgpos)) print(string.format("Function installed in:%x function to call is: %x",modpos,trgpos))
local firstpos=modpos+engine.FindMarker(ModData,"function") local firstpos=modpos+engine.FindMarker(ModData,"function")
engine.poked(firstpos,trgpos-firstpos) --call first function engine.poked(firstpos,trgpos-firstpos-4) --call Lua-Onfunction
engine.poked(modpos+engine.FindMarker(ModData,"function2"),modpos+engine.FindMarker(ModData,"function3")) -- function table start onfunction.fpos=modpos+engine.FindMarker(ModData,"function3")
engine.poked(modpos+engine.FindMarker(ModData,"function2"),modpos+modsize)
engine.poked(onfunction.fpos,modpos+modsize)
SetExecute(modpos)
onfunction.calls={}
end end
function OnFunction(values) function OnFunction(values)
print("Onfunction called!") print("Onfunction called!")
@ -17,20 +20,23 @@ function OnFunction(values)
for k,v in pairs(values) do for k,v in pairs(values) do
print(string.format("%s=%x",k,v)) print(string.format("%s=%x",k,v))
end end
return 0 --todo return real address return onfunction.calls[values.ret] --returns real function to call
end end
function onfunction.patch(addr) function onfunction.patch(addr)
if(engine.peekb(addr)~=0xe8) then if(engine.peekb(addr)~=0xe8) then
error("Incorrect address, not a function call") error("Incorrect address, not a function call")
else else
--todo add to list of functions after patch
engine.poked(addr+1,onfunction.pos-addr-1) onfunction.calls[addr+5]=addr+engine.peekd(addr+1)+5 --adds real function to call
engine.poked(addr+1,engine.getmod("functions")-addr-5)
end end
end end
mypos=engine.getmod("functions") mypos=engine.getmod("functions")
if mypos then if mypos then
print("Onfunction already installed") print("Onfunction already installed")
onfunction.patch(0x189dd6+offsets.base())
else else
onfunction.install() onfunction.install()
end end