Also habe ich diesen Code für 2 Jahre auf x86 laufen, und vor zwei Wochen habe ich versucht, es zu jeder CPU zu kompilieren. Und es funktioniert nicht. Ich habe etwas gelesen und ich habe nichts gefunden. Ich bin ein Anfänger und wenn Sie mir helfen wollen, werde ich es schätzen.VB.NET ANYCPU ReadProcessMemory
<StructLayout(LayoutKind.Sequential)>
Public Structure MEMORY_BASIC_INFORMATION
Public BaseAddress As Integer
Public AllocationBase As Integer
Public AllocationProtect As Integer
Public RegionSize As Integer
Public State As Integer
Public Protect As Integer
Public lType As Integer
End Structure
<StructLayout(LayoutKind.Sequential)>
Public Structure SYSTEM_INFO
Dim dwOemID As Integer
Dim dwPageSize As Integer
Dim lpMinimumApplicationAddress As Integer
Dim lpMaximumApplicationAddress As Integer
Dim dwActiveProcessorMask As Integer
Dim dwNumberOrfProcessors As Integer
Dim dwProcessorType As Integer
Dim dwAllocationGranularity As Integer
Dim dwReserved As Integer
End Structure
<DllImport("kernel32.dll", EntryPoint:="VirtualQueryEx", SetLastError:=True), SuppressUnmanagedCodeSecurity()>
Public Function VirtualQueryEx(ByVal hProcess As IntPtr, ByVal lpAddress As UInteger, ByRef lpBuffer As MEMORY_BASIC_INFORMATION, ByVal dwLength As Integer) As Integer
End Function
<DllImport("kernel32.dll", EntryPoint:="GetSystemInfo", SetLastError:=True), SuppressUnmanagedCodeSecurity()>
Public Sub GetSystemInfo(ByRef lpSystemInfo As SYSTEM_INFO)
End Sub
<DllImport("kernel32.dll", EntryPoint:="OpenProcess", SetLastError:=True), SuppressUnmanagedCodeSecurity()>
Public Function OpenProcess(ByVal dwDesiredAccess As Integer, ByVal blnheritHandle As Boolean, ByVal dwAppProcessId As Integer) As IntPtr
End Function
<DllImport("kernel32.dll", EntryPoint:="CloseHandle", SetLastError:=True), SuppressUnmanagedCodeSecurity()>
Public Function CloseHandle(ByVal hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("kernel32.dll", EntryPoint:="ReadProcessMemory", SetLastError:=True), SuppressUnmanagedCodeSecurity()>
Public Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer() As Byte, ByVal iSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
End Function
Public Const PROCESS_VM_READ = (&H10)
Public Const PROCESS_VM_OPERATION = (&H8)
Public Const PROCESS_QUERY_INFORMATION = (&H400)
Public Const PROCESS_READ_WRITE_QUERY = PROCESS_VM_READ + PROCESS_VM_OPERATION + PROCESS_QUERY_INFORMATION
Public Sub Test2()
Dim _targetProcessHandle As IntPtr = System.Diagnostics.Process.GetProcesses("solitaire")(0).Handle
Dim _mbi As MEMORY_BASIC_INFORMATION, _sysInfo As SYSTEM_INFO
Dim _mbiSize As Int32 = System.Runtime.InteropServices.Marshal.SizeOf(_mbi)
GetSystemInfo(_sysInfo)
Dim _addr As Integer = _sysInfo.lpMinimumApplicationAddress
Dim _readBuff(_sysInfo.dwPageSize - 1) As Byte
Dim _actualBytesRead As Int32 = 0
Dim _oldPageProtection As UInt32 = 0
Dim _accessRightsChanged As Boolean = False
_targetProcessHandle = OpenProcess(PROCESS_READ_WRITE_QUERY, False, CInt(_targetProcessHandle))
Dim ret As Integer
Do
ret = VirtualQueryEx(_targetProcessHandle, CType(_addr, IntPtr), _mbi, _mbiSize)
If ret = _mbiSize Then
If ((_mbi.lType = &H20000) And (_mbi.State = &H1000) And (_mbi.RegionSize > 0)) Then
Dim _byteBuff(_mbi.RegionSize) As Byte
ReadProcessMemory(_targetProcessHandle, _mbi.BaseAddress, _byteBuff, _mbi.RegionSize, 0)
'Do some work
Array.Clear(_byteBuff, 0, _byteBuff.Length)
End If
_addr = _mbi.BaseAddress + _mbi.RegionSize
End If
Loop While _addr < _sysInfo.lpMaximumApplicationAddress
CloseHandle(_targetProcessHandle)
End Sub
Dies funktioniert problemlos auf X86, aber es möchte nicht auf AnyCpu ausgeführt werden. Kannst du mir bitte helfen ? Danke im Voraus.
'Öffentliche Funktion VirtualQueryEx (ByVal hProzess als IntPtr, ByVal lpAddress als IntPtr, ByRef lpBuffer als MEMORY_BASIC_INFORMATION, ByVal dwLength als IntPtr) Wie IntPtr' – GSerg
hast du nur x86 und x64 versucht? 32-Bit- und 64-Bit-System mit einigen Unterschieden beim Lesen von Bits. – snoopcommands
'Öffentliche Funktion ReadProcessMemory (ByVal hProcess als IntPtr, ByVal lpBaseAddress als IntPtr, ByVal lpBuffer() als Byte, ByVal iSize als IntPtr, ByRef lpNumberOfBytesRead als IntPtr) Wie Boolean ' – GSerg