Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region "Injector Code"
- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
- Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Integer, ByVal lpAddress As Integer, ByVal dwSize As Integer, ByVal flAllocationType As Integer, ByVal flProtect As Integer) As Integer
- Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer() As Byte, ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As UInteger) As Boolean
- Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Integer, ByVal lpProcName As String) As Integer
- Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Integer
- Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Integer, ByVal lpThreadAttributes As Integer, ByVal dwStackSize As Integer, ByVal lpStartAddress As Integer, ByVal lpParameter As Integer, ByVal dwCreationFlags As Integer, ByVal lpThreadId As Integer) As Integer
- Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Integer, ByVal dwMilliseconds As Integer) As Integer
- Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
- Private Function Inject(ByVal ProcessName As String, ByVal dllLocation As String, ByVal CAI As Boolean) As Boolean
- Label2.Text = "Injecting ..."
- Threading.Thread.Sleep(500)
- Dim pID As Integer = System.Diagnostics.Process.GetProcessesByName(ProcessName)(0).Id
- Dim hProcess As Integer = OpenProcess(&H1F0FFF, 1, pID)
- If hProcess = 0 Then Return False
- Dim dllBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(dllLocation)
- Dim allocAddress As Integer = VirtualAllocEx(hProcess, 0, dllBytes.Length, &H1000, &H4)
- If allocAddress = Nothing Then Return False
- Dim kernelMod As Integer = GetModuleHandle("kernel32.dll")
- Dim loadLibAddr = GetProcAddress(kernelMod, "LoadLibraryA")
- If kernelMod = 0 OrElse loadLibAddr = 0 Then Return False
- WriteProcessMemory(hProcess, allocAddress, dllBytes, dllBytes.Length, 0)
- Dim libThread As Integer = CreateRemoteThread(hProcess, 0, 0, loadLibAddr, allocAddress, 0, 0)
- If libThread = 0 Then
- Return False
- Else
- WaitForSingleObject(libThread, 5000)
- CloseHandle(libThread)
- End If
- CloseHandle(hProcess)
- If CAI = True Then
- Close()
- End If
- Return True
- End Function
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment