[HELP] Visual Basic.NET 05/08 - Read Memory

07/31/2009 18:54 IAmHawtness#16
Quote:
Originally Posted by Zeelia View Post
Thanks guys, finally receiving some help ^.^
And thanks for the code examples, ookamocka and IAmHawtness, this will really help me to proceed with my code.

I hope you can help me if i get some more errors. I really want to do this since there is no (known) application which uses VB.NET, which really is the easiest language (except English).

*EDIT* I have one question though, it may sound newbie.
To use memory addresses in VB I have to replace the initiating double-zeros with &H, right?
But what do I have to do if I have a memory address starting with only one zero?
Is the "rule" that you should replace initiating double zero's with &H or ANY beginning zero, no matter how many, with &H?
I'd really appreciate an answer on this one =)

Thanks!
//Zeelia
If you have an address, say 1B4AD589, then in VB you'd just put &H in fron of all of it: &H1B4AD589. Only reason you put &H in front is so VB knows that it's hexadecimal. It will remove the zeros infront of the hex number automatically, if there is anything to remove.
07/31/2009 18:59 _tao4229_#17
You don't need to call OpenProcess using the ID, .NET provides the native handle as 'variable_name'.Handle. From there you can directly call Read/WriteProcessMemory.
07/31/2009 19:23 Zeelia#18
@IAmHawtness yes I know, thank you. I was just stupid because I put the memory address in a string variable so that's why VB didn't do it automatically. When I removed the quotes, all the magic happened =)

@_tao4229_ Ohh you're right! Thanks :D
Since I'm using FindWindow, I get the handle directly. But how do you mean with "'variable_name'.Handle"?
Handle is not a property of an integer which the handle variable is.

And here's how I get the handle now, thanks to tao4229:
PHP Code:
            ProcessHandle FindWindow(vbNullString"[Conquer] Raiding Clans")
            
GetWindowThreadProcessId(ProcessHandleProcessID)
            
fReadProcessMemory(&H82B010
07/31/2009 20:43 IAmHawtness#19
Quote:
Originally Posted by Zeelia View Post
Okay so first I don't know how to find the player base address.But for the charname, I have the memory address which isn't static, and I'm having troubles finding the pointer and offset because nothing writes to the memory address while I'm logged in so I have to do a pointer scan which really takes long time... Maybe its here that the player base address comes in?
Code:
Public Const PlayerBaseAddrPtr As Long = &H691CA0

Public Const NamePtrOffset = &H10C
Public Const XCoordOffset = &H1B8
Public Const YCoordOffset = &H1BC
Public Const IDOffset = &H88
To find your char name you could do something like:

Code:
Dim BaseAddress as long
Dim NamePtrAddress as long
Dim Name(16) as byte

ReadProcessMemory ProcessHandle, PlayerBaseAddrPtr, BaseAddress, 8, 0 
ReadProcessMemory ProcessHandle, BaseAddress + NamePtrOffset, NamePtrAddress, 8, 0
ReadProcessMemory ProcessHandle, NamePtrAddress, Name(0), 16, 0

CharName.Text = StrConv(Name, vbUnicode)
That's if not .NET has some other string converting feature that I'm not aware of.
07/31/2009 21:29 Zeelia#20
Thank you! :D

In fact, since the return from the memory is in a byte, there is this function which I have been told to use:
System.Text.UnicodeEncoding.Unicode.GetString(Name )

But i guess they work the same =)

I'm gonna start up cheat engine to get the memory addresses and I'll test the example you posted above.
I'll edit this post in a few minutes...

*EDIT* Okay. I think I have some kind of error in my code... Maybe while I'm retrieving the window handle, I don't know :S.
All the memory addresses I try give me an error and the code you supplied also gives me errors.
I'm using Err.LastDllError and it returns error '6' which means that my variables have the wrong properties (I think).
I changed the declared function into:
PHP Code:
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As LongByVal lpBaseAddress As LongByRef lpBuffer As LongByVal nSize As IntegerByRef lpNumberOfBytesWritten As Integer) As Integer 
and now it returns null.
Any ideas??
07/31/2009 21:32 IAmHawtness#21
Quote:
Originally Posted by Zeelia View Post
Thank you! :D

In fact, since the return from the memory is in a byte, there is this function which I have been told to use:
System.Text.UnicodeEncoding.Unicode.GetString(Name )

But i guess they work the same =)

I'm gonna start up cheat engine to get the memory addresses and I'll test the example you posted above.
I'll edit this post in a few minutes...
Good luck ;)
07/31/2009 22:29 Zeelia#22
*bump*
okay edited my post
just bumping so you know that I've edited^^