Started working on new plugin

develop
Warmist 2011-08-20 01:12:30 +03:00
parent fc745f70ae
commit b29c719538
6 changed files with 84 additions and 0 deletions

@ -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)

@ -0,0 +1 @@
as -anl --32 -o functions.o 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]

@ -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

@ -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<lua::nil>())
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<uint32_t>();
}
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)