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 


I Need Performance

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
maskelihileci
Cheater
Reputation: 0

Joined: 08 Oct 2016
Posts: 43

PostPosted: Thu Jun 16, 2022 9:14 pm    Post subject: I Need Performance Reply with quote

My goal is to list all the vtable addresses of a game and write a plugin on it.
But I am having performance problems.

The cheat engine is starting a new thread for each scan. I think this is a performance loss.

Do you think a touch can be made to the code below that will increase its performance?

Code:

function scannames()

s=createMemScan()

s.firstScan(soExactValue, vtString, rtRounded, '.?AV', '', getAddress(process) ,getAddress(process)+getAddress(getModuleSize(process)) ,"*W*X*C" ,fsmNotAligned ,'1' ,false ,true, false, true);
s.waitTillDone()

fl=createFoundList(s)

names={}
fl.initialize()

sll=createStringList()
for i=1,fl.Count do
  local a=tonumber(fl[i-1],16)
  names[i]={}
  names[i].name=readString(tonumber(fl[i-1],16)+4)
  names[i].address=a-0x10
  sll.add(names[i].name)
end

end

scannames()

for r=1,fl.Count do

if (r==-1) then return end

a=names[r+1].address
if targetIs64Bit() then
  a=a-getAddress(process)
end


s=createMemScan() --- missing code

fl.deinitialize()
s.firstScan(soExactValue, vtDword, rtRounded, string.format("%x",a), '', getAddress(process) ,getAddress(process)+getAddress(getModuleSize(process)) ,"*W*X*C" ,fsmAligned ,'4' ,true ,true, false, true);
s.waitTillDone()

fl=createFoundList(s) --- missing code


fl.initialize()

RTTIInfo={}
for i=1,fl.Count do
  local a=tonumber(fl[i-1],16)
  a=a-12
  if readBytes(a,1)==1 then
    table.insert(RTTIInfo,a)
  end
end


if targetIs64Bit() then
  scantype=vtQword
  pointersize=8
else
  scantype=vtDword
  pointersize=4
end

vtables={}

for i=1,#RTTIInfo do
  a=RTTIInfo[i]
  fl.deinitialize()
  s.firstScan(soExactValue, scantype, rtRounded, string.format("%x",a), '', getAddress(process) ,getAddress(process)+getAddress(getModuleSize(process)) ,"*W*X*C" ,fsmAligned ,'4' ,true ,true, false, true);
  s.waitTillDone()
  fl.initialize()

  for j=1,fl.Count do
    table.insert(vtables, tonumber(fl[j-1],16)+pointersize)
  end
end



instances={}

for i=1,#vtables do
  a=vtables[i]
  fl.deinitialize()
  s.firstScan(soExactValue, scantype, rtRounded, string.format("%x",a), '', 0 ,0xffffffffffffffff ,"*W*X*C" ,fsmAligned ,'4' ,true ,true, false, true);
  s.waitTillDone()
  fl.initialize()

  for j=1,fl.Count do
    table.insert(instances, tonumber(fl[j-1],16))
  end
end


for i=1,#instances do
 print(sll[r])
 print(string.format("%x",instances[i])) -- adress class
end

end

Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4293

PostPosted: Fri Jun 17, 2022 12:03 am    Post subject: Reply with quote

I started reading your code (after using a tool to format it), but gave up shortly after the end of the first function. Mutable global state is bad (use local variables), the first function shouldn't even be a function, and there's code that's completely pointless (`if (r==-1) ...`: `r` will never be -1 because fl.Count is unsigned).

Using better protection flags will make scans faster ("*W*X*C" is almost always unnecessary).
You're leaking memscans every time you call createMemScan after the first call.
Maybe think about memoizing scans to not repeat work.
Likely other stuff.

No clue what algorithm you're using to identify vtables.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
maskelihileci
Cheater
Reputation: 0

Joined: 08 Oct 2016
Posts: 43

PostPosted: Fri Jun 17, 2022 10:18 am    Post subject: Reply with quote

ParkourPenguin wrote:
I started reading your code (after using a tool to format it), but gave up shortly after the end of the first function. Mutable global state is bad (use local variables), the first function shouldn't even be a function, and there's code that's completely pointless (`if (r==-1) ...`: `r` will never be -1 because fl.Count is unsigned).

Using better protection flags will make scans faster ("*W*X*C" is almost always unnecessary).
You're leaking memscans every time you call createMemScan after the first call.
Maybe think about memoizing scans to not repeat work.
Likely other stuff.

No clue what algorithm you're using to identify vtables.


Code:
if (r==-1)


Here I want the for loop to continue until the end
It stops after giving an error but it seems like I have no other choice because I don't know how many results are in the list.
If I knew how many results were in the list, I could try to compare with it.

createMemScan When I don't use it, no results can be found.

https://forum.cheatengine.org/viewtopic.php?t=613639&sid=3a7b69de5c3b62d0db7619e66a3cad4d


A MemScan was created in the original dark byte code, but this does not yield any results.
I had to create more than one to get it to work, maybe there is a different solution.

You asked about the logic of the algorithm, it is explained in this topic.

https://framedsc.com/GeneralGuides/using_rtti.htm
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