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 


Trying to make a trainer but scanning using hex

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Radon-222
How do I cheat?
Reputation: 0

Joined: 15 Apr 2017
Posts: 1

PostPosted: Sat Apr 15, 2017 7:12 am    Post subject: Trying to make a trainer but scanning using hex Reply with quote

so i have been trying to make a lua trainer. i got to the point where i needed to search in the memory.
i found from the wiki that i could use a list of binaries to do the search with AOBscan. but that is not what i want. i want to search for a speciffic hex value and thereafter change it. is this possible? do i have to convert the hex code to a list of binaries somehow? is there a function to search with hex values?
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 26

Joined: 01 Oct 2008
Posts: 666

PostPosted: Sat Apr 15, 2017 6:40 pm    Post subject: Reply with quote

May be some helper function to convert a hex to some aob string, so that it can be search using AOBScan. eg.

Code:

function s2aob(s) -- s is an arbitrary byte string
  return s:gsub(".",function(c)
    return string.format(" %02X", c:byte())
  end):sub(2)
end

-- ntype = 2,4,8 for word, dword, qword, 'd' for double (8bytes), 'f' for float (4bytes)
function num2ByteString(n, ntype, isBigEndian)
  local packfmt = tonumber(tostring(ntype)) and 'i'..ntype or ntype or 'i4'
  packfmt = (isBigEndian and '>' or '<')..packfmt
  return string.pack(packfmt,n)
end

function str2Wide(s)
  return byteTableToString(wideStringToByteTable(s))
end


So to AOBScan a (hex, prefix with 0x) number, try
Code:

local aob = AOBScan ( s2aob(num2ByteString( 0x12345 )) ) -- 4byte dword
-->            AOBScan ( "45 23 01 00" )
local aob = AOBScan ( s2aob(num2ByteString( 0x12345 , 8)) ) -- 8byte qword
-->            AOBScan ( "45 23 01 00 00 00 00 00" )

To AOBScan a double, try
Code:

local aob = AOBScan ( s2aob(num2ByteString( 43.5, 'd', true )) ) -- big endian
-->            AOBScan ( "40 45 C0 00 00 00 00 00" )
local aob = AOBScan ( s2aob(num2ByteString( 43.5, 'd')) ) -- little endian
-->            AOBScan ( "00 00 00 00 00 C0 45 40" )


To scan for a string ,
Code:

local aob = AOBScan ( s2aob("Cheat") )  -- ascii string
-->            AOBScan ( "43 68 65 61 74" )
local aob = AOBScan ( s2aob(str2Wide("Cheat")) )  -- unicode string
-->            AOBScan ( "43 00 68 00 65 00 61 00 74 00" )


It can also combine/join multiple aob like a structure using table.concat,
Code:
 
local aob = AOBScan ( table.concat ( { s2aob(num2ByteString(5)), s2aob("Cheat")}, " ") ) 
-->            AOBScan ( "05 00 00 00 43 68 65 61 74" )





or using MemScan Class, it has many option that may map to the CE scan interface.

For both scan method, you may need to consider what to do if the scan is not unique, there may be risk on modifying false result.

_________________
- Retarded.
dropbox
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