Results 1 to 4 of 4
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,222
    Thanks Thanks Given 
    211
    Thanks Thanks Received 
    2,230
    Thanked in
    292 Posts
    Rep Power
    10

    Simple VB Write/Read Memory Class

    Contains:
    • WriteProcessMemory
    • ReadProcessMemory
    • GetWindowThreadProcessId
    • FindWindow
    • CloseHandle


    [syntax]Public Class Class1
    Private Declare Function ReadProcessMemory Lib "KERNEL32" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Long, ByVal Size As Integer, ByVal BytesWritten As Integer) As Long
    Private Declare Function WriteProcessMemory Lib "KERNEL32" (ByVal Handle As Integer, ByVal Address As Integer, ByRef Value As Long, ByVal Size As Integer, ByVal BytesWritten As Integer) As Long
    'test
    Private process_id As Int32 = 0
    'Private Const ACCESS_RIGHTS_ALL = &H1F0FF
    Private Const ACCESS_RIGHTS_ALL = &H1014099D
    Private Declare Function OpenProcess Lib "KERNEL32" (ByVal dbDesiredAccess As Int32, ByVal bInheritHandle As Int32, ByVal dwProcessId As Int32) As Int32
    Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Int32) As Int32
    Private Declare Function WPM Lib "KERNEL32" Alias "WriteProcessMemory" (ByVal hProcess As Int32, ByVal ipBaseAddress As Int32, ByVal ipBuffer As Byte, ByRef nSize As Int32, ByRef ipNumberOfBytesWritten As Int32) As Byte
    Private Declare Function WPM Lib "KERNEL32" Alias "WriteProcessMemory" (ByVal hProcess As Int32, ByVal ipBaseAddress As Int32, ByVal ipBuffer As Int32, ByRef nSize As Int32, ByRef ipNumberOfBytesWritten As Int32) As Int32
    Private Declare Function WPM Lib "KERNEL32" Alias "WriteProcessMemory" (ByVal hProcess As Int32, ByVal ipBaseAddress As Int32, ByVal ipBuffer As Int64, ByRef nSize As Int32, ByRef ipNumberOfBytesWritten As Int32) As Int64
    'Read
    Private Declare Function RPM Lib "KERNEL32" Alias "ReadProcessMemory" (ByVal hProcess As Int32, ByVal ipBaseAddress As Int32, ByVal ipBuffer As Byte, ByRef nSize As Int32, ByRef ipNumberOfBytesWritten As Int32) As Byte
    Private Declare Function RPM Lib "KERNEL32" Alias "ReadProcessMemory" (ByVal hProcess As Int32, ByVal ipBaseAddress As Int32, ByVal ipBuffer As Int32, ByRef nSize As Int32, ByRef ipNumberOfBytesWritten As Int32) As Int32
    Private Declare Function RPM Lib "KERNEL32" Alias "ReadProcessMemory" (ByVal hProcess As Int32, ByVal ipBaseAddress As Int32, ByVal ipBuffer As Int64, ByRef nSize As Int32, ByRef ipNumberOfBytesWritten As Int32) As Int64
    Public Sub WriteMemmoryInteger(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Integer)
    Dim Open = Process.GetProcessesByName(ProcessName)
    If Open.Length = 0 Then
    Exit Sub
    End If
    WriteProcessMemory(Open(0).Handle, Address, Value, 4, 0)
    End Sub
    Public Sub WriteMemoryASM(ByVal ProcessName As String, ByVal Address As Integer, ByVal array As Byte())
    Dim Open = Process.GetProcessesByName(ProcessName)
    If Open.Length = 0 Then
    Exit Sub
    End If
    For Value As Byte = LBound(array) To UBound(array)
    WriteProcessMemory(Open(0).Handle, Address + Value, array(Value), 1, 0)
    Next
    End Sub
    'TEST
    Public Function GetProcessId()
    Dim Processes() As Process = Process.GetProcesses
    Dim process_name As String
    Dim i As Byte

    For i = LBound(Processes) To UBound(Processes)
    process_name = Processes(i).ProcessName
    If process_name = "Swat4" Then
    process_id = Processes(i).Id
    Return process_id
    End If
    Next
    End Function
    #Region "Writes"
    Public Sub Write_Byte(ByVal address As Int32, ByVal value As Byte)
    Dim process_handle As Int32
    process_handle = OpenProcess(ACCESS_RIGHTS_ALL, False, process_id)
    If process_handle <> 0 Then
    WPM(process_handle, address, value, 1, 0)
    End If
    CloseHandle(process_handle)
    End Sub
    Public Sub Write_Integer(ByVal address As Int32, ByVal value As Int32)
    Dim process_handle As Int32
    process_handle = OpenProcess(ACCESS_RIGHTS_ALL, False, process_id)
    If process_handle <> 0 Then
    WPM(process_handle, address, value, 4, 0)
    End If
    CloseHandle(process_handle)
    End Sub
    Public Sub Write_Long(ByVal address As Int32, ByVal value As Int64)
    Dim process_handle As Int32
    process_handle = OpenProcess(ACCESS_RIGHTS_ALL, False, process_id)
    If process_handle <> 0 Then
    WPM(process_handle, address, value, 8, 0)
    End If
    CloseHandle(process_handle)
    End Sub
    #End Region
    #Region "Reads"
    Public Function Read_Byte(ByVal address As Int32)
    Dim process_handle As Int32, value As Byte
    process_handle = OpenProcess(ACCESS_RIGHTS_ALL, False, process_id)
    If process_handle <> 0 Then
    RPM(process_handle, address, value, 1, 0)
    End If
    CloseHandle(process_handle)
    Return value
    End Function
    Public Function Read_Integer(ByVal address As Int32)
    Dim process_handle As Int32, value As Int32
    process_handle = OpenProcess(ACCESS_RIGHTS_ALL, False, process_id)
    If process_handle <> 0 Then
    RPM(process_handle, address, value, 4, 0)
    End If
    CloseHandle(process_handle)
    Return value
    End Function
    Public Function Read_Long(ByVal address As Int32)
    Dim process_handle As Int32, value As Int64
    process_handle = OpenProcess(ACCESS_RIGHTS_ALL, False, process_id)
    If process_handle <> 0 Then
    RPM(process_handle, address, value, 8, 0)
    End If
    CloseHandle(process_handle)
    Return value
    End Function

    Public Sub autopatcher(ByVal address As Int32, ByVal value As Byte())
    Dim i As Byte
    For i = LBound(value) To UBound(value)
    Write_Byte(address + i, value(i))
    Next
    End Sub
    #End Region


    Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, ByVal lpdwProcessId As Long) As Long
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Function LAB(ByVal address As Long, ByVal value As Long)
    Dim handle As Long, processID As Long, ProcessHandle As Long
    handle = FindWindow(vbNullString, "hl2")
    GetWindowThreadProcessId(handle, processID)
    ProcessHandle = OpenProcess(&H1F0FFF, True, processID)
    WriteProcessMemory(ProcessHandle, address, value, 1, 0)
    CloseHandle(ProcessHandle)
    End Function
    End Class[/syntax]
    Author: DragonHunter
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

  2. #2
    MrSmith
    MrSmith is offline
    Member-in-training
    Join Date
    2010 Aug
    Posts
    85
    Thanks Thanks Given 
    9
    Thanks Thanks Received 
    7
    Thanked in
    4 Posts
    Rep Power
    0

    Re: Simple VB Write/Read Memory Class

    Just a note to this. The WriteProcessMemory function here is for single byte only. If you wish to change it for other datatype value here is how;

    Code:
    WriteProcessMemory(ProcessHandle, Address, Value (this is the buffer), Byte Size, 0&)
    Change Byte Size to either

    1 - single byte (Declare ByVal value As Byte)
    2 - 2 bytes (Declare ByVal value as Long)
    4 - 4 bytes (Declare ByVal value as Long)

    If you are searching for float value, Declare ByVal value as Single.

    Regards, MrSmith
    Ever Danced With The Devil By The Pale Moonlight ?

  3. #3
    P.o.X
    P.o.X is offline
    Member-in-training P.o.X's Avatar
    Join Date
    2012 May
    Posts
    64
    Thanks Thanks Given 
    11
    Thanks Thanks Received 
    11
    Thanked in
    7 Posts
    Rep Power
    0
    i need help i`m noob right now never did this before if someone can help me,i have som static adresses for a game and i want to creata a form application in vb for reading the adresses and show in label ,please add skype :babinetfilip,if u have msn please just replay i`ll add you ty =)

  4. #4
    emoisback
    emoisback is offline
    Full member
    Join Date
    2011 Dec
    Location
    Indonesia there i'm
    Posts
    508
    Thanks Thanks Given 
    83
    Thanks Thanks Received 
    244
    Thanked in
    68 Posts
    Rep Power
    13
    Quote Originally Posted by P.o.X View Post
    i need help i`m noob right now never did this before if someone can help me,i have som static adresses for a game and i want to creata a form application in vb for reading the adresses and show in label ,please add skype :babinetfilip,if u have msn please just replay i`ll add you ty =)
    Create Form then use this ReadProcessMemory function from Kernel32 (or take dwar's vb write/read memory class)
    then use ReadProcessMemory to read bytes, and then covert byte to data type u want..
    Learn from PGC for Share on PGC..


    For another Stuff i have make try to find it [Please, register to view links]
    If i have help you, please thanks and respect ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •