none
WriteProcessMemory到自己 的問題 RRS feed

  • 問題

  • Code Snippet

        Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByRef lpBuffer As Integer, ByVal nSize As Integer, <Out()> ByRef lpNumberOfBytesWritten As Integer) As Boolean

        Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
        Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer

     

        Public Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000
        Public Const SYNCHRONIZE As Integer = &H100000
        Public Const SPECIFIC_RIGHTS_ALL As Short = &HFFFFS
        Public Const STANDARD_RIGHTS_ALL As Integer = &H1F0000
        Public Const PROCESS_ALL_ACCESS As Boolean = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFFS
        Public Const PROCESS_VM_OPERATION As Integer = &H8
        Public Const PROCESS_VM_READ As Integer = &H10
        Public Const PROCESS_VM_WRITE As Integer = &H20

     


        Private Sub WriteIntToMe()
            Dim MyProcess As Process = Process.GetCurrentProcess
            Dim hProcess As Integer
            hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, MyProcess.Id)
            WriteProcessMemory(hProcess, &H400400, 12345, 4, 0)
            CloseHandle(hProcess)
        End Sub

     

     

     

     


    我把&H400400的值,以4bytes型式,改成12345

    但是,每次都不成功,也沒成功寫入(傳回值:False)

    已知400400區是ReadWrite皆可的區域

     

     

    請問有高手知道如何解決嗎?   

    2008年9月13日 下午 12:19

解答