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 


ReadProcessMemory returning wrong value! [VB6]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Zinglish
How do I cheat?
Reputation: 0

Joined: 06 Jul 2010
Posts: 6

PostPosted: Thu Jul 08, 2010 4:19 am    Post subject: ReadProcessMemory returning wrong value! [VB6] Reply with quote

Hey guys, I am making my first trainer in VB6 (Old as, i know!).

I have this in my form:
Code:

Private Sub cmdTest_Click()
    Dim hwnd As Long 'Window's handle
    Dim pid 'Process ID
    Dim pHandle 'Process Handle
    Dim Buff As Long
   
    Buff = 1
   
    hwnd = FindWindow(vbNullString, "Solitaire")
   
    GetWindowThreadProcessId hwnd, pid
   
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
   
    ReadProcessMemory pHandle, &H585F9C8, Buff, 4, 0&
    Text1.Text = CLng(Buff)
   
    CloseHandle pHandle
End Sub


And this in a Module:

Code:
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function WriteProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
Public Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long

Public Const PROCESS_ALL_ACCESS As Long = &HFFF



It refuses to give me a real value! In fact every address I try gives me the same value, talk about epic failure on the first god damn try: FAIL
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Thu Jul 08, 2010 10:44 am    Post subject: Reply with quote

I don't know VB6, but I'd guess wrong byte order. DWORD 0x12345678 is written as 0x78 0x56 0x34 0x12 in the memory. If you want to read more, here's the keyword: endianness
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Jul 08, 2010 6:48 pm    Post subject: Reply with quote

Set breakpoints and walk through the code as it's running. Also add error checking to see if something is failing.

Also make sure you are reading the correct size for the address you wish to obtain the value of. 4 will not be the size you use for everything.

@Jani: VB6 will read back values in the correct format. (Assuming he's looking for a basic value and not bytes of a function etc.)

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Jul 08, 2010 8:10 pm    Post subject: Reply with quote

Seriously consider switching to something like C#

You'll probably find that it makes your life a lot easier.
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