0

当我运行此代码块时,它会运行,但是当我尝试将正在运行的进程内存地址的字符串值更改为其他时,它会给我一个错误:

"System.IndexoutofRangeException Index was outside the Bounds of the Array"

这些是功能:

 <DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As  IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As System.UInt32, <Out()> ByRef lpNumberOfBytesWritten As Int32) As Boolean
End Function
Public Shared Function StrToByteArray(ByVal str As String) As Byte()
    Dim encoding As New System.Text.ASCIIEncoding()
    Return encoding.GetBytes(str)
End Function
Public Shared Function Poke(ByVal proc As Process, ByVal target As Integer, ByVal data As Byte()) As Boolean
    Return WriteProcessMemory(proc.Handle, New IntPtr(target), data, data.Length, 0)
End Function

这是执行更改的内存地址值字符串的按钮。

Private Sub saveButton_Click(sender As Object, e As EventArgs) Handles saveButton.Click
    Try
        Dim p As Process() = Process.GetProcessesByName(AppName.Text)
        Dim Written As Boolean = False

        Written = Poke(p(0), &HB8FDCC, StrToByteArray(TxtVal.Text))

        If Written = True Then

            MsgBox("WriteProcessMemory Sucess!", MsgBoxStyle.OkOnly, "Poke Memory Status")


        ElseIf Written = False Then

            MsgBox("WriteProcessMemory Failed!", MsgBoxStyle.OkOnly, "Poke Memory Status")

        End If

    Catch ex As Exception

        MsgBox(ex.ToString)

    End Try
End Sub

End Class
4

1 回答 1

0

不要以进程的名称添加程序/应用程序的扩展名,在您的情况下,Chrome AppName.Text 必须是“Chrome”而不是“Chrome.exe”,祝你好运。

于 2013-05-30T09:03:29.977 回答