Difference between revisions of "Lua:generateAPIHookScript"
Jump to navigation
Jump to search
(Created page with ''''function''' generateAPIHookScript(''AddressToHook'', ''AddressToJumpTo'', ''AddressToStoreNewCallAddress'' OPTIONAL) Returns an autoassemble script that when executed hooks t…') |
(Major overhaul of the post.) |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
| − | '''function''' generateAPIHookScript('' | + | [[Category:Lua]] |
| + | {{CodeBox|'''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=== | ===Function Parameters=== | ||
| − | {|width="85%" cellpadding="10 | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
!align="left"|Parameter | !align="left"|Parameter | ||
!align="left"|Type | !align="left"|Type | ||
!style="width: 80%;background-color:white;" align="left"|Description | !style="width: 80%;background-color:white;" align="left"|Description | ||
|- | |- | ||
| − | | | + | |address |
|[[CEAddressString]] | |[[CEAddressString]] | ||
| − | |The address to hook | + | |The address or symbol to hook. |
|- | |- | ||
| − | | | + | |addresstojumpto |
|[[CEAddressString]] | |[[CEAddressString]] | ||
| − | |The address | + | |The address or symbol the hook should jump to. |
|- | |- | ||
| − | | | + | |addresstogetnewcalladdress |
| − | |[[CEAddressString]] | + | |[[CEAddressString]] OPTIONAL |
| − | |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=== | ||
| + | String — The generated Auto Assembler script. | ||
| + | |||
| + | ===Examples=== | ||
| + | |||
| + | ====Generate an API hook script==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local script = generateAPIHookScript("kernel32.dll+1234", "MyHook") | ||
| + | |||
| + | print(script) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Generate and execute the hook script==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local script = generateAPIHookScript("kernel32.dll+1234", "MyHook") | ||
| + | |||
| + | if script ~= nil and script ~= "" then | ||
| + | autoAssemble(script) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Use symbols as hook targets==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook") | ||
| + | |||
| + | print(script) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Use the optional new-call-address parameter==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook", "NewCallAddress") | ||
| + | |||
| + | print(script) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Use all optional parameters==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook", "NewCallAddress", "", false) | ||
| + | |||
| + | print(script) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Save the generated script to a file==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook") | ||
| + | |||
| + | if script ~= nil then | ||
| + | local file = io.open([[C:\\Temp\\generated_hook.cea]], "w") | ||
| + | |||
| + | if file ~= nil then | ||
| + | file:write(script) | ||
| + | file:close() | ||
| + | end | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Preview before execution==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local script = generateAPIHookScript("SomeModule.SomeAPI", "MyAPIHook") | ||
| + | |||
| + | if script ~= nil then | ||
| + | print("Generated script:") | ||
| + | print(script) | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| − | + | {{LuaSeeAlso}} | |
| − | |||
| − | |||
Latest revision as of 20:15, 25 June 2026
Generates an Auto Assembler script that hooks the given address when the script is executed.
Contents
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