InjectDll UDF

02/12/2011 00:56 KDeluxe#1
Code:
;=================================================================================================
; Function:          _InjectDll($processId, $dllPath)
; Description:       Injects a .dll into a running program.
; Return Value(s):   On Success - Returns true
;                    On Failure - Returns false
;                    @Error - 0 = No error.
;                             1 = Invalid ProcessId
;                             2 = File does not exist
;                             3 = File is not a .dll (invalid file)
;                             4 = Failed to open 'Advapi32.dll'
;                             5 = Failed to get the full path
;                             6 = Failed to open the process
;                             7 = Failed to call 'GetModuleHandle'
;                             8 = Failed to call 'GetProcAddress'
;                             9 = Failed to call 'VirtualAllocEx'
;                             10 = Failed to write the memory
;                             11 = Failed to create the 'RemoteThread'
; Author(s):        KDeluxe
;=================================================================================================

Func _InjectDll($processId, $dllPath)
    If ProcessExists($processId) == 0 Then Return SetError(1, "", False)
    If Not FileExists($dllPath) Then Return SetError(2, "", False)
    If Not StringRight($dllPath, 4) == ".dll" Then Return SetError(3, "", False)

    $dllKernel32 = DllOpen("Kernel32.dll")
    If @error Then Return SetError(4, "", False)

    $dllPathStruct = DllStructCreate("char[255]")
    DllCall($dllKernel32, "DWORD", "GetFullPathNameA", "str", $dllPath, "DWORD", 255, "ptr", DllStructGetPtr($dllPathStruct), "int", 0)
    If @error Then Return SetError(5, "", False)

    $PROCESS_ALL_ACCESS = 0x001F0FFF
    If @OSBuild >= 6000 Then $PROCESS_ALL_ACCESS = BitOR($PROCESS_ALL_ACCESS, 0xF000)

    $process = DllCall($dllKernel32, "DWORD", "OpenProcess", "DWORD", $PROCESS_ALL_ACCESS, "int", 0, "DWORD", $processId)
    If @error Then Return SetError(6, "", False)

    $module = DllCall($dllKernel32, "DWORD", "GetModuleHandleA", "str", "kernel32.dll")
    If @error Then Return SetError(7, "", False)

    $startAddress = DllCall($dllKernel32, "DWORD", "GetProcAddress", "DWORD", $module[0], "str", "LoadLibraryA")
    If @error Then Return SetError(8, "", False)

    $parameter = DllCall($dllKernel32, "DWORD", "VirtualAllocEx", "int", $process[0], "int", 0, "ULONG_PTR", DllStructGetSize($dllPathStruct), "DWORD", 0x3000, "int", 4)
    If @error Then Return SetError(9, "", False)

    DllCall($dllKernel32, "BOOL", "WriteProcessMemory", "int", $process[0], "DWORD", $parameter[0], "str", DllStructGetData($dllPathStruct, 1), "ULONG_PTR", DllStructGetSize($dllPathStruct), "int", 0)
    If @error Then Return SetError(10, "", False)

    DllCall($dllKernel32, "int", "CreateRemoteThread", "DWORD", $process[0], "int", 0, "int", 0, "DWORD", $startAddress[0], "DWORD", $parameter[0], "int", 0, "int", 0)
    If @error Then Return SetError(11, "", False)

    DllCall($dllKernel32, "BOOL", "CloseHandle", "DWORD", $process[0])
    DllClose($dllKernel32)

    Return SetError(0, "", True)
EndFunc
02/12/2011 09:51 TrickGamer#2
nicht das ich jz nerve aber eine inject udf gibts schon in einem anderen autoit forum
aber trotzdem,nicht jeder findet sie und gut das das hier gepostet wird ;)
ps. Download geht bei mir nicht.
02/12/2011 11:57 KDeluxe#3
Quote:
Originally Posted by KillerDeluxe View Post
Es gibt zwar schon UDFs für das injizieren von .dlls, aber ich kenne niemanden, bei dem diese auch funktionieren.
Mein Grund, weshalb ich diese UDF erstellt habe, steht schon in der 1. Zeile.
Die Datei wurde gelöscht, ich hab sie aber wie hoch geladen.
02/12/2011 13:52 PenGuin :O#4
Quote:
Es gibt zwar schon UDFs für das injizieren von .dlls, aber ich kenne niemanden, bei dem diese auch funktionieren.
Bei mir funktioniert diese: