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 


Calculate address from [$process+offset]... (Solved)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions
View previous topic :: View next topic  
Author Message
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 194

PostPosted: Wed Jul 29, 2020 12:01 pm    Post subject: Calculate address from [$process+offset]... (Solved) Reply with quote

I regularly collect certain mem_addresses "embedded" within the opcode; and wrote a lua script (see below) for that. My 'latest' version worked fine untill I came accross this code:
[code]
"MadMax.exe"+1E37E6D: 48 8B 05 5C 69 9C FF - mov rax,[MadMax.exe+17FE7D0]
"MadMax.exe"+1E37E74: 8B 88 3C 0A 00 00 - mov ecx,[rax+00000A3C][/code]

I get that address by running {getStaticAddr("8B 88 3C 0A 00 00",4,"pChallenge")}. Basically, the fn calculates/collects the address shown in {[MadMax.exe+17FE7D0]}...

After some recalcs, I found out I had to add an additional check {== "FF"} to get that part working.
It works fine now, but my question is more generic: what is the proper way to get this working overall?
(btw: game is x64; no issues - sofar - with x32 games)

[code]
function getStaticAddr(sAOB,nOffset,sBaseAddr,nEval)
nEval = nEval or 0
--local scan1 = AOBScan(sAOB,"+X-C-W")
local scan = createMemScan(false)
scan.setOnlyOneResult(true)
scan.firstScan(soExactValue,vtByteArray,rtRounded,sAOB,nil,0,0xffffffffffffffff,"*W+X-C",
fsmNotAligned,nil,true,false,false,false)
scan.waitTillDone()
scan.getOnlyResult()
--print(sAOB)
local addrStruct = scan.Result
--print(string.format('- %X -',scan.Result))
if (nEval == 0) then
local offsVal = scan.Result - nOffset
--print(string.format('- %X -',offsVal))
-- ... as per suggested solution below
offsVal = string.format('%X',readInteger(offsVal,true))
--offsVal = string.format('%X',readInteger(offsVal))
--print(offsVal)
-- need to verify/confirm this check...
--if (string.sub(offsVal,1,2) == "FF") then offsVal = "FFFFFFFF" .. offsVal end
addrStruct = scan.Result + tonumber(offsVal,16) - nOffset + 4
addrStruct = readQword(addrStruct)
--print(string.format('[%X]',addrStruct))
end

scan.destroy()

local addrFound = getAddress(sBaseAddr)
writeQword(addrFound,addrStruct)
--print(string.format('* %X *',addrStruct))
end
[/code]

ps: I also use this fn now to get the 'actual' AOB address, rather then using an aobscan (in combo with registerSymbol). Result is the same, but it saves on code.
ps2: if you like this code, feel free to use/alter it any way you want. No permission needed. If you improve it, I obviously like to know about it... Cool
ps3: I tend/try to use the opcode directly following the mem_address I want, as I then have the "base" address and only need to add the offset value (hence: (+)4 means 4 bytes back). Eventually came across code where this was not possible - non-AOB convenient sort of speak - and introduced a "forwarding" rule as well (in which case I need to use negative values)...
ps4: Mad max is a bit of an oddball in that I need to set '*W' to also get opcode scanned properly...


Last edited by paul44 on Thu Jul 30, 2020 12:19 am; edited 1 time in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4657

PostPosted: Wed Jul 29, 2020 1:48 pm    Post subject: Reply with quote

RIP relative addressing uses signed offsets. Use "readInteger(offsVal, true)" to read a signed value (and get rid of that 'FF' stuff)
_________________
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
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 194

PostPosted: Thu Jul 30, 2020 12:16 am    Post subject: and so it goes... Reply with quote

yep, tested and working (even after reboot Smile)

2 remarks/fyi:
a) the 2nd param is not mentioned in the wiki nor in celua.txt
b) I assume that this param also applies to some of the other readXXX instructions; and perhaps writeXXX... if that even makes sense. anyways: I know now it is there, and surely use it again in time...

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

Joined: 06 Jul 2014
Posts: 4657

PostPosted: Thu Jul 30, 2020 1:51 pm    Post subject: Reply with quote

paul44 wrote:
a) the 2nd param is not mentioned in the wiki nor in celua.txt
It kind of does:
celua.txt wrote:
readSmallInteger, readInteger, readSmallIntegerLocal, readIntegerLocal
can also have second boolean parameter. If true, value will be signed.


paul44 wrote:
b) I assume that this param also applies to some of the other readXXX instructions; and perhaps writeXXX... if that even makes sense.
There are no unsigned floats/doubles, and it doesn't make sense for strings or AoBs. (you'll have to do it yourself for one-byte values)
writeInteger functions don't make sense to have a signed or unsigned variant: both signed and unsigned integers are stored the same way.

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Discussions 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