movss Cheater Reputation: 0
Joined: 10 Feb 2018 Posts: 38
|
Posted: Sat Feb 10, 2018 4:05 am Post subject: How do I use the debug_onModuleLoad() function? |
|
|
beloved from main.lua
----------
function debugger_onModuleLoad(modulename, baseaddress) :
this routine is called when a module is loaded. Only works for the windows debugger
return 1 if you want to cause the debugger to break
----------
How do I get the value of baseaddress with lua ?
i was so confused about this
help,pls
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Sat Feb 10, 2018 8:20 am Post subject: |
|
|
Not something I've played with before, so I played with it (in CE 6.7).
Code: | -- function to run when attaching to a process
function onOpenProcess(pid)
print('attached to', pid)
-- create function to print stuff
local firstRun = true
function debugger_onModuleLoad(modulename, baseaddress)
if firstRun then
firstRun = false
for k,v in pairs(enumModules(pid)) do
print(k,v.Name, tostring(v.Is64Bit), v.PathToFile, v.Address, ('%X'):format(v.Address))
end
end
-- in x64 this seems to be a light userdata object (a C pointer) but in x86 a regular number...
local straddress = type(baseaddress) == 'userdata' and tostring(baseaddress):match('userdata: (%x+)') or ('%X'):format(baseaddress)
print('new module:', modulename, baseaddress, straddress, type(baseaddress))
return 0 -- 1 to break
end
end |
Run that and then attach to the tutorial, attach the debugger and click the close button, or simply create the Tutorial process from the file and you'll get prints like this and this, respectively, though make sure you check the memory viewer and click run if it's stopped. There'll be a long delay on the create method, I think that's due to the debugger failing to attach and waiting 10 seconds before launching a messagebox asking if it should try again and letting everything else continue but it works as expected regardless so...
Now in the first you'll notice "xmllite.dll" (apparently an xml parser) listed several times... no idea why but when you click the close button xmllite is loaded and then removed from memory (very quickly, before the message box is even handled) lol. This is why I said to click the close button when attaching to an existing tutorial process, because I know it always causes onModuleLoad to run which is what spews out all the module info (only the first time it runs)
In the second you'll notice something a bit strange, it says "userdata" after, nearly, everything... This one was done with the x64 process intead of the i386 and I'm not entirely sure why but the way CE passes the base address to a lua function causes it to pass a "light userdata" object (which is just a wrapper around a C pointer) if it's greater than 0xFFFFFFFF (the max value of a 4 byte int).
Actually I just remembered a better way to get the address from that lol, if type(baseaddress) == 'userdata' then baseaddress = userDataToInteger(baseaddress) end and then it can just be formatted as a hex string the same way it was in enumModules. eg.
Code: | -- if the address > 0xFFFFFFFF then CE passes light userdata object (a C pointer)... deal with that
if type(baseaddress) == 'userdata' then baseaddress = userDataToInteger(baseaddress) end
print('new module:', modulename, baseaddress, ('%X'):format(baseaddress)) |
|
|