1 Attachment(s)
how to write/Read game memory with vb 2008
this tut will show you how to read & write memory in any game
first go to vb 2008 add a module paste this into it
Code:
Module Memory
Public Const PROCESS_VM_READ = &H10
Public Const PROCESS_VM_WRITE = (&H20)
Public Const PROCESS_VM_OPERATION = (&H8)
Public Const PROCESS_QUERY_INFORMATION = (&H400)
Public Const PROCESS_READ_WRITE_QUERY = PROCESS_VM_READ + PROCESS_VM_WRITE + PROCESS_VM_OPERATION + PROCESS_QUERY_INFORMATION
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Int32, ByRef lpBuffer As Int32, ByVal nSize As Int32, ByVal lpNumberOfBytesWritten As Int32) As Long
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Int32, ByRef lpBuffer As Byte(), ByVal nSize As Int32, ByVal lpNumberOfBytesWritten As Int32) As Long
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Int32, ByVal lpBuffer() As Byte, ByVal nSize As Int32, ByVal lpNumberOfBytesWritten As Int32) As Long
Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As UInteger, ByVal bInheritHandle As Integer, ByVal dwProcessId As UInteger) As IntPtr
Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hHandle As IntPtr) As Boolean
Public Function Game_Hwnd() As Int32
Dim i As Int32 : Dim foundit As Boolean = False
For Each p As Process In Process.GetProcessesByName("Halo2") ' Replace that with the games window text
i = p.Id
foundit = True : Exit For
Next
If foundit = True Then
Return i
Else
MsgBox("Couldn't find Game")
Return 0
End If
End Function
#Region "Memory reading/Writing"
Public Sub WriteMemory(ByVal Address As Integer, ByVal Value As Integer, ByVal Size As Integer)
Try
Dim GameReadWrite As Integer
Dim PID As Integer = Game_Hwnd()
GameReadWrite = OpenProcess(PROCESS_READ_WRITE_QUERY, False, PID)
Dim bytArray() As Byte
bytArray = BitConverter.GetBytes(Value)
WriteProcessMemory(GameReadWrite, Address, bytArray, Size, 0)
CloseHandle(GameReadWrite)
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub WriteMemory(ByVal Address As Integer, ByVal Value() As Byte)
Try
Dim GameReadWrite As Integer
Dim PID As Integer = Game_Hwnd()
GameReadWrite = OpenProcess(PROCESS_READ_WRITE_QUERY, False, PID)
WriteProcessMemory(GameReadWrite, Address, Value, Value.Length, 0)
CloseHandle(GameReadWrite)
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub WriteMemory(ByVal Address As Integer, ByVal Value() As Byte, ByVal Offset As Integer, ByVal Length As Integer)
Try
Dim Count1 As Integer
For Count1 = 0 To Length - 1
WriteMemory(Address + Count1, Value(Count1 + Offset), 1)
Next
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub WriteMemory(ByVal Address As Integer, ByVal Value As String)
Try
Dim Length As Integer = Value.Length
For I As Integer = 0 To Length - 1
WriteMemory(Address + I, Asc(Value.Chars(I)), 1)
Next
WriteMemory(Address + Length, 0, 1)
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub WriteMemory(ByVal Address As Integer, ByVal Value As Double)
Try
Dim Buffer(0 To 7) As Byte
Buffer = BitConverter.GetBytes(Value)
For I As Integer = 0 To 7
WriteMemory(Address + I, CInt(Buffer(I)), 1)
Next
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
'Read Memory
Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As Double)
Try
Dim Buffer(7) As Byte
Dim Temp As Integer
For I As Integer = 0 To 7
ReadMemory(Address + I, Temp, 1)
Buffer(I) = CByte(Temp)
Next
Value = BitConverter.ToDouble(Buffer, 0)
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As Integer, ByVal Size As Integer)
Try
Dim mValue As Integer
Dim GameReadWrite As Integer
Dim PID As Integer = Game_Hwnd()
GameReadWrite = OpenProcess(PROCESS_READ_WRITE_QUERY, False, PID)
ReadProcessMemory(GameReadWrite, Address, mValue, Size, 0)
Value = mValue
CloseHandle(GameReadWrite)
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub ReadMemory(ByVal Address As Integer, ByRef Value() As Byte, ByVal Length As Integer)
Try
Dim bytArray() As Byte
Dim Count1 As Integer
Dim tempInteger As Integer
ReDim bytArray(Length - 1)
For Count1 = 0 To Length - 1
ReadMemory(Address + Count1, tempInteger, 1)
bytArray(Count1) = CByte(tempInteger)
Next
Value = bytArray
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As String)
Try
Dim intChar As Integer
Dim Count1 As Integer
Dim strTemp As String
strTemp = String.Empty
Count1 = 0
Do
ReadMemory(Address + Count1, intChar, 1)
If intChar <> 0 Then strTemp = strTemp & Chr(intChar)
Count1 += 1
Loop Until intChar = 0
Value = strTemp
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
Public Sub ReadMemory(ByVal Address As Integer, ByRef Value As String, ByVal Length As Integer)
Try
Dim intChar As Integer
Dim Count1 As Integer
Dim strTemp As String
strTemp = String.Empty
For Count1 = 0 To Length - 1
ReadMemory(Address + Count1, intChar, 1)
strTemp = strTemp & Chr(intChar)
Next
Value = strTemp
Catch Ex As Exception
'ShowError(Ex)
End Try
End Sub
#End Region
Function ReadInt(ByVal Address As Int32)
Dim i As Int32
ReadMemory(Address, i, 4)
Return i
End Function
Sub WriteInt(ByVal Address As Int32, ByVal Value As Int32)
WriteMemory(Address, Value, 4) ' We'll write a 4 bit to the address
End Sub
End Module
then go to your form add a button to read the address name it "read" and add a label then double click the read button you just made and paste this code
Code:
'if your address you got from Cheat Engine or anything else has
gamename+address then use this
Label1.Text = ReadInt((BaseAddress + put address here))
'if it doesn't have the + then use this
Label1.Text = ReadInt((put address here))
now add a button to write to the address
then paste this
Code:
'again if the address had + then use this
WriteInt((BaseAddress + 5350952), value you want to set it to)
if it didnt have + then use this
WriteInt((5350952), value you want to set it to)
now paste this code in your form load event
Code:
Dim MyProcess As Process() = Process.GetProcessesByName("halo2") ' Replace that with the games window text
Dim mainModule As ProcessModule
mainModule = MyProcess(0).MainModule
BaseAddress = CInt(mainModule.BaseAddress)
BaseAddress = CInt(mainModule.BaseAddress)
add this code right under where it says
Public Class form1
Code:
Dim BaseAddress As Integer
Dim MyProcess As Process() = Process.GetProcessesByName("halo2") ' Replace that with the games window text
and your done! if you have any other questions add me on Xfire or msn
Xfire-codehpro
msn-ipivb@live.com
you can download the source files at the bottom of this post
here are some pic;s of what it should look like when your done
https://img251.imageshack.us/img251/9541/70826344.jpg
https://img251.imageshack.us/img251/2507/55644619.jpg
https://img251.imageshack.us/img251/8242/80891939.jpg