Solved

VB:readprocessmemory

Posted on 2004-09-11
5
306 Views
Last Modified: 2010-05-02
im trying to use readprocess memory to read a value in another process's memory
ive got it to work in visual c++ so i know the address is correct and im going about it the right way
anyway heres my code (uses 4 text boxes and a button)
when i use this the window is found and a handle is created but the value input to the buffer after readprocessmem is incorrect
and if i keep pressing the button the value changes, most of the time it is either 127 or 0, and will alternate after each press
---------------------------------

Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteString Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'Private Declare Function WriteValue Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub get_Click()
Dim bytvalue As Long
Dim phandle As Long
Dim res As Long

    res = FindWindow(vbNullString, "MyApp")
    Text2 = res
    If res = 0 Then
        MsgBox "Could not find window"
    End If
     
    GetWindowThreadProcessId res, pId
   
    Text3 = pId
   
    phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
   
    Text4 = phandle
   
    If (phandle = 0) Then
         GoTo die
    End If
   
    tmp = ReadProcessMemory(phandle, "532E8C", bytvalue, 1, 0&)
   
    Text1 = bytvalue
   
   
die:

End Sub
0
Comment
Question by:tsukasa
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 12037052
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 12559775
Points to AzraSound
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now