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 


CE Structure Lookup

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3325

PostPosted: Fri Dec 29, 2023 3:23 pm    Post subject: CE Structure Lookup Reply with quote

Hello,
I build a LUA script that extracts the name of a structure from RTTI.
How do I pass this to CE so it would recognize the name on 'Define'? (so it would tell me this structure already exists and it would be automatically loaded)?
Also, how would I scan the memory for structures matching a specific name?
Thank you!
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1522

PostPosted: Sat Dec 30, 2023 4:37 pm    Post subject: Reply with quote

I'm not sure this is what you want.
Still, some explanation would be nice.

Since reading and manipulating the list in code causes problems, I left a function that adds the list to the autorun folder and reads it from there.

Code:
function CE_FullDefined()
tbl = "" --{}
  for k, v in pairs(_G) do
    if (v ~= nil and type(v) == 'table') then
        --print(1,k);
        --tbl[#tbl + 1] = v
        for kk, vv in pairs(v) do
          res = string.format('%s.%s (%s)',k, kk, type(vv))
          --print(res);
          --tbl[#tbl + 1] = res
          tbl = tbl..res.."\n"
        end
    end
  end
 return tbl
end

local list_of_items = {}
local path = getAutorunPath()..[[def1.lua]]

function save_def()
list = CE_FullDefined()
file = io.open(path, "w")
file:write(list)
file.close()
end
--Enable this on the first installation and create the required file with the list.
--save_def()

function src_def(s)
res = ""
local string_to_find = s
local new_list = {}
for i, v in ipairs(list_of_items) do
  if v:find(string_to_find) then
    table.insert(new_list, v)
  end
end

  if #new_list==0 then
   res = s.."  undefined!"
  else
   for i, v in ipairs(new_list) do
    res = res..v.."\n"
   end
   res = res.." defined.."
  end
return res
end
--###############################################
if df1 then df1.Destroy() df1=nil end
DP1=getScreenDPI()/96
df1=createForm()
df1.height=139*DP1 df1.width=236*DP1 df1.left=346*DP1 df1.top=147*DP1
df1.PopupMode=0 df1.caption="Search  Defined Form"
df1.Position="poDesktopCenter" df1.BorderStyle="bsSingle"  df1.ShowInTaskBar="stAlways"
-------------------------
local srcdfn = {}
----------------------- srcdfn.btn1 ----- 
srcdfn.btn1=createButton(df1)
srcdfn.btn1.AutoSize=false
srcdfn.btn1.height=25*DP1 srcdfn.btn1.width=151*DP1 srcdfn.btn1.left=44*DP1 srcdfn.btn1.top=13*DP1
srcdfn.btn1.caption="Load  Defined  List"
srcdfn.btn1.Font.Style="fsBold" srcdfn.btn1.Font.Size=10*DP1
-----------------------
----------------------- srcdfn.edt1 ----- 
srcdfn.edt1=createEdit(df1)
srcdfn.edt1.AutoSize=true
srcdfn.edt1.height=23*DP1 srcdfn.edt1.width=204*DP1 srcdfn.edt1.left=16*DP1 srcdfn.edt1.top=60*DP1
srcdfn.edt1.text=""
srcdfn.edt1.alignment="taLeftJustify"
srcdfn.edt1.Font.Style="fsBold" srcdfn.edt1.Font.Size=10*DP1
-----------------------
----------------------- srcdfn.btn2 ----- 
srcdfn.btn2=createButton(df1)
srcdfn.btn2.AutoSize=false
srcdfn.btn2.height=25*DP1 srcdfn.btn2.width=151*DP1 srcdfn.btn2.left=44*DP1 srcdfn.btn2.top=100*DP1
srcdfn.btn2.caption="Search  Defined"
srcdfn.btn2.Font.Style="fsBold" srcdfn.btn2.Font.Size=10*DP1
-----------------------
srcdfn.edt1.Enabled=false
srcdfn.btn2.Enabled=false
srcdfn.edt1.Text = "math.sin" --sample

srcdfn.btn1.OnClick=function()

--load list (table)
file = io.open(path, "r")
res1 = file:read("*a")
file.close()
 sl = createStringList()
 sl.Text = res1
  for i=0, sl.count -1 do
   res2 = sl[i]
    if res2~="" then
     list_of_items[i + 1] = res2
    end
  end

srcdfn.edt1.Enabled=true
srcdfn.btn2.Enabled=true
end

srcdfn.btn2.OnClick=function()
 if srcdfn.edt1.Text=="" then
  showMessage("Please type the text to search for in the box!")
 else
  def1 = src_def(srcdfn.edt1.Text)
  print(def1)
 end
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3325

PostPosted: Wed Jan 03, 2024 7:40 am    Post subject: Reply with quote

Thanks! However, I am not sure I follow.

I have a LUA function that looks like this: GetRTTIName("0x123456790") and this function prints out the string, when found. I guess I'd need to adapt it to return the string.
But.
How would I have CE call this function with the pointer when I right-click and select Define in the first place?

Happy New Year!
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25797
Location: The netherlands

PostPosted: Wed Jan 03, 2024 8:26 am    Post subject: Reply with quote

Code:

if mystructnamelookup then
  unregisterStructureNameLookup(mystructnamelookup)
end

mystructnamelookup=registerStructureNameLookup(function(address)
  local s=getRTTIClassName(address) --yes, this function already exists
  if s==nil then
    s=string.format('The structure based of address %x (no RTTI info detected)',address)
  end

  return s
end)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3325

PostPosted: Thu Jan 04, 2024 2:29 pm    Post subject: Reply with quote

Dark Byte wrote:
Code:

if mystructnamelookup then
  unregisterStructureNameLookup(mystructnamelookup)
end

mystructnamelookup=registerStructureNameLookup(function(address)
  local s=getRTTIClassName(address) --yes, this function already exists
  if s==nil then
    s=string.format('The structure based of address %x (no RTTI info detected)',address)
  end

  return s
end)

Works, thanks!
However, CE does not offer me the "structure already exists" option to create a new one or load the existing one.
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 Lua Scripting 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