Page 1 of 1

Addressing or Jump to Method that shared same name.

Posted: Sat Oct 09, 2021 9:44 am
by TheByteSize
I got 2 methods that has same name but difference in number of variable inputs.
For example got these 2.

Code: Select all

dothing:init(a,b,c,d)
dothing:init(e)
then if I use

Code: Select all

mono_compile_method(mono_getJitInfo(getAddress('dothing:init')).method)
CE will compile both.
now if I try to jump to dothing:init, it will always jump to whichever compiled first.
So, how do I get address for each of these methods?

Re: Addressing or Jump to Method that shared same name.

Posted: Sat Oct 09, 2021 12:19 pm
by GreenHouse
You could do this, might not be the best, but if you can see any way to improve it, go ahead.
Gets class, enumerates methods inside, then iterates between all methods and checks if the name and the parameters are the same. If so, then print.

Code: Select all

local methods = mono_class_enumMethods(mono_findClass('','Player'))

for i = 1,#methods do
if methods[i].name == 'UnlockSticker' and mono_method_getSignature(methods[i].method) == 'string,bool' then
print(mono_method_getSignature(methods[i].method)) --Do Compile Here
end end

Re: Addressing or Jump to Method that shared same name.

Posted: Sat Oct 09, 2021 1:15 pm
by DhaosCollider
TheByteSize wrote:
Sat Oct 09, 2021 9:44 am
...
If getAddress('doing:init') is true, it means that the JIT compilation has already been executed, right?
Do you need mono_compile_method?

Anyway, I think it's C# method overloading.
Since the array of bytes should be different, I think it's easiest to use Auto Assembler:aobScanRegion to get the address.
TheByteSize wrote:
Sat Oct 09, 2021 10:05 pm
unfortunately, aobscanregion(x,dothing:init,dothing:init+aaa,0xf) will jump which ever method get compiled first.
Can't methods with the same name be separated by the 0xf part (signature)?
If you can't do that, if I were you, I would consider other places to hook. Good luck.

Re: Addressing or Jump to Method that shared same name.

Posted: Sat Oct 09, 2021 10:05 pm
by TheByteSize
GreenHouse wrote:
Sat Oct 09, 2021 12:19 pm
thanks for the idea.
DhaosCollider wrote:
Sat Oct 09, 2021 1:15 pm
If getAddress('doing:init') is true, it means that the JIT compilation has already been executed, right?
Do you need mono_compile_method?

Anyway, I think it's C# method overloading.
Since the array of bytes should be different, I think it's easiest to use Auto Assembler:aobScanRegion to get the address.
unfortunately, aobscanregion(x,dothing:init,dothing:init+aaa,0xf) will jump which ever method get compiled first.

I'm currently word around this problem by giving the end of region address to be have stupid large address.

Re: Addressing or Jump to Method that shared same name.

Posted: Sat Oct 09, 2021 11:17 pm
by aSwedishMagyar
I asked the same question some time ago here

I have since simplified the functions in that post and you can use this:

The findMethodBySignature function:

Code: Select all

function findMethodBySignature(nameSpace,className,methodName,signature)
    local classId = mono_findClass(nameSpace,className)
    local methodTable = mono_class_enumMethods(classId)
    for i = 1,#methodTable do
        local currentMethod = methodTable[i]
        if currentMethod.name == methodName then
            local sig = mono_method_getSignature(currentMethod.method)
            if sig:match(signature) then return currentMethod.method end
        end
    end
    return nil
end
And how to use it:

Code: Select all

local nameSpace = ''
local className = ''
local methodName = ''
local signature = ''
local methId = findMethodBySignature(nameSpace,className,methodName,signature)
if methId ~= nil then
    local methAddr = mono_compile_method(methId)
    unregisterSymbol('myMethod')
    registerSymbol('myMethod',methAddr)
end

Re: Addressing or Jump to Method that shared same name.

Posted: Sun Oct 10, 2021 1:13 am
by TheByteSize
I got it working but now ....
aSwedishMagyar wrote:
Sat Oct 09, 2021 11:17 pm
I'll use that clean structured code. Thank you all.