当前位置: 代码迷 >> VB Dotnet >> 例如内存地址00CB1111里边的A9 73 8C 5B 8E 7F 16 4E 4C 75 FD 56 45 96 48 72 84 76读取出来并转换成汉字
  详细解决方案

例如内存地址00CB1111里边的A9 73 8C 5B 8E 7F 16 4E 4C 75 FD 56 45 96 48 72 84 76读取出来并转换成汉字

热度:358   发布时间:2016-04-25 02:13:33.0
比如内存地址00CB1111里边的A9 73 8C 5B 8E 7F 16 4E 4C 75 FD 56 45 96 48 72 84 76读取出来并转换成汉字
比如内存地址00CB1111里边的A9 73 8C 5B 8E 7F 16 4E 4C 75 FD 56 45 96 48 72 84 76读取出来并转换成汉字啊,请大神给出代码
------解决方案--------------------
参考: VB.NET读取内存的函数
使用WINAPI的ReadProcessMemory函数读取内存地址。示例用法

    Private hwd As Integer
    Private pid As Integer
    Private hProcess As Integer
    Private Const WM_READ As Integer = &H10
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
    Private Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
    Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer
    Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer() As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Private Function mGetString() As String
        On Error Resume Next
        Dim Base() As Byte
        ReDim Base(31)
        Dim word As String
        Dim bytesRead As Integer = 0
        Dim ClassName As String = "#11111"
        hwd = FindWindow(ClassName, vbNullString)
        If hwd = 0 Then Return ("")
        GetWindowThreadProcessId(hwd, pid)
        If pid = 0 Then Return ""
        hProcess = OpenProcess(WM_READ, 0, pid)
        If hProcess <> 0 Then
            hProcess = OpenProcess(WM_READ, False, pid)
            If hProcess Then
                ReadProcessMemory(hProcess, &H111110, Base, Base.Length, bytesRead)
                word = System.Text.Encoding.Default.GetString(Base, 0, Base.Length)
                word = Mid(word, 1, InStr(word, Chr(0)) - 1)
                'word = Replace(word, Chr(0), "")
                word = word.Trim
                CloseHandle(hProcess)
                Return word
            Else
                Return ""
            End If
        Else
            Return ""
        End If
    End Function