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 


Restore original OAB 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: 16

PostPosted: Tue May 15, 2018 6:32 am    Post subject: Restore original OAB values Reply with quote

Hello!

I have a code that searchs for and replaces some AOBs:

Code:

function replace(searchV, replaceV)
  if type(searchV) ~= "table" then
    searchV = {(assert(tonumber(searchV),"Could not convert first argument to number"))}
  end
 
  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)
      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 are parsed into bytes
replace(aobs, {01,00,00,00,00,00,00,00,01,00})


Is there a way to restore the values to its original values after they have been replaced.

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

Joined: 09 Aug 2013
Posts: 996

PostPosted: Tue May 15, 2018 7:06 am    Post subject: Reply with quote

Keep track of the addresses you found and when you want to change them back loop through and write bytes from the original AOB that found it back (if you had wildcards you'd also need to keep track of the original bytes before overwriting them)
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 16

PostPosted: Wed May 16, 2018 2:57 am    Post subject: Reply with quote

Thanks FreeER.
May you kindly give me an example of how to do it please. I can't figure a correct way to do keep track of found addresses and restore them without errors.

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

Joined: 09 Aug 2013
Posts: 996

PostPosted: Wed May 16, 2018 5:20 am    Post subject: Reply with quote

Code:
someTableToStoreAddresses = {}
function replace(searchV, replaceV)
  if type(searchV) ~= "table" then
    searchV = {(assert(tonumber(searchV),"Could not convert first argument to number"))}
  end
 
  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
        someTableToStoreAddresses[res[j]] = v -- save address and aob
        writeBytes(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'
}

-- pass a table of bytes rather than a string that are parsed into bytes
replace(aobs, {01,00,00,00,00,00,00,00,01,00})

-- whenever you want to restore them loop over saved addresses
for k,v in pairs(someTableToStoreAddresses) do
    FunctionToWriteAOBStringToAddress(k,v)
end

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 16

PostPosted: Tue May 22, 2018 9:32 pm    Post subject: Reply with quote

Many thanks for your time FreeER.
Back to top
View user's profile Send private message
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 16

PostPosted: Tue Feb 12, 2019 4:04 am    Post subject: Reply with quote

FreeER wrote:
Code:

-- whenever you want to restore them loop over saved addresses
for k,v in pairs(someTableToStoreAddresses) do
    FunctionToWriteAOBStringToAddress(k,v)
end


How can I iterate through the table named "someTableToStoreAddresses" and restore the values?

I tried:
Code:

for k,v in pairs(someTableToStoreAddresses) do
    writeBytes(someTableToStoreAddresses[v], v)
end


but it is not working.
How can I iterate through the table and print the values?

I am not expert in lua and hope if somebody kindly help me.
Thanks!
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 24

Joined: 24 Feb 2017
Posts: 733
Location: 'Merica

PostPosted: Tue Feb 12, 2019 4:25 am    Post subject: Reply with quote

Maybe this will help.

aitboss wrote:
...
How can I iterate through the table and print the values?
...


Code:
local myTable = {
   [0xDEADBEEF] = "80 BF 58010000 00",
   [0xADABEEF0] = "F3 0F10 40 1C",
}

for key, value in pairs(myTable) do
   print("key: ", string.format("%016X", key), " : ", key)
   print("value: ", value)
   print("")
end

Quote:
key: 00000000ADABEEF0 : 2913726192
value: F3 0F10 40 1C

key: 00000000DEADBEEF : 3735928559
value: 80 BF 58010000 00


_________________
Back to top
View user's profile Send private message
Aylin
Master Cheater
Reputation: 7

Joined: 16 Feb 2017
Posts: 362

PostPosted: Tue Feb 12, 2019 7:42 pm    Post subject: Reply with quote

Define the change scenario above.
Leave the remaining job: checkbox control.
If scripts and codes are good; Enable and Disable will work correctly.

(or worst of all: It's me, I'm misunderstanding the question! Wink )

Code:
function CECheckbox1Change(sender)
if UDF1.CECheckbox1.Checked==true then
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, {01,00,00,00,00,00,00,00,01,00})

else

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

replace(aobs, {F4,20,E8,FA,78,C8,C8,F4,20,03})
--end
end

_________________
Hi Hitler Make a Youtube Web for Trainer
https://forum.cheatengine.org/viewtopic.php?t=609146
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 MSN Messenger
aitboss
Newbie cheater
Reputation: 0

Joined: 30 Sep 2017
Posts: 16

PostPosted: Wed Feb 13, 2019 2:19 pm    Post subject: Reply with quote

What I am trying to do is:

search for each AOB in the list and replace it with:
"01 00 00 00 00 00 00 00 01 00"

01,00,00,00,00,00,00,00,01,00 (in hexadecimal)
and storing the original value in a table for each address.

Then when, for example a key is pressed, I want to restore the original values to each address (in hexadecimal).

I am stuck at making the function that will loop and write the bytes back. Crying or Very sad
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater
Reputation: 26

Joined: 10 Apr 2015
Posts: 953

PostPosted: Wed Feb 13, 2019 7:20 pm    Post subject: Reply with quote

Quote:
How can I iterate through the table and print the values?


--- for AOB not in a table

Code:
function getByteString(address, bytecount)
  local bytes = readBytes(address, bytecount, true)
  if bytes then
    local result = ""
    for i = 1, #bytes do
      if #result > 0 then
        result = result .. " "
      end
      result = result .. string.format("%02X", bytes[i])
    end
    return result
  end
end


aobresult=AOBScan("F4 01 00 00 D0 07 00 00 F4 01")

j = 0
cnt = 1

if (aobresult~=nil) then
  print("Results found: "..aobresult.Count)
  while j < aobresult.Count do
    a = getByteString(aobresult[j], 12)
    print("Address "..cnt.." = "..aobresult[j].." --> AOB :  "..a)
     j=j+1
     cnt = cnt+1
  end
  aobresult.destroy()
  aobresult=nil
else
  print("No results found")
end

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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