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
Public Function inject(ByVal ProcessID As Long, ByVal DLLPath As String) As Boolean
On Error GoTo exiterror
Dim DProc As Integer
Dim DAdd As Integer
Dim DWrote As UInteger
Dim DAll As Integer
Dim DThe As Integer
Dim DMHD As Integer
DProc = OpenProcess(&H1F0FFF, 1, ProcessID)
DAdd = VirtualAllocEx(DProc, 0, DLLPath.Length, &H1000, &H4)
If (DAdd > 0) Then
Dim DByte() As Byte
DByte = StrChar(DLLPath)
WriteProcessMemory(DProc, DAdd, DByte, DLLPath.Length, DWrote)
DMHD = GetModuleHandle("kernel32.dll")
DAll = GetProcAddress(DMHD, "LoadLibraryA")
DThe = CreateRemoteThread(DProc, 0, 0, DAll, DAdd, 0, 0)
If (DThe > 0) Then
WaitForSingleObject(DThe, &HFFFF)
CloseHandle(DThe)
Return True
Else
GoTo exiterror
End If
Else
GoTo exiterror
End If
inject = True
Exit Function
exiterror:
inject = False
End Function
Private Function StrChar(ByRef strString As String) As Byte()
Dim bytTemp() As Byte
Dim i As Short
ReDim bytTemp(0)
For i = 1 To Len(strString)
If bytTemp(UBound(bytTemp)) <> 0 Then ReDim Preserve bytTemp(UBound(bytTemp) + 1)
bytTemp(UBound(bytTemp)) = Asc(Mid(strString, i, 1))
Next i
ReDim Preserve bytTemp(UBound(bytTemp) + 1)
bytTemp(UBound(bytTemp)) = 0
StrChar = bytTemp
End Function
End Module
[/php]
Originally Posted by ilikewaterha
Just because you nerds think its simple..
Those tryhards don't lol =P
Just because you nerds think its simple..
Those tryhards don't lol =P
Why do you always call us nerds whenever you wander back into this section? It's hardly rocket science. OMG I CAN HAZ PARAMETERS FOR MAI SUBZ? NO FUXIN WAY!
Lol because you're nerds =P
Nerds = Smart people
You = Nerd at VB = Good at VB
-facepalm-
And wander back?
Its not like i cave anywhere else?
Unlike you who entirely caves in this section xD
Originally Posted by ilikewaterha
Lol because you're nerds =P
Nerds = Smart people
You = Nerd at VB = Good at VB
-facepalm-
And wander back?
Its not like i cave anywhere else?
Unlike you who entirely caves in this section xD
By wander back in I mean you disappear for weeks then randomly pop back in.
Nerd = Derogatory term for smart people = insult.
Also, I visit pretty much every section, but I contribute most here.
Alright, lets sort this out.
1. Me disappearing, just had to sort out my life, do some stuff, so i didn't have much time for MPGH.
2. Didn't mean it to be offensive, i'll call you smartass from now on ^^.
3. Meh, caver xD. You pretty much most on VB , so yeah ..
End of story. - back on topic-
Why processid, why not name? Go edit it and make it accept the name instead of the id :P
Err :P
Give me a bit =P
Blubb you're a lazy mofo.
I'll do the groundwork.
Whack this into the module.
[php]
Private Function GetPID(ByVal ProcName as String)
if ProcName.Contains(".exe") then
ProcName = ProcName.Replace(".exe", "")
End if
dim PID as integer = 0
For Each p As Process in Process.GetProcesses(My.Computer.Name)
If p.ProcessName = ProcName then
PID = p.ID
End If
Return PID
End Function
[/php]
Then modify your inject function like so:
[php]
Public Function inject(ByVal ProcName As Long, ByVal DLLPath As String) As Boolean
Dim ProcessID As Integer = GetPID(ProcName)
If ProcessID = 0 then
GoTo exiterror
End If
On Error GoTo exiterror
Dim DProc As Integer
Dim DAdd As Integer
Dim DWrote As UInteger
Dim DAll As Integer
Dim DThe As Integer
Dim DMHD As Integer
DProc = OpenProcess(&H1F0FFF, 1, ProcessID)
DAdd = VirtualAllocEx(DProc, 0, DLLPath.Length, &H1000, &H4)
If (DAdd > 0) Then
Dim DByte() As Byte
DByte = StrChar(DLLPath)
WriteProcessMemory(DProc, DAdd, DByte, DLLPath.Length, DWrote)
DMHD = GetModuleHandle("kernel32.dll")
DAll = GetProcAddress(DMHD, "LoadLibraryA")
DThe = CreateRemoteThread(DProc, 0, 0, DAll, DAdd, 0, 0)
If (DThe > 0) Then
WaitForSingleObject(DThe, &HFFFF)
CloseHandle(DThe)
Return True
Else
GoTo exiterror
End If
Else
GoTo exiterror
End If
inject = True
Exit Function
exiterror:
inject = False
[/php]
Why 2 functions, put both together
Originally Posted by Blubb1337
Why 2 functions, put both together
Meh I like function, the inject one was already there and I like having a re-usable function for a later date, keeps things tidy.