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 


Search for AOB and change their values

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

Joined: 30 Sep 2017
Posts: 17

PostPosted: Sat Sep 30, 2017 4:37 pm    Post subject: Search for AOB and change their values Reply with quote

Hello I have some arrays of bytes that I want search for their occurrence and change their values to
'01 00 00 00 00 00 00 00 01 00'.

I tried the following Lua code but no success:

Code:
function replace(searchV, replaceV)
  if type(searchV) ~= "table" then
    searchV = {(assert(tonumber(searchV),"Could not convert first argument to number"))}
  end
  replaceV = math.floor(replaceV)

  for i,v in ipairs(searchV) do
    local res = AOBScan(v, "+W-C", 1, 4)
    if res then
      for j=0, res.Count-1, 1 do
        writeInteger(res[j], replaceV)
      end
      res.destroy()
    end
  end
end

local aobs = {
'F4 01 00 00 D0 07 00 00 F4 01',
'20 03 00 00 F4 01 00 00 20 03',
'E8 03 00 00 DC 05 00 00 20 03',
'FA 00 00 00 00 00 00 00 26 02',
'78 05 00 00 00 00 00 00 58 02',
'C8 00 00 00 00 00 00 00 78 05',
'C8 00 00 00 00 00 00 00 08 07',
'F4 01 00 00 00 00 00 00 F4 01',
'20 03 00 00 E8 03 00 00 20 03',
'03 00 00 E8 03 00 00 20 03',
'20 03 00 00 00 00 00 00 20 03'
}

replace(aobs, '01000000000000000100')


Can you tell me what part I am missing or if their is a better method to do it?
Thank you!
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sat Sep 30, 2017 9:37 pm    Post subject: Reply with quote

Code:
replaceV = math.floor(replaceV)


indicates that the function expects the replacement value to be a number. If you want to use an aob I'd suggest a couple changes:

Code:
function replace(searchV, replaceV)
  if type(searchV) ~= "table" then
    searchV = {(assert(tonumber(searchV),"Could not convert first argument to number"))}
  end
  -- removed the math.floor which doesn't make sense for an aob

  for i,v in ipairs(searchV) do
    local res = AOBScan(v, "+W-C", 1, 4)
    if res then
      for j=0, res.Count-1, 1 do
        writeBytes(res[j], replaceV) -- use writeBytes for an array/table of bytes
      end
      res.destroy()
    end
  end
end

local aobs = {
'F4 01 00 00 D0 07 00 00 F4 01',
'20 03 00 00 F4 01 00 00 20 03',
'E8 03 00 00 DC 05 00 00 20 03',
'FA 00 00 00 00 00 00 00 26 02',
'78 05 00 00 00 00 00 00 58 02',
'C8 00 00 00 00 00 00 00 78 05',
'C8 00 00 00 00 00 00 00 08 07',
'F4 01 00 00 00 00 00 00 F4 01',
'20 03 00 00 E8 03 00 00 20 03',
'03 00 00 E8 03 00 00 20 03',
'20 03 00 00 00 00 00 00 20 03'
}

-- pass a table of bytes rather than a string that you would have to parse into bytes
replace(aobs, {01,00,00,00,00,00,00,00,01,00})


That does depend on you always wanting to replace all of the found aobs with the same array of bytes. If you don't want that you'd need to make multiple calls.

if that still doesn't work then replace -AOBScan(v, "+W-C", 1, 4)- with -AOBScan(v)-, it'll probably take longer to do the scans, but it's more likely to find them in case you accidentally messed up one of the restrictions (like it being not copy on write or 4 byte aligned). And potentially add some print statements to show you whether anything is being found or not eg (if res then print('found ', v, 'at ', res[0] end).
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Sep 30, 2017 10:04 pm    Post subject: Reply with quote

http://forum.cheatengine.org/viewtopic.php?p=5620925
Back to top
View user's profile Send private message
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 17

PostPosted: Sun Oct 01, 2017 6:13 pm    Post subject: Reply with quote

Thank you FreeER for your time and comprehensive answer.

Worked perfectly!


I have another question, is there a way to save this code as trainer to run with a specific process.

I pasted this script in the Lua script: Cheat Table and then clicked:
File > Save as... > Cheat Engine Trainer Standalone (*.EXE)

But when I run it, nothing happens!

Any help will be appreciated.

Thank you!
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Oct 01, 2017 7:29 pm    Post subject: Reply with quote

aitboss wrote:
I have another question, is there a way to save this code as trainer to run with a specific process.

Go to File->"Generate generic trainer lua script from table" change the output to "Script Only" and then generate, then add your own code to that
Code:
... -- generated code

function replace(searchV, replaceV)
  ... -- function code
end

local aobs = {
'F4 01 00 00 D0 07 00 00 F4 01', ... -- all your aobs
}

-- will call function when the process is actually opened
function onOpenProcess(pid)
  reinitializeSymbolhandler() -- call to force the open to complete
  replace(aobs, {01,00,00,00,00,00,00,00,01,00}) -- call replace function
end


And then you can save it as an exe (though you'd probably want to tweak the GUI some, there should be several tutorials for making trainers with CE on youtube that show how to manipulate the GUI if it's not obvious)
Back to top
View user's profile Send private message
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 17

PostPosted: Sun Oct 01, 2017 10:59 pm    Post subject: Reply with quote

Thank you!

Is there a way to make the generated trainer runs independently from the Cheat Engine? (as I noticed it requires that the user have Cheat Engine installed)
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1587

PostPosted: Mon Oct 02, 2017 12:33 am    Post subject: Reply with quote

aitboss wrote:
Thank you!

Is there a way to make the generated trainer runs independently from the Cheat Engine? (as I noticed it requires that the user have Cheat Engine installed)

dont choose "tiny" when generating.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote:
i am a sweetheart.
Back to top
View user's profile Send private message Visit poster's website
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 17

PostPosted: Mon Oct 02, 2017 10:51 pm    Post subject: Reply with quote

I tried the gigantic method and it made the trainer runs without requiring the CE to be installed.
My the problem is when the trainer runs, it extracts and run the required executable files which are detected by the system. The game security system will close the process Cheat Engine.exe if it is running and so the trainer will close as well.

Is there a way to rename the processes that are being run by the trainer with the lua code or by including an exterior library to do so?

Thank You!
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1587

PostPosted: Tue Oct 03, 2017 2:24 am    Post subject: Reply with quote

there is a way to rename the process name, and this question have been answered week ago or so.
tried to find that topic but i couldnt, hope someone link you to that topic.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote:
i am a sweetheart.
Back to top
View user's profile Send private message Visit poster's website
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 17

PostPosted: Tue Oct 03, 2017 7:20 pm    Post subject: Reply with quote

But I don't want to rename the trainer process.
In the task manager there is "Cheat Engine" process opened by the trainer, which I want to rename, so the game security don't close it.
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