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 


Memory Scanner

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Jul 05, 2008 5:04 am    Post subject: Memory Scanner Reply with quote

I have coded a memory scanner in the form of an injectable DLL but have a question or two on making it more efficient and more functionable:

1) Is it faster to read and compare dwords (assuming they are at 4 byte alignments) or is it faster to read and compare bytes ?

eg. which one would be faster:

Code:
mov al, byte ptr ds:[1234ABCD]
cmp al, bl
je label1
mov al, byte ptr ds:[1234ABCE]
cmp al, bl
je label2
mov al, byte ptr ds:[1234ABCF]
cmp al, bl
je label3
mov al, byte ptr ds:[1234ABD0]
cmp al, b
je label4l


Or:
Code:
mov eax, dword ptr ds:[1234ABCD]
cmp eax, ebx
je label


2) What is the "best" way of testing whether memory is readable (at the moment I am depending on the user to give suitable memory regions):
- SEH
- IsBadReadPtr
- VirtualQuery << I'm heading towards this one
- Reading from section headers << I expect this option would take more work than any of the others
- Other ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25840
Location: The netherlands

PostPosted: Sat Jul 05, 2008 10:21 am    Post subject: Reply with quote

1: Comparing dwords is faster, if you're looking for a dword. If you're looking for a single byte, use byte.
As a rule of thumb, always pick the biggest possible type, the less instructions, the better

also, since the 0x386 architecture, you can do:
Code:

cmp byte ptr ds:[1234ABCD],bl


2: VirtualQuery to map the memory regions beforehand, followed by SEH when reading. (e.g another thread might have deallocated the page while you where till reading it)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jul 06, 2008 11:01 am    Post subject: Reply with quote

First correction is just me being stupid haha Embarassed

I will try to use the method you describe in terms of getting allocated memory regions, thanks Wink

//edit :

I would now love some advice about storing "matches" for some sort of "next scan function".

I initially thought of having an array but I realised this is actually impossible considering that array is in the memory space of the memory you are potentially scanning so you can never match the size of the entire memory space (potentially 0x7FFFFFFF).

So instead of an array in terms of boolean bytes, I thought why not boolean nibbles. eg. first nibble would correspond to like 0x00000000 and next nibble would correspond to 0x00000001.

Then I thought, why not take this even further and to the extreme and use "boolean bits" ? I could store the "state" (in terms of match/non-match) of 8 virtual addresses in each byte of my array.

However, bit manipulation does not seem to be best option. I would potentially still have a lot of addresses to read but this would be still faster than my last option..

My last option I could think of was to write to disk. Disk access is unarguably slower than memory access but this would leave me no problems with bulking up a load of memory. However if I were to use this method, I would need to investigate a bit more on what sort of APIs to use, etc.

Another noob idea I had was to write out all matches to a console then re-read it. Probably slow, but not memory consuming.

Does anyone have any advice on what to do ? I don't care about how easy/hard it may be, that is NP. I have all the time and patience in the world. I would love to know the most EFFICIENT method. Or maybe there is another better method I have not mentioned. I am not overly satisfied with any of the ideas I came up with.
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 programming 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