Hello MPGH. I was writing module for VB.Net cause kyos tut interested me. However in kyo tut it was pretty strange lol. And there were a lot of problems with it. So i wrote a module, becouse copying and pasting code between subs and buttons sux, doesnt it? Now u will be able to change memory in 1 line of text (for pointers u'll need more :P). Pointers same as for VB6, read then add the offset and voila.
However reading isnt the same, here i got public variables storing read values. It is better becouse u dont need to declare variable every time u wanna read from some address. So reading will look like this (for byte, 2bytes, 4bytes, 8bytes):
Code:
ReadMemory(“someapp”, &Haddress)
Textbox1.Text = vBuffer
and for float:
Code:
ReadFloat(“someapp”, &Haddress)
Textbox1.Text = vBufferS
but before u can put ur greedy fingers on my module u need to figure out some parts of it. They were replaced with xxxxxx. Without figuring it out module won't work. Don't worry, errors displayed by VB will help you
And here comes the module:
Code:
Option Explicit On
Imports System
Imports System.diagnostics
Module ReadWriteMem
Public vBuffer As Long 'public variable storing read values for Byte, 2 Bytes 4 Bytes and 8 Bytes
Public vBufferS As Single 'public variable to store read floating point values
'stuff
Public Declare Function KeyPressed Lib "user32" Alias "GetAsyncKeyState" (ByVal Key As Integer) As Integer
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'reading
Private Declare Function ReadMem Lib "kernel32" Alias "xxxxxx" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByRef buffer As Long, ByVal size As Int32, ByRef lpNumberOfBytesRead As Int32) As Boolean
Private Declare Function ReadFloat Lib "kernel32" Alias "xxxxxx” (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByRef buffer As Single, ByVal size As Int32, ByRef lpNumberOfBytesRead As Int32) As Boolean
'writing
Private Declare Function WriteMem Lib "kernel32" Alias "xxxxxx" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal buffer() As Long, ByVal size As Int32, ByRef lpNumberOfBytesRead As Int32) As Boolean
Private Declare Function WriteFloat Lib "kernel32" Alias "xxxxxx " (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal buffer() As Single, ByVal size As Int32, ByRef lpNumberOfBytesRead As Int32) As Boolean
Private appProcess As Process
Private Function SetProcess(ByVal ProcessName As String) As Boolean
Dim processes As Process() = Process.GetProcessesByName(ProcessName)
If (processes.Length > 0) Then
appProcess = processes(0)
Return True
Else
Return False
End If
End Function
Public Function WriteMemory(ByVal appName As String, ByVal address As Integer, ByVal value As Object, ByVal bytes As Integer)
If SetProcess((xxxxxx)) = False Then
MsgBox(xxxxxx & " not found.", MsgBoxStyle.Critical, "Error")
End
Exit Function
End If
Dim buffer() As Long = New Long(0) {value}
Return WriteMem(xxxxxxx.Handle, address, buffer, bytes, Nothing)
CloseHandle(xxxxxxx.Handle)
End Function
Public Function ReadMemory(ByVal appName As String, ByVal address As Integer, ByVal bytes As Integer)
If SetProcess((xxxxxxx)) = False Then
MsgBox(xxxxxxx & " not found.", MsgBoxStyle.Critical, "Error")
End
Exit Function
End If
ReadMem(xxxxxxx.Handle, address, vBuffor, bytes, Nothing)
Return vBuffer
CloseHandle(xxxxxxx.Handle)
End Function
Public Function WriteFloat(ByVal appName As String, ByVal address As Integer, ByVal value As Single)
If SetProcess((xxxxxx)) = False Then
MsgBox(xxxxxx & " not found.", MsgBoxStyle.Critical, "Error")
End
Exit Function
End If
Dim buffer() As Single = New Single() {value}
Return WriteFloat(xxxxxxx.Handle, address, buffer, 142, Nothing)
CloseHandle(xxxxxxx.Handle)
End Function
Public Function ReadFloat(ByVal appName As String, ByVal address As Integer)
If SetProcess((xxxxxx)) = False Then
MsgBox(xxxxxx & " not found.", MsgBoxStyle.Critical, "Error")
End
Exit Function
End If
ReadMem(xxxxxxx.Handle, address, vBufferS, 834, Nothing)
Return vBufferS
CloseHandle(xxxxxxx.Handle)
End Function
End Module
There are no comments since a few days ago my comp crashed and i lost whole module. When rewritting i didnt want to bother rewriting them.
btw except for xxxxxx-ed parts there are 2 code traps. :P But while reading u should notice them since they are kinda obvious (if u understand the code)