SolvedRead Integer From Selected Memory Address

Posts 14 of 4 · Page 1 of 1
Read Integer From Selected Memory Address
Hi to all,

I am noob to vb programing.
First of all i read post (about 20 times) which you discouss abot this topic.
POST

First of all sorry for my english is not my native language.

What i need?

See picture 1 below.

How i imagine to programs looks at outside?

See picture 2 below.

Ok. I know how to do basic thinks in vb, but i do not know how to write code to read from memory.
I will be really happy if anyone can help me, step by step.

Thank you all!
add after Public Class Form1:

Code:
<DllImport("kernel32.dll")> _
   Private Declare Function ReadProcessMemory Lib "kernel32" ( _
ByVal hProcess As Integer, _
ByVal lpBaseAddress As Integer, _
ByRef lpBuffer As Long, _
ByVal nSize As Integer, _
ByRef lpNumberOfBytesWritten As Integer _
) As Integer

then use this function to read from the address

Code:
Public Sub readaddress()
        Dim ReadAddress As Integer
        Dim AddressValue As Integer        
        ReadAddress = &H1CD8ECC&
        
        ReadProcessMemory(p(0).Handle.ToInt32, ReadAddress, AddressValue, 4, 0)
    End Sub
That's for 1 specific address, you can globalise the read function easily though so you can do readaddress(address) but declare the address globally and not inside the function
Code:
  Private Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
    Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer
   Private Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
 


   Public Function ReadLong(ByVal ProcessN As String, ByVal Address As Integer, ByVal ByteL As Byte) As Long
        Dim value As Long
        Dim proc As Process = Process.GetProcessesByName(ProcessN)(0)
        Dim winhandle As IntPtr = OpenProcess(&H1F0FFF, True, proc.Id)

        If ReadProcessMemory(winhandle, Address, value, ByteL, 0) = 0 Then Return -1
        CloseHandle(winhandle)

        Return value
    End Function
Works on x64 bit Win 7.
Quote Originally Posted by Blubb1337 View Post
Code:
  Private Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
    Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer
   Private Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
 


   Public Function ReadLong(ByVal ProcessN As String, ByVal Address As Integer, ByVal ByteL As Byte) As Long
        Dim value As Long
        Dim proc As Process = Process.GetProcessesByName(ProcessN)(0)
        Dim winhandle As IntPtr = OpenProcess(&H1F0FFF, True, proc.Id)

        If ReadProcessMemory(winhandle, Address, value, ByteL, 0) = 0 Then Return -1
        CloseHandle(winhandle)

        Return value
    End Function
Works on x64 bit Win 7.
That's if you build the application as 32-bit.
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Need help?