EmptyDllCreator

  • Hey Community,

    Für Leute die gerne die Resourcen in Dlls verlagern ist dieses Script perfekt.
    Es erstellt per Knopfdruck eine leere Dll ohne unnötigen Balast (Keine Funktionen, Keine Imports/Exports)

    Hier der minimalistische Code:

    Spoiler anzeigen
    [autoit]


    #NoTrayIcon

    [/autoit] [autoit][/autoit] [autoit]

    Global $bEmptyDll = "0x4D5A80000100000004001000FFFF0000400100000000000040000000000000" & _
    "0000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B" & _
    "409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20" & _
    "444F53206D6F64652E0D0A240000000000000000504500004C010300B170B04D0000000000000" & _
    "000E0000E210B0101450000000000000000000000000000000000100000001000000000400000" & _
    "10000000020000010000000000000004000000000000000010000000020000929700000200400" & _
    "10010000000100000000001000000000000000000100000000010000000000000000000000000" & _
    "00000000000000000000000000000000000000000000000000000010000000000000000000000" & _
    "00000000000000000000000000000000000000000000000000000000000000000000000000000" & _
    "000000000000000000000000000000000000000000000000000000000000000000000000002E7" & _
    "46578740000000000000000100000000000000002000000000000000000000000000020000060" & _
    "2E656461746100000000000000100000000000000002000000000000000000000000000040000" & _
    "0402E72656C6F6300000000000000100000000000000002000000000000000000000000000040" & _
    "00000200000000000000000000000000000000" ;Created with FASM (Flat Assembler)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hMainGui = GUICreate("EmptyDllCreator", 250, 48)
    Global $hMainCreate = GUICtrlCreateButton("Create empty Dll", 8, 8, 234, 32)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    Case $hMainCreate
    $sSave = FileSaveDialog("EmptyDllCreator", "", "Dynamic Link Libary (*.dll)", 18, "", $hMainGui)
    If @error Then ContinueLoop

    [/autoit] [autoit][/autoit] [autoit]

    If StringRight($sSave, 4) <> ".dll" Then $sSave &= ".dll"

    [/autoit] [autoit][/autoit] [autoit]

    $hFile = FileOpen($sSave, 18) ;Binary mode + Write mode (Erease old Content)
    FileWrite($hFile, $bEmptyDll)
    FileClose($hFile)

    [/autoit] [autoit][/autoit] [autoit]

    Exit
    EndSwitch
    WEnd

    [/autoit]

    Der Code für die leere DLL in FASM:

    Code
    format PE GUI 4.0 DLL
    section '.text' code readable executable
    section '.edata' export data readable
    section '.reloc' fixups data discardable

    Eine erstellte DLL ist 512 Byte groß. Kleiner habe ich sie nicht bekommen :D

    viel Spaß mit dem kleinen Tool.
    PS: Verbesserungsvorschläge oder ähnliches immer gerne gesehen.

  • Echt nützlich das Script.
    Gerade für mich ^^ xD Benötige relativ oft DLL´s.

    Keep it up!

  • Ich versteh zwar nicht viel von dlls, aber ich sehe keinen Nutzen in einer leeren dll, kannst du mal ein Beispiel posten, wofür man sowas gebrauchen kann?

    DFPWare


    Das ist nützlich, wenn man eine DLL mit Ressourcen nicht selbst über rc-Dateien kompilieren will, sondern dies einfach per GUI (Reshacker) machen möchte.

  • Also mach ich mir jetzt mit dem programm ne dll und füg da mit reshack funktionen ein?


    Du erstellst dir die leere DLL und fügst dann Ressourcen wie Bilder, Icons, Sounds, Texte, ... ein, keine Funktionen. Funktionen müssen programmiert und dann kompiliert werden.

    • Offizieller Beitrag

    Ich habe heute mal eine Dll damit erstellt und versucht zu nutzen. Jedoch kann ich nichts aus der Dll wieder laden.
    Habe dann eine existierende Dll ausgeschlachtet und die identischen Inhalte eingebaut - daraus kann ich auch wieder laden.
    Bei deiner Dll kann die "SizeofResource" nicht ermittelt werden. Ich habe beide Dll mal angehängt.

    Spoiler anzeigen
    [autoit]

    #include-once
    #include <WinAPI.au3>
    #include <Memory.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $res1 = @ScriptDir & '\ressource.dll' ; Leer-Dll erstellt mit "EmptyDllCreator"
    $res2 = @ScriptDir & '\my_res.dll' ; vorhandene Dll ausgeschlachtet

    [/autoit] [autoit][/autoit] [autoit]

    $hBmp = _GetImageFromResource('POWER_ON', $res1)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hBmp = ' & $hBmp & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    $hBmp = _GetImageFromResource('POWER_ON', $res2)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hBmp = ' & $hBmp & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    [/autoit] [autoit][/autoit] [autoit]

    #cs
    @@ Debug ($res1): $hBmp = 0
    >Error code: 5 << "SizeofResource" Ermittlung schlägt fehl!!
    @@ Debug ($res2): $hBmp = 0x28051D4D
    >Error code: 0
    #ce

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;#Function# ============================================================================================================================================
    ; Name............: _GetImageFromResource
    ; Description.....: Laden eines Bildes (BMP,GIF,JPG) aus einer Resourcedatei
    ; Syntax..........: _GetImagefromResource($Resname, $Resfile = -1, $ResType = 10)
    ; Parameters......:
    ; $Resname - Name der Resource
    ; $Resfile - Resourcedateiname , wenn leer wird die Autoit Exe Datei verwendet
    ; $ResType - Resourcetype 2= Bitmap, alle anderen = 10. GIF und JPG Dateien müssen als RCDATA gespeichet sein.
    ; Return values .:
    ; Success - Handle des des Bitmaps
    ; Failure - Comming soon
    ; Author ........:
    ; Modified.......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........;
    ; Example .......;
    ; ======================================================================================================================================================
    Func _GetImagefromResource($Resname, $Resfile = -1, $ResType = 10)
    Local Const $IMAGE_BITMAP = 0
    Local $hmod, $hwnd, $InfoBlock, $ResSize, $Mem, $pMem, $dll, $dll2, $hData, $pData, $pStream, $ret, $hBitmap, $pBitmap
    If $Resfile = -1 Then; Resfile = Executable Autoit Exe
    $hmod = _WinAPI_GetModuleHandle("")
    If @error Then Return SetError(1, 0, 0)
    Else
    ;~ $hmod = _WinAPI_LoadLibrary($Resfile)
    $hmod = _WinAPI_LoadLibraryEx($Resfile, 0x00000020) ; $LOAD_LIBRARY_AS_DATAFILE ; ############
    If @error Then Return SetError(2, 0, 0)
    EndIf
    If $ResType =2 Then
    $hBitmap = _WinAPI_LoadImage($hmod, $Resname, $IMAGE_BITMAP, 0, 0, 0)
    If @error Then Return SetError(3, 0, 0)
    If $Resfile <> -1 Then DllCall("Kernel32.dll", "int", "FreeLibrary", "str", $hmod)
    Return $hBitmap
    Else
    $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceW", "int", $hmod, "wstr", $Resname & Chr(0), "long", $ResType) ; ############
    ;~ ConsoleWrite('FindResourceW: ' & $InfoBlock[0] & @LF)
    If @error Then Return SetError(4, 0, 0)
    $InfoBlock = $InfoBlock[0]
    If $InfoBlock = 0 Then Return SetError(5, 0, 0)
    $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "int", $hmod, "int", $InfoBlock)
    If @error Then Return SetError(6, 0, 0)
    $ResSize = $ResSize[0]
    If $ResSize = 0 Then Return SetError(7, 0, 0)
    $Mem = DllCall("kernel32.dll", "int", "LoadResource", "int", $hmod, "int", $InfoBlock)
    If @error Then Return SetError(8, 0, 0)
    $Mem = $Mem[0]
    If $Mem = 0 Then Return SetError(9, 0, 0)
    $pMem = DllCall("kernel32.dll", "int", "LockResource", "int", $Mem)
    If @error Then Return SetError(8, 0, 0)
    $pMem = $pMem[0]
    If $pMem = 0 Then Return SetError(10, 0, 0)
    If $Resfile <> -1 Then DllCall("Kernel32.dll", "int", "FreeLibrary", "str", $hmod)
    $hData = _MemGlobalAlloc($ResSize, 2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($pMem, $pData, $ResSize)
    _MemGlobalUnlock($hData)
    $ret = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "int", $hData, "long", 1, "Int*", 0)
    $pStream = $ret[3]
    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    $dll = DllStructCreate("Uint", $pStream)
    $dll2 = DllStructCreate("uInt", DllStructGetData($dll, 1) + 8)
    DllCall("", "UInt", DllStructGetData($dll2, 1), "UInt", $pStream)
    _WinAPI_DeleteObject($pStream)
    $pStream = 0
    _MemGlobalFree($hData)
    If $Resname <> -1 Then _WinAPI_FreeLibrary($hmod)
    Return $hBitmap
    EndIf
    EndFunc ;==>_GetImagefromResource

    [/autoit]
  • Versuche es doch mal mit einer DllMain, die einfach TRUE zurückgibt. Bei LoadLibrary wird soweit ich weiß die DLLMain aufgerufen.

    Vielleicht wird die DLL dadurch nicht richtig geladen

  • EmptyDllCreator, gab es den nicht schon einmal vor einiger Zeit ? :!:

    [autoit]


    #NoTrayIcon

    [/autoit][autoit][/autoit][autoit]

    Global $bEmptyDll = "0x4D5A80000100000004001000FFFF0000400100000000000040000000000000" & _
    "0000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B" & _
    "409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20" & _
    "444F53206D6F64652E0D0A240000000000000000504500004C010300B170B04D0000000000000" & _
    "000E0000E210B0101450000000000000000000000000000000000100000001000000000400000" & _
    "10000000020000010000000000000004000000000000000010000000020000929700000200400" & _
    "10010000000100000000001000000000000000000100000000010000000000000000000000000" & _
    "00000000000000000000000000000000000000000000000000000010000000000000000000000" & _
    "00000000000000000000000000000000000000000000000000000000000000000000000000000" & _
    "000000000000000000000000000000000000000000000000000000000000000000000000002E7" & _
    "46578740000000000000000100000000000000002000000000000000000000000000020000060" & _
    "2E656461746100000000000000100000000000000002000000000000000000000000000040000" & _
    "0402E72656C6F6300000000000000100000000000000002000000000000000000000000000040" & _
    "00000200000000000000000000000000000000" ;Created with FASM (Flat Assembler)

    [/autoit][autoit][/autoit][autoit]

    Global $hMainGui = GUICreate("EmptyDllCreator", 250, 48)
    Global $hMainCreate = GUICtrlCreateButton("Create empty Dll", 8, 8, 234, 32)
    GUISetState()

    [/autoit][autoit][/autoit][autoit]

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    Case $hMainCreate
    $sSave = FileSaveDialog("EmptyDllCreator", "", "Dynamic Link Libary (*.dll)", 18, "", $hMainGui)
    If @error Then ContinueLoop

    [/autoit][autoit][/autoit][autoit]

    If StringRight($sSave, 4) <> ".dll" Then $sSave &= ".dll"

    [/autoit][autoit][/autoit][autoit]

    $hFile = FileOpen($sSave, 18) ;Binary mode + Write mode (Erease old Content)
    FileWrite($hFile, $bEmptyDll)
    FileClose($hFile)
    Exit
    EndSwitch
    WEnd
    ;Ende

    [/autoit]