Skip to content

Commit

Permalink
Fix 'jmp short', I'm an idiot. Also add option
Browse files Browse the repository at this point in the history
to hook an overridden method.   This inserts a
short LUA script in the created table entry to
find the overridden method with the correct
signature.
  • Loading branch information
JasonGoemaat committed Feb 26, 2024
1 parent 136392a commit 739b59c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
47 changes: 42 additions & 5 deletions Dev.CT
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="45">
<Forms>
<CESplitter1 Class="TCESplitter" Encoding="Ascii85">vtwXj2nldA.0_$i4KB#ZEGbDX.zlqHS$tB^N_,xpvU#Ltre}BeA7f$.$uD4HWDU/uDal{BWncgR</CESplitter1>
<CESplitter1 Class="TCEForm" Encoding="Ascii85">@J8FO2nldAU:MM2b.}cx/#u*rF38C(DM;9dWbsK(D]9?b$mWrnnVwO=e2j?XB*?:)ku@Lsr6hximCMK3CoHw7I5R)wjonBO1PvG%00</CESplitter1>
</Forms>
<CheatEntries>
<CheatEntry>
<ID>0</ID>
<ID>1</ID>
<Description>"MonoHelper"</Description>
<LastState/>
<VariableType>Auto Assembler Script</VariableType>
Expand Down Expand Up @@ -1580,17 +1580,22 @@ function mono.formClass:popupMethods_OnPopup(popup)

addMenuItem(popup, "miMethodsHook", "Hook", mono.formClass.methodHook)
addMenuItem(popup, "miMethodsHookEntry", "Hook (Table Entry)", mono.formClass.methodHookEntry)
addMenuItem(popup, "methodHookEntryOverridden", "Hook (Table Entry, Overridden)", mono.formClass.methodHookEntryOverridden)
addMenuItem(popup, "miMethodsDisassemble", "Disassemble", mono.formClass.methodDisassemble)
addMenuItem(popup, "miMethodsCreateTableScript", "Create Debug Entry", mono.formClass.methodCreateTableScript)
end

formMonoClass.popupMethods.OnPopup = function(sender) mono.formClass:popupMethods_OnPopup(sender) end

mono.formClass.methodHookEntryOverridden = function()
mono.formClass.methodHook(1, 1)
end

mono.formClass.methodHookEntry = function()
mono.formClass.methodHook(1)
end

mono.formClass.methodHook = function(entry_flag)
mono.formClass.methodHook = function(entry_flag, override_flag)
local self = mono.formClass
local method = self:getSelectedMethod()
if method == nil then
Expand All @@ -1610,7 +1615,39 @@ mono.formClass.methodHook = function(entry_flag)
]]

local lines = {}
table.insert(lines, "define(hook,"..hookInfo.hookString..")")

if override_flag then
local signature = mono_method_getSignature(method.id)
table.insert(lines, '{$lua}')
table.insert(lines, 'if syntaxcheck then return "define(hook,0)" end')
table.insert(lines, 'local class_id = mono_findClass("'..method.class.namespace..'", "'..method.class.name..'")')
table.insert(lines, 'local methods = mono_class_enumMethods(class_id)')
table.insert(lines, 'for i = 1,#methods do')
table.insert(lines, ' local m = methods[i]')
table.insert(lines, ' if m.name == "'..method.name..'" and mono_method_getSignature(m.method) == "'..signature..'" then')
table.insert(lines, ' local address = mono_compile_method(m.method)')
table.insert(lines, ' return string.format("define(hook,%x)",address)')
table.insert(lines, ' end')
table.insert(lines, 'end')
table.insert(lines, 'return nil, "COULD NOT FIND METHOD WITH SIGNATURE"')
table.insert(lines, '{$asm}')
--[[ This works in Underminer
if syntaxcheck then return "define(hook,0)" end
local class_id = mono_findClass("", "Inventory")
local methods = mono_class_enumMethods(class_id)
for i = 1,#methods do
local m = methods[i]
print(m.name.." signature: "..mono_method_getSignature(m.method))
if m.name == "TryRemoveItem" and mono_method_getSignature(m.method) == "Item,int" then
local address = mono_compile_method(m.method)
return string.format("define(hook,%x)",address)
end
end
return nil, "COULD NOT FIND METHOD WITH SIGNATURE"
]]
else
table.insert(lines, "define(hook,"..hookInfo.hookString..")")
end
table.insert(lines, "define(bytes,"..hookInfo.aobString..")")
table.insert(lines, "")
table.insert(lines, "[enable]")
Expand Down Expand Up @@ -1646,7 +1683,7 @@ mono.formClass.methodHook = function(entry_flag)
table.insert(lines, " jmp hook+"..string.format("%X", hookInfo.returnOffset))
table.insert(lines, "")
table.insert(lines, "hook:")
table.insert(lines, " jmp short newmem")
table.insert(lines, " jmp long newmem")
table.insert(lines, "")
table.insert(lines, "[disable]")
table.insert(lines, "")
Expand Down
43 changes: 40 additions & 3 deletions src/lua/forms/formClass.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,22 @@ function mono.formClass:popupMethods_OnPopup(popup)

