Lua:generateAPIHookScript

From Cheat Engine
(Redirected from generateAPIHookScript)
Jump to navigation Jump to search

<> Lua API Reference

function generateAPIHookScript(address, addresstojumpto, addresstogetnewcalladdress OPTIONAL, ext OPTIONAL, targetself OPTIONAL) : string

Generates an Auto Assembler script that hooks the given address when the script is executed.

Function Parameters[edit]

Parameter Type Description
address CEAddressString The address or symbol to hook.
addresstojumpto CEAddressString The address or symbol the hook should jump to.
addresstogetnewcalladdress CEAddressString OPTIONAL Optional address or symbol used by the generated hook script to get the new call address.
ext CEAddressString OPTIONAL Optional extension text used by the generated script.
targetself Boolean OPTIONAL Optional flag that controls whether the generated hook targets the current process context.

Returns[edit]

String — The generated Auto Assembler script.

Examples[edit]

Generate an API hook script[edit]

1 local script = generateAPIHookScript("kernel32.dll+1234", "MyHook")
2 
3 print(script)

Generate and execute the hook script[edit]

1 local script = generateAPIHookScript("kernel32.dll+1234", "MyHook")
2 
3 if script ~= nil and script ~= "" then
4   autoAssemble(script)
5 end

Use symbols as hook targets[edit]

1 local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook")
2 
3 print(script)

Use the optional new-call-address parameter[edit]

1 local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook", "NewCallAddress")
2 
3 print(script)

Use all optional parameters[edit]

1 local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook", "NewCallAddress", "", false)
2 
3 print(script)

Save the generated script to a file[edit]

 1 local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook")
 2 
 3 if script ~= nil then
 4   local file = io.open([[C:\\Temp\\generated_hook.cea]], "w")
 5 
 6   if file ~= nil then
 7     file:write(script)
 8     file:close()
 9   end
10 end

Preview before execution[edit]

1 local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook")
2 
3 if script ~= nil then
4   print("Generated script:")
5   print(script)
6 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine