Injector Class (Should work for 64bit)
it is a simple update and edited class to the sdk nextgen posted and stuff. Just added a few things to see how they go :O
Credits
@topblast
@NextGen1
[highlight="VB.Net"]
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Text
Imports System.Diagnostics
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.IO.Compression
Imports System.Security.Cryptography
Imports System.Net
Imports System.Windows.Forms
Imports System.Management
Imports System.Xml.XPath
Public Class Injector
Public Shared LOG As String
Private Shared Sub AddLog(ByVal text As String)
LOG = LOG + text + vbNewLine
End Sub
Private Shared Sub AddError(ByVal text As String)
AddLog(text)
MessageBox.Show(text, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub
Friend Declare Auto Function WaitForSingleObject Lib "kernel32" (ByVal handle As IntPtr, ByVal milliseconds As Int32) As Int32
<DllImport("kernel32")> _
Private Shared Function CreateRemoteThread(ByVal hProcess As IntPtr, ByVal lpThreadAttributes As IntPtr, ByVal dwStackSize As UInteger, ByVal lpStartAddress As UIntPtr, ByVal lpParameter As IntPtr, ByVal dwCreationFlags As UInteger, ByRef lpThreadId As IntPtr) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Private Shared Function OpenProcess(ByVal dwDesiredAccess As UInt32, ByVal bInheritHandle As Int32, ByVal dwProcessId As Int32) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)> _
Private Shared Function GetProcAddress(ByVal hModule As IntPtr, ByVal procName As String) As UIntPtr
End Function
<DllImport("kernel32.dll")> _
Private Shared Function CloseHandle(ByVal hObject As IntPtr) As Int32
End Function
Private Declare Auto Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UIntPtr, ByVal dwFreeType As UInteger) As Boolean
Private Declare Auto Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal flAllocationType As UInteger, ByVal flProtect As UInteger) As IntPtr
<DllImport("kernel32.dll")> _
Private Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Object, ByVal nSize As UIntPtr, ByRef lpNumberOfBytesWritten As IntPtr) As Boolean
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr
End Function
Private Shared Function ProcessId(ByVal proc As [String]) As Int32
Dim ProcLRet As Process()
ProcLRet = Process.GetProcessesByName(proc)
Return ProcLRet(0).Id
End Function
Private Shared Function Inject(ByVal oProcess As IntPtr, ByVal strDLLName As [String]) As Boolean
Try
Dim bytes As IntPtr
Dim Len As Int32 = strDLLName.Length + 1
Dim AllMem As IntPtr = VirtualAllocEx(oProcess, IntPtr.Zero, CUInt(Len), &H1000, &H40)
WriteProcessMemory(oProcess, AllMem, strDLLName, Len, bytes)
Dim Injector As UIntPtr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA")
If Injector = Nothing Then
AddError("Injector: Error ID 001, Fail to find Fail to find [ Kernel32.dll::LoadLibraryA ]")
Return False
End If
Dim ThreadHd As IntPtr = CreateRemoteThread(oProcess, IntPtr.Zero, 0, Injector, AllMem, 0, bytes)
If ThreadHd = Nothing Then
AddError("Injector: Error ID 101, Fail to start DLL")
Return False
End If
Dim Result As Integer = WaitForSingleObject(ThreadHd, Int32.MaxValue)
If Result = 128L OrElse Result = 258L OrElse Result = &HFFFFFFFF Then
If Result = 258L Then
AddError("Injector: Error ID 201, FAIL Waiting to Long for Object")
Else
AddError("Injector: Error ID 202, Injection fail")
End If
If Not ThreadHd = Nothing Then
Return CloseHandle(ThreadHd)
End If
Return False
End If
Thread.Sleep(10)
VirtualFreeEx(oProcess, AllMem, 0, &H8000)
If Not ThreadHd = Nothing Then
Return CloseHandle(ThreadHd)
End If
Return False
Catch ex As Exception
Return False
End Try
End Function
Public Shared Function InjectDirect(ByVal DLLName As [String], ByVal ProcessName As [String]) As Boolean
Dim ProcID As Int32 = ProcessId(ProcessName)
If ProcID >= 0 Then
AddLog("Injector: Getting Process Info")
Dim oProcess As String = OpenProcess(&H1F0FFF, 1, ProcID)
If oProcess Is Nothing Then
AddLog("Injector: Error, Starting Process FAILED!")
AddLog("-------------------------------------------")
MessageBox.Show("ERROR: Process start FAILED", "Process Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Exit Function
Else
Dim val = Inject(oProcess, DLLName)
AddLog("Injector: Injected is " + val.ToString)
AddLog("-------------------------------------------")
Return val
End If
End If
Return False
End Function
Public Shared Function InjectDirect(ByVal DLLName As [String], ByVal ProcID As [Int32]) As Boolean
If ProcID >= 0 Then
AddLog("Injector: Getting Process Info")
Dim oProcess As String = OpenProcess(&H1F0FFF, 1, ProcID)
If oProcess Is Nothing Then
AddLog("Injector: Error, Starting Process FAILED!")
AddLog("-------------------------------------------")
MessageBox.Show("ERROR: Process start FAILED", "Process Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Exit Function
Else
Dim val = Inject(oProcess, DLLName)
AddLog("Injector: Injected is " + val.ToString)
AddLog("-------------------------------------------")
Return val
End If
End If
Return False
End Function
End Class
[/highlight]
Credits
@topblast
@NextGen1
[highlight="VB.Net"]
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Text
Imports System.Diagnostics
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.IO.Compression
Imports System.Security.Cryptography
Imports System.Net
Imports System.Windows.Forms
Imports System.Management
Imports System.Xml.XPath
Public Class Injector
Public Shared LOG As String
Private Shared Sub AddLog(ByVal text As String)
LOG = LOG + text + vbNewLine
End Sub
Private Shared Sub AddError(ByVal text As String)
AddLog(text)
MessageBox.Show(text, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub
Friend Declare Auto Function WaitForSingleObject Lib "kernel32" (ByVal handle As IntPtr, ByVal milliseconds As Int32) As Int32
<DllImport("kernel32")> _
Private Shared Function CreateRemoteThread(ByVal hProcess As IntPtr, ByVal lpThreadAttributes As IntPtr, ByVal dwStackSize As UInteger, ByVal lpStartAddress As UIntPtr, ByVal lpParameter As IntPtr, ByVal dwCreationFlags As UInteger, ByRef lpThreadId As IntPtr) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Private Shared Function OpenProcess(ByVal dwDesiredAccess As UInt32, ByVal bInheritHandle As Int32, ByVal dwProcessId As Int32) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)> _
Private Shared Function GetProcAddress(ByVal hModule As IntPtr, ByVal procName As String) As UIntPtr
End Function
<DllImport("kernel32.dll")> _
Private Shared Function CloseHandle(ByVal hObject As IntPtr) As Int32
End Function
Private Declare Auto Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UIntPtr, ByVal dwFreeType As UInteger) As Boolean
Private Declare Auto Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal flAllocationType As UInteger, ByVal flProtect As UInteger) As IntPtr
<DllImport("kernel32.dll")> _
Private Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Object, ByVal nSize As UIntPtr, ByRef lpNumberOfBytesWritten As IntPtr) As Boolean
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr
End Function
Private Shared Function ProcessId(ByVal proc As [String]) As Int32
Dim ProcLRet As Process()
ProcLRet = Process.GetProcessesByName(proc)
Return ProcLRet(0).Id
End Function
Private Shared Function Inject(ByVal oProcess As IntPtr, ByVal strDLLName As [String]) As Boolean
Try
Dim bytes As IntPtr
Dim Len As Int32 = strDLLName.Length + 1
Dim AllMem As IntPtr = VirtualAllocEx(oProcess, IntPtr.Zero, CUInt(Len), &H1000, &H40)
WriteProcessMemory(oProcess, AllMem, strDLLName, Len, bytes)
Dim Injector As UIntPtr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA")
If Injector = Nothing Then
AddError("Injector: Error ID 001, Fail to find Fail to find [ Kernel32.dll::LoadLibraryA ]")
Return False
End If
Dim ThreadHd As IntPtr = CreateRemoteThread(oProcess, IntPtr.Zero, 0, Injector, AllMem, 0, bytes)
If ThreadHd = Nothing Then
AddError("Injector: Error ID 101, Fail to start DLL")
Return False
End If
Dim Result As Integer = WaitForSingleObject(ThreadHd, Int32.MaxValue)
If Result = 128L OrElse Result = 258L OrElse Result = &HFFFFFFFF Then
If Result = 258L Then
AddError("Injector: Error ID 201, FAIL Waiting to Long for Object")
Else
AddError("Injector: Error ID 202, Injection fail")
End If
If Not ThreadHd = Nothing Then
Return CloseHandle(ThreadHd)
End If
Return False
End If
Thread.Sleep(10)
VirtualFreeEx(oProcess, AllMem, 0, &H8000)
If Not ThreadHd = Nothing Then
Return CloseHandle(ThreadHd)
End If
Return False
Catch ex As Exception
Return False
End Try
End Function
Public Shared Function InjectDirect(ByVal DLLName As [String], ByVal ProcessName As [String]) As Boolean
Dim ProcID As Int32 = ProcessId(ProcessName)
If ProcID >= 0 Then
AddLog("Injector: Getting Process Info")
Dim oProcess As String = OpenProcess(&H1F0FFF, 1, ProcID)
If oProcess Is Nothing Then
AddLog("Injector: Error, Starting Process FAILED!")
AddLog("-------------------------------------------")
MessageBox.Show("ERROR: Process start FAILED", "Process Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Exit Function
Else
Dim val = Inject(oProcess, DLLName)
AddLog("Injector: Injected is " + val.ToString)
AddLog("-------------------------------------------")
Return val
End If
End If
Return False
End Function
Public Shared Function InjectDirect(ByVal DLLName As [String], ByVal ProcID As [Int32]) As Boolean
If ProcID >= 0 Then
AddLog("Injector: Getting Process Info")
Dim oProcess As String = OpenProcess(&H1F0FFF, 1, ProcID)
If oProcess Is Nothing Then
AddLog("Injector: Error, Starting Process FAILED!")
AddLog("-------------------------------------------")
MessageBox.Show("ERROR: Process start FAILED", "Process Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Exit Function
Else
Dim val = Inject(oProcess, DLLName)
AddLog("Injector: Injected is " + val.ToString)
AddLog("-------------------------------------------")
Return val
End If
End If
Return False
End Function
End Class
[/highlight]



