can't invoke a mono method that return a string

Anything Cheat Engine related, bugs, suggestions, helping others, etc..
Post Reply
Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

can't invoke a mono method that return a string

Post by Spazi »

Hi,

Like the title says, I get a crash when trying to invoke any method that has a return type of String (lua crash on "return monopipe.readString(resultlength);").
Is there a way to force mono_invoke to return the string address instead, so I do the string reading myself ?

Thank you

Eric
Hall of Famer
Hall of Famer
Posts: 174
Joined: Thu Mar 02, 2017 11:01 pm
Reputation: 90

Re: can't invoke a mono method that return a string

Post by Eric »

replace your mono collector dll's with the ones in these and then try. (There was an error with mono_free) [Link]

extract to your ce base folder/autorun/dll folder

Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

Re: can't invoke a mono method that return a string

Post by Spazi »

Wow, did not expect a response so fast.
I had already made a custom dll in the meantime, but an official correct solution is always better.
Thank you, will put it to good use

Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

Re: can't invoke a mono method that return a string

Post by Spazi »

Well, actually, just tested, it still crashed with yours on the game I'm testing :/
Same thing, it crash on getting the string from pipe

Eric
Hall of Famer
Hall of Famer
Posts: 174
Joined: Thu Mar 02, 2017 11:01 pm
Reputation: 90

Re: can't invoke a mono method that return a string

Post by Eric »

most mono games have no anti debug so you can debug the dll sourcecode with visual studio while attached to the game
perhaps you can see and fix it

and don't forget to close the game before compiling/replacing else the test will be done on the old dll

Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

Re: can't invoke a mono method that return a string

Post by Spazi »

I get a "Write acces violation" exception from the call to 'mono_type_get_type' in 'WriteObject'

I'll see if I can go into the mono function with Mono sources to have more detail

Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

Re: can't invoke a mono method that return a string

Post by Spazi »

Disregard pervious message, was because I was going step by step and, cheat engine was putting the pipe to a faulty behavior.

So, exception is on :
void *string = mono_object_to_string(object, NULL);

in WriteObject, and is a Read access violation.
Will try to know more

Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

Re: can't invoke a mono method that return a string

Post by Spazi »

(Or you could implement a workaround in this case, and have Lua read the string instead of Mono, like I did :D
Would save me a lot of hours I think '^^

I had Lua read a net string like this, to circumvent that invoke problem (and added another invoke method to MonoDataCollector that return the string address instead of trying to read it)

Code: Select all

local _readNetStringIT = nil
local _readNetStringCE = 0
local _readNetStringMN = nil
function readNetString(addr)
    local classid, classname = mono_object_getClass(addr)
    if classname ~= 'String' then return nil end

    if _readNetStringIT == nil then
       for _, m in pairs(mono_class_enumMethods(classid)) do
           if m.name == 'System.Collections.IEnumerable.GetEnumerator' then _readNetStringIT = m.method end
       end
    end

    local it = mono_invoke_method(nil,_readNetStringIT,addr,{})

    if _readNetStringMN == nil then
       for _, m in pairs(mono_class_enumMethods(mono_object_getClass(it))) do
           if m.name == 'MoveNext' then _readNetStringMN = m.method end
       end
       for _, f in ipairs(mono_class_enumFields(mono_object_getClass(it))) do
           if f.name == 'currentElement' then _readNetStringCE = f.offset end
       end
    end

    local sread = ''
    local mn = mono_invoke_method(nil, _readNetStringMN, it, {})
    repeat
          sread = sread .. readString(it+_readNetStringCE, 1)
          mn = mono_invoke_method(nil, _readNetStringMN, it, {})
    until mn == 0

    return sread
end
)

Eric
Hall of Famer
Hall of Famer
Posts: 174
Joined: Thu Mar 02, 2017 11:01 pm
Reputation: 90

Re: can't invoke a mono method that return a string

Post by Eric »

perhaps you can skip mono_object_to_string and just call mono_string_to_utf8 directly(havn't tested yet)

Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

Re: can't invoke a mono method that return a string

Post by Spazi »

Okay, it worked with commenting the "object_to_string" and changing the paramater for to_utf8 :)

I'll wait your official dll builds

Spazi
Cheater
Cheater
Posts: 25
Joined: Mon Sep 04, 2017 3:51 am
Reputation: 12

Re: can't invoke a mono method that return a string

Post by Spazi »

There is another problem with current invoke implementation, and parameters.

What you did works fine for value type, but it will always crash when passing any object parameter.
That is because the array you create and give to mono_invoke is malformed for object parameters.

Current implementation "box" everything, which is good only for value type. For object, you need to send the address, not box the address

I fixed it for me, for vtPointer parameter, by modifying the ReadObject function :

Code: Select all

	case MONO_TYPE_PTR:
		if (size > 0)
		{
			Read(addr, size);
			result = (void *) *((UINT64*)addr);
		}
		break;
	case MONO_TYPE_BYREF:
	case MONO_TYPE_CLASS:
	case MONO_TYPE_FNPTR:
	case MONO_TYPE_GENERICINST:
	case MONO_TYPE_ARRAY:
	case MONO_TYPE_SZARRAY:
		if (size > 0)
		{
			Read(addr, size);
		}
		break;
	}
Haven't tested for arrays and the like, but since in lua, we can only send vtPointer, that should cover it already

Post Reply

Who is online

Users browsing this forum: No registered users