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 


Confused about readbytes and readstring

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

Joined: 27 Aug 2014
Posts: 36

PostPosted: Tue Feb 07, 2017 8:52 pm    Post subject: Confused about readbytes and readstring Reply with quote

I'm trying to get a string from 4 bytes which correspond to an address that i can find using AOBScan, but i can't figure out how to get Lua to read the string at that address.

Code:

-- mov cl,[eax+A676CF8] -- A676CF8 is the address that holds the string i want.

AOBtarget = AOBScan("?? ?? ?? ?? 88 4C 04 24 83 C0 01 84 C9 75 EF 8D 4C 24 24 51")
-- ?? ?? ?? ?? corresponds to A676CF8 in mov cl,[eax+A676CF8]

if AOBtarget ~= nil then

target2 = readBytes(AOBtarget[0], 4, true)
-- set target2 as the first 4 bytes found at the address of the AOBScan, which should turn it into the target address

--writeBytes(testaddress, target2)
-- writes F8 C6 A7 00 to the test address so i know that at least works

target3 = readString(target2, 16, false)
-- read the string at the target address

--print(tostring(target3)) -- returns nil

end


Clearly i'm doing something wrong with target3 because it is returning nil when it should be reading the string at the target address.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Tue Feb 07, 2017 8:58 pm    Post subject: Reply with quote

Sounds like you're trying to use it as a pointer.
Use readPointer() not readBytes()
Code:
target2 = readPointer(AOBtarget[0])
target3 = readString(target2, 16, false)
print(target3)
Back to top
View user's profile Send private message
beagle
Cheater
Reputation: 0

Joined: 27 Aug 2014
Posts: 36

PostPosted: Tue Feb 07, 2017 9:02 pm    Post subject: Reply with quote

works flawlessly!

thank you very much :)
Back to top
View user's profile Send private message
beagle
Cheater
Reputation: 0

Joined: 27 Aug 2014
Posts: 36

PostPosted: Sat Feb 11, 2017 10:23 pm    Post subject: Reply with quote

How do i readPointer with AutoAssemble?
I'm trying to get the integer values stored in test.exe+672338, from AoBScan.

test.exe+4d330 - 8B 15 3823A700 - mov edx,[test.exe+672338]

Here's what im trying:
Code:

1. aobscan to find test.exe+4d330

2.
test:
readmem(test.exe+4d330+2,4) // set the value of test to the address 00a72338

3.
mov ecx,[test] // move the value at the target address into ecx
mov [store],ecx //put the value in "store"

4. result
test = A72338
store = A72338 // it's supposed to be the value at address A72338


The problem is "store" just ends up with the address, not the value at the address. I feel like i am making a very simple mistake.

The same happens if i use readmem twice and then try and store it, like:
Code:

test:
readmem(test.exe+4d330+2,4)

test1:
readmem(test,4)

mov ecx,[test1]
mov [store],ecx


*Edit: Ah i got it, i knew i was missing something simple, this seems to work:
test:
readmem(test.exe+4d330+2,4)

test1:
mov ecx,[test]
mov eax,ecx
mov ecx,[eax]
mov [store],ecx
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 Feb 11, 2017 11:34 pm    Post subject: Reply with quote

Code:
aobscan(myvar,8B 15 ?? ?? ?? ?? {more bytes for uniqueness})
mov ecx,[myvar+2]
Back to top
View user's profile Send private message
beagle
Cheater
Reputation: 0

Joined: 27 Aug 2014
Posts: 36

PostPosted: Sun Feb 12, 2017 2:03 am    Post subject: Reply with quote

Zanzer wrote:
Code:
aobscan(myvar,8B 15 ?? ?? ?? ?? {more bytes for uniqueness})
mov ecx,[myvar+2]


Ah i got it after a while, thanks :) I ended up using readmem instead of [myvar+2] because it kept giving me an error. I'll have to go back and look at it some time.

To get it to work i had to make it:
1. aobscan(myvar,8B 15 ?? etc) -> Find Address(A)
2. mov ecx,[myvar+2] -> Value of Address(A) (which is address B) to ecx
3. mov eax, [ecx] -> Value of Address(B) to eax
4. mov [x],eax -> Value of Address(B) to x

i hate pointers 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