addMenuItem(popup, "miMethodsHook", "Hook", mono.formClass.methodHook)
addMenuItem(popup, "miMethodsHookEntry", "Hook (Table Entry)", mono.formClass.methodHookEntry)
addMenuItem(popup, "methodHookEntryOverridden", "Hook (Table Entry, Overridden)", mono.formClass.methodHookEntryOverridden)
addMenuItem(popup, "miMethodsDisassemble", "Disassemble", mono.formClass.methodDisassemble)
addMenuItem(popup, "miMethodsCreateTableScript", "Create Debug Entry", mono.formClass.methodCreateTableScript)
end

formMonoClass.popupMethods.OnPopup = function(sender) mono.formClass:popupMethods_OnPopup(sender) end

mono.formClass.methodHookEntryOverridden = function()
mono.formClass.methodHook(1, 1)
end

mono.formClass.methodHookEntry = function()
mono.formClass.methodHook(1)
end

mono.formClass.methodHook = function(entry_flag)
mono.formClass.methodHook = function(entry_flag, override_flag)
local self = mono.formClass
local method = self:getSelectedMethod()
if method == nil then
Expand All @@ -276,7 +281,39 @@ mono.formClass.methodHook = function(entry_flag)
]]

local lines = {}
table.insert(lines, "define(hook,"..hookInfo.hookString..")")

if override_flag then
local signature = mono_method_getSignature(method.id)
table.insert(lines, '{$lua}')
table.insert(lines, 'if syntaxcheck then return "define(hook,0)" end')
table.insert(lines, 'local class_id = mono_findClass("'..method.class.namespace..'", "'..method.class.name..'")')
table.insert(lines, 'local methods = mono_class_enumMethods(class_id)')
table.insert(lines, 'for i = 1,#methods do')
table.insert(lines, ' local m = methods[i]')
table.insert(lines, ' if m.name == "'..method.name..'" and mono_method_getSignature(m.method) == "'..signature..'" then')
table.insert(lines, ' local address = mono_compile_method(m.method)')
table.insert(lines, ' return string.format("define(hook,%x)",address)')
table.insert(lines, ' end')
table.insert(lines, 'end')
table.insert(lines, 'return nil, "COULD NOT FIND METHOD WITH SIGNATURE"')
table.insert(lines, '{$asm}')
--[[ This works in Underminer
if syntaxcheck then return "define(hook,0)" end
local class_id = mono_findClass("", "Inventory")
local methods = mono_class_enumMethods(class_id)
for i = 1,#methods do
local m = methods[i]
print(m.name.." signature: "..mono_method_getSignature(m.method))
if m.name == "TryRemoveItem" and mono_method_getSignature(m.method) == "Item,int" then
local address = mono_compile_method(m.method)
return string.format("define(hook,%x)",address)
end
end
return nil, "COULD NOT FIND METHOD WITH SIGNATURE"
]]
else
table.insert(lines, "define(hook,"..hookInfo.hookString..")")
end
table.insert(lines, "define(bytes,"..hookInfo.aobString..")")
table.insert(lines, "")
table.insert(lines, "[enable]")
Expand Down Expand Up @@ -312,7 +349,7 @@ mono.formClass.methodHook = function(entry_flag)
table.insert(lines, " jmp hook+"..string.format("%X", hookInfo.returnOffset))
table.insert(lines, "")
table.insert(lines, "hook:")
table.insert(lines, " jmp short newmem")
table.insert(lines, " jmp long newmem")
table.insert(lines, "")
table.insert(lines, "[disable]")
table.insert(lines, "")
Expand Down

0 comments on commit 739b59c

Please sign in to comment.