Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module ProcessRoutines
- Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAcess As UInt32, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Int32) As IntPtr
- Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer() As Byte, ByVal iSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
- Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As IntPtr) As Boolean
- Public _targetProcess As Process = Nothing
- Public _targetProcessHandle As IntPtr = IntPtr.Zero
- Private PROCESS_ALL_ACCESS As UInt32 = &H1F0FFF
- Private PROCESS_VM_READ As UInt32 = &H10
- 'Find process
- Public Function TryAttachToProcess(ByVal windowCaption As String) As Boolean
- Dim _allProcesses() As Process = Process.GetProcesses
- For Each pp As Process In _allProcesses
- If pp.MainWindowTitle.ToLower.Contains(windowCaption.ToLower) Then
- 'found it! proceed.
- Return TryAttachToProcess(pp)
- End If
- Next
- Return False
- End Function
- 'Inject to process
- Private Function TryAttachToProcess(ByVal proc As Process) As Boolean
- If _targetProcessHandle = IntPtr.Zero Then 'not already attached
- _targetProcess = proc
- _targetProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, _targetProcess.Id)
- If CInt(_targetProcessHandle) = 0 Then
- TryAttachToProcess = False
- MessageBox.Show("FAIL! Are you Administrator??")
- Else
- 'if we get here, all connected and ready to use ReadProcessMemory()
- TryAttachToProcess = True
- End If
- Else
- MessageBox.Show("Already attached!")
- TryAttachToProcess = False
- End If
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement