Code:
Imports System.Runtime.InteropServices
Module ReadMemoryString
<DllImport("kernel32.dll", SetLastError:=True)> Private Function ReadProcessMemory _
(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByRef lpBuffer As Byte, _
ByVal iSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
End Function
Public Function ReadString(ByVal proces As String, ByVal address As Integer) As String
Try
Dim process0 As String = proces
Dim prox As Process() = Process.GetProcessesByName(process0)
Return GetTextinMemory(prox(0).Handle, address, 16) & GetTextinMemory(prox(0).Handle, address + 32, 16)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Private Function GetTextinMemory(ByVal ProcessHandle As IntPtr, ByVal MemoryAddress As IntPtr, ByVal CharsToRead As Integer, Optional ByVal IsUnicode As Boolean = True) As String
Dim ReturnValue As String = vbNullString
Dim StringBuffer() As Byte
If IsUnicode Then
ReDim StringBuffer(CharsToRead * 2 - 1)
Else
ReDim StringBuffer(CharsToRead - 1)
End If
Try
If ReadProcessMemory(ProcessHandle, MemoryAddress, StringBuffer(0), StringBuffer.Length, Nothing) Then
If IsUnicode Then
ReturnValue = System.Text.Encoding.ASCII.GetString(StringBuffer)
Else
ReturnValue = System.Text.Encoding.Default.GetString(StringBuffer)
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return ReturnValue
End Function
End Module