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 


Maintain AOB replace have same length with AOB scan

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Dec 16, 2016 9:05 pm    Post subject: Maintain AOB replace have same length with AOB scan Reply with quote

Hi guys,

Code:
search='46 ?? ?? ?? 11 13 00 00 60 ?? ?? 2c ?? ?? 4f ?? ?? ?? 24 01 5e ?? ?? 2b 61 ?? ?? 5d ?? ??'
change='46 ?? ?? ?? 11 00 00 00 60 ?? ?? 2c ?? ?? 29 29 02 02 24 14 5e ?? ?? 2b 61 ?? ?? 5d ?? ??'
aobs = search

function DEC_HEX(IN)
   local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
    if IN<1 then
      OUT=0
      return OUT
   end
   while IN>0 do
      I=I+1
      IN,D=math.floor(IN/B),math.fmod(IN,B)+1
      OUT=string.sub(K,D,D)..OUT
   end
   return OUT
end

if(aobs == nil) then
showMessage("No AOB to check")
else
 for i = 1, string.len(change), 3 do
 z = string.sub(change, i, i+2)
 x, y = string.find(z, "%?+")
 if (x == nil) then
   script=[[
              ]].."+"..(DEC_HEX((i-1)/3))..[[:
       db ]]..z..[[
       ]]
  autoAssemble(script)
  print(script)
 end
 end
 object_destroy(aobs);
 aobs=nil
end

--- result
              +0:
       db 46        
              +4:
       db 11        
              +5:
       db 00        
              +6:
       db 00        
              +7:
       db 00        
              +8:
       db 60        
              +B:
       db 2c        
              +E:
       db 29        
              +F:
       db 29        
              +10:
       db 02        
              +11:
       db 02        
              +12:
       db 24        
              +13:
       db 14        
              +14:
       db 5e        
              +17:
       db 2b        
              +18:
       db 61        
              +1B:
       db 5d    

-- seem like '46 ?? ?? ?? 11 13 00 00 60 ?? ?? 2c ?? ?? 4f ?? ?? ?? 24 01 5e ?? ?? 2b 61 ?? ?? 5d ?? ??'
has replaced with '46 ?? ?? ?? 11 00 00 00 60 ?? ?? 2c ?? ?? 29 29 02 02 24 14 5e ?? ?? 2b 61 ?? ?? 5d ?? ??'

-- Now if :
search = 'd0 30 28 d6 20 63 06 '
change = '26 48 '
-- with same function above, give result
              +0:
       db 26        
              +1:
       db 48       



from 2nd result, how to maintain given result print as '26 48 28 d6 20 63 06' ?. Meant AOB's not replaced also including when print it and also checking both AOB have same length.

Thanks
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Dec 16, 2016 9:45 pm    Post subject: Reply with quote

Insert trailing wildcard to make it fit?
Code:

search = 'd0 30 28 d6 20 63 06 '
change = '26 48 ?? ?? ?? ?? ??'


Since ce 6.5 (or ce 6.4?) support wildcard in db lines, so may be simply:
Code:

local aob = AOBScan(search)
if aob then
  for i=0,aob.Count-1 do
    autoAssemble(aob[i]..':\ndb '..change)
  end
  aob.Destroy()
end

unless your code is testing other thing.

bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Dec 16, 2016 10:41 pm    Post subject: Reply with quote

Are you trying to do this? http://forum.cheatengine.org/viewtopic.php?p=5620925

Code:
local replace = "26 ?? 48"
local count = 0
local script = ""
for byte in replace:gmatch("%S+") do
  if byte ~= "??" then
    script = script .. string.format("+%X:\r\ndd %s\r\n", count, byte)
  end
  count = count + 1
end
print(script)
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Dec 16, 2016 11:52 pm    Post subject: Reply with quote

Thanks both Panraven and Zanzer

@Panraven : Yes it's better to use wildcard "??" put as not replacing AOB and maintain same AOB length both scan and replace

@Zanzer

Code:
$lua}
if syntaxcheck then return end
cheat_name = "MyCheat"
[ENABLE]
..
..
[DISABLE]


Where put the script ?. In Cheat Engine Table or AA ?. I am not understand with this "{$lua} and "[ENABLE] [DISABLE]" statement.


Code:
// eq.
scan="27 D0 30 66 C1 2C"

local replace = "26 ?? 48"
local count = 0
local script = ""
for byte in replace:gmatch("%S+") do
  if byte ~= "??" then
    script = script .. string.format("+%X:\r\ndb %s\r\n", count, byte)
  end
  count = count + 1
end
print(script)

// result
+0:
db 26
+2:
db 48


how to print script (result) with format "26 ?? 48 ?? ?? ??" ?. I mean ignoring aob count / bytes position and "db" to be print, something like concatenate replace aob with add wildcard "??" for the rest aob not replaced.

Thank you and regards
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Sat Dec 17, 2016 12:44 am    Post subject: Reply with quote

Padding wildcard to aob to a length if shorter?

Code:

function cntAobBytes(aob)
  local cnt = 0
  for _ in aob:gmatch"%S%S?" do cnt=cnt+1 end
  return cnt
end
function padAob(aob,n)
  n = type(n)=='string' and cntAobBytes(n) or n
  return aob..string.rep(" ??",n-cntAobBytes(aob))
end

print(padAob("26 ?? 48",6))
print(padAob("26 ?? 48","27 D0 30 66 C1 2C"))
print(padAob(" 1  ?  3",6))

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Dec 17, 2016 1:24 am    Post subject: Reply with quote

Nah,...thank so much Panraven
This is I am looking for.

Code:
function cntAobBytes(aob)
  local cnt = 0
  for _ in aob:gmatch"%S%S?" do cnt=cnt+1 end
  return cnt
end
function padAob(aob,n)
  n = type(n)=='string' and cntAobBytes(n) or n
  return aob..string.rep(" ??",n-cntAobBytes(aob))
end

print(padAob("26 ?? 48",6))
print(padAob("26 ?? 48","27 D0 30 66 C1 2C"))
print(padAob(" 1  ?  3",6))

26 ?? 48 ?? ?? ??
26 ?? 48 ?? ?? ??
 1  ?  3 ?? ?? ??


So, n mean is AOB length.

Thanks and regard
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 Dec 17, 2016 7:32 am    Post subject: Reply with quote

Yes, my Lua in the other post is added as an AA script.
The {$lua} tells CE to interpret the code as Lua instead of assembly.
So it will execute the Lua when the user enables the script.
Performing the replace when its enabled and undoing it when disabled.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Dec 17, 2016 8:32 am    Post subject: Reply with quote

Understood and thanks for helped

Regards
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