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