Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Bug] Duplicate Class IDs Issue in Mono Tool

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
agpcheatengine
Newbie cheater
Reputation: 0

Joined: 07 Nov 2018
Posts: 12

PostPosted: Sat Mar 23, 2024 1:25 am    Post subject: [Bug] Duplicate Class IDs Issue in Mono Tool Reply with quote

I would like to report an issue regarding the use of the same class names to represent identical classes in different images within the Mono tool.
Test:
Code:
local class= mono_findClass('Assembly-CSharp','OptionsMenu')
local class2 = mono_findClass('Assembly-UnityScript','OptionsMenu')
return class==class2

1:true

System:
Cheat Engine:7.5
windows 10
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 943

PostPosted: Sat Mar 23, 2024 3:30 am    Post subject: Reply with quote

function mono_findClass(namespace, classname)
The first param is namespace not assembly name, likely it return class==class2 true because both call return nil, check it.

What you need to call may be:
mono_image_findClass(image, namespace, classname)
An assemblyName (as string) has a matching image (the param is a number).
Sample code to find the image number matching an assemblyName,
Code:

-- return image number from assembly name, or nil
function assName2Image(assemblyName)
  local ass = mono_enumAssemblies()
  for i=1, #(ass or {}) do
    local image = mono_getImageFromAssembly(ass[i])
    local imagename = mono_image_get_name(image)
    if imagename == assemblyName then
      return image
    end     
  end
end

May check the source of monoscript @ autorun directory.

_________________
- Retarded.
Back to top
View user's profile Send private message
agpcheatengine
Newbie cheater
Reputation: 0

Joined: 07 Nov 2018
Posts: 12

PostPosted: Sat Mar 23, 2024 7:27 am    Post subject: duplicate class problem Reply with quote

panraven wrote:
function mono_findClass(namespace, classname)
The first param is namespace not assembly name, likely it return class==class2 true because both call return nil, check it.

What you need to call may be:
mono_image_findClass(imageID, namespace, classname)
An assemblyName (as string) has a matching image (the param is a number).
Sample code to find the image number matching an assemblyName,
Code:

-- return image number from assembly name, or nil
function assName2Image(assemblyName)
  local ass = mono_enumAssemblies()
  for i=1, #(ass or {}) do
    local image = mono_getImageFromAssembly(ass[i])
    local imagename = mono_image_get_name(image)
    if imagename == assemblyName then
      return image
    end     
  end
end

May check the source of monoscript @ autorun directory.

Code:

return getAddress('Assembly-CSharp.OptionsMenu::.ctor')

1:92525824
return getAddress('Assembly-CSharp.OptionsMenu::.ctor')==getAddress('Assembly-UnityScript.OptionsMenu::.ctor')

1:true

When I entered two different addresses in the "go to address" tool within the memory view, it went to the same address, or when I called different addresses using getAddress in the Lua engine, it still went to the same address.
In the example provided in the link(wiki.cheatengine .org/index.php?title=Mono:Lua:mono_findMethod), the namespace 'Assembly-CSharp' is used, which is why I used it as well.
The application crashes when I use the method "mono_image_findClass(imageID, namespace, classname)", so I haven't been able to test it. I have resolved my own issue with the following code. However, "duplicate class problem" still continues .
Code:
function mono_find_classes(namespace,classname)
 local ass=mono_enumAssemblies()
 local classes,k={},1
 if string.find(classname,':') then parent=classname:sub(1,string.find(classname,':')-1) classname=classname:sub(string.find(classname,':')+1,classname:len()) end
 if ass==nil then return nil end
 for i=1, #ass do
 if monopipe==nil then print('mono not active...')return 0 end
 local c=mono_image_enumClasses(mono_getImageFromAssembly(ass[i]))
 if c then
 local j
 for j=1, #c do
 if c[j].namespace==namespace and string.find(c[j].classname,classname) then classes[k]=c[j] k=k+1 end
 end
 end
 end
 return classes
end
function mono_findMethodAdress(namespace,classname,methodname)
 if not namespace then namespace='' end
 local class=mono_find_classes(namespace,classname)
 local result,m,methods={},1
 for i=1,#class do
 methods = mono_class_enumMethods(class[i].class,false)
 for l,v in ipairs(methods) do
 if v.name==methodname and class[i].classname==classname  then
 result= mono_compile_method(v.method) m=m+1 end end
 end
 return result
end

The problem was that a method existed in one case but not in the other, which is why this code worked. However, in the same method, this code will not be effective.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 943

PostPosted: Sat Mar 23, 2024 1:33 pm    Post subject: Reply with quote

[Updated] nvm, I mixed thing up, the title said class id, not function address.

Wait, is it an il2cpp game (there is GameAssembly.dll beside the <game>.exe)?
In il2cpp, address of some simple function that has exactly same bytes (cpu instructions) and length may be shared.
If not il2cpp, then I've no idea.

_________________
- Retarded.
Back to top
View user's profile Send private message
agpcheatengine
Newbie cheater
Reputation: 0

Joined: 07 Nov 2018
Posts: 12

PostPosted: Sun Mar 24, 2024 12:58 am    Post subject: Reply with quote

panraven wrote:
[Updated] nvm, I mixed thing up, the title said class id, not function address.

Wait, is it an il2cpp game (there is GameAssembly.dll beside the <game>.exe)?
In il2cpp, address of some simple function that has exactly same bytes (cpu instructions) and length may be shared.
If not il2cpp, then I've no idea.

I think I found the reason for the problem. Whenever I use any word instead of <anyword> in the format "<anyword>.OptionsMenu::.ctor", it always goes to the same address. There are no error messages. It's probably not working with the image name, which is why it always shows the same address. yes its il2cpp game.

Edit: I have edited the 'monoscript.lua' file, and now it supports the image name.
Code:
function mono_findClass(namespace, classname, imagename)
...
if fullnamerequested == false then
    for i = 1, #ass do
        image = mono_getImageFromAssembly(ass[i])
        result = mono_image_findClass(image, namespace, classname)
        if (result ~= 0) then
            if (imagename ==nil or imagename == "" or imagename == mono_image_get_name(image)) then
                return result
            end
        end
    end
end

--still here:

for i = 1, #ass do
    image = mono_getImageFromAssembly(ass[i])
    result = mono_image_findClassSlow(image, namespace, classname)
    if (result ~= 0) then
        if (imagename ==nil or imagename == "" or imagename == mono_image_get_name(image)) then
            return result
        end
    end
end
...



monoscript.lua
 Description:
added image name to adress

Download
 Filename:  monoscript.lua
 Filesize:  147.79 KB
 Downloaded:  25 Time(s)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites