프로그래밍언어/VB.NET

writeprocessmemory

부산딸랑이 2013. 7. 14. 16:46

   Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer

    Private Declare Function WriteProcessMemory1 Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer

 

   Public Sub WriteInteger(ByVal ProcessName As String, ByVal Address As Integer, ByVal Value As Integer, Optional ByVal nsize As Integer = 4)

        If ProcessName.EndsWith(".exe") Then

            ProcessName = ProcessName.Replace(".exe", "")

        End If

        Dim MyP As Process() = Process.GetProcessesByName(ProcessName)

        If MyP.Length = 0 Then

            MessageBox.Show(ProcessName & " isn't open!")

            Exit Sub

        End If

        Dim hProcess As IntPtr = OpenProcess(PROCESS_ALL_ACCESS, 0, MyP(0).Id)

        If hProcess = IntPtr.Zero Then

            MessageBox.Show("Failed to open " & ProcessName & "!")

            Exit Sub

        End If


        Dim hAddress, vBuffer As Integer

        hAddress = Address

        vBuffer = Value

        WriteProcessMemory1(hProcess, hAddress, CInt(vBuffer), nsize, 0)

    End Sub

'프로그래밍언어 > VB.NET' 카테고리의 다른 글

VB.NET 체크박스 사용하기  (0) 2013.07.31
wpf Property lisview  (0) 2013.07.15
비베닷넷 무료 IDE   (0) 2013.07.13
VB.NET 문자열 배열내 값찾기  (0) 2013.07.13
VB.NET 동적컨트롤 생성  (0) 2013.07.10