0

したがって、このコードを x86 で 2 年間実行し、2 週間前に任意の CPU にコンパイルしようとしました。そして、それは機能しません。私はいくつかの読書をしましたが、何も見つかりませんでした。私は初心者です。もし私を助けたいなら、私はそれを感謝します。

 <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

これは X86 では問題なく動作しますが、AnyCpu では実行したくありません。私を助けてくれませんか?前もって感謝します。

4

1 に答える 1