找回密码
 加入
搜索
楼主: xunfengcn

[系统综合] AUTOIT能创建建DLL不?

 火... [复制链接]
发表于 2012-5-11 01:06:45 | 显示全部楼层
回复 14# happytc


在没有计算机的年代里,图灵创建了图灵机模型,可以解释这世界上的一切事物,他最早提出了人工智能。后来计算机问世了,运行原理当然也逃不出图灵机模型。在图灵那个年代,他本人不仅探索了计算机能做到的事情,而且也指出了计算机永远也做不到的事情。happytc兄明白我的意思吗?你确定用AU3不能编写出一个 Au3ToAsm函数?反正我目前的水平是编写不出的。

评分

参与人数 1金钱 +10 贡献 +20 收起 理由
tryhi + 10 + 20 很神奇

查看全部评分

发表于 2012-5-11 08:28:30 | 显示全部楼层
回复 18# pusofalse


    呵,P版,我相信若在有au3源码的情况下,再经过大规模改造重写,我们的au3也肯定能直接编译成机器码,VBS不就是这样实现的嘛。外人想搞,就是有这个能力,在没有源码的情况下,也变成不可能的事了。而看官方的态度,特别是Jon的态度,这种要求根本不会考虑的。想au3开源,也不大可能。
发表于 2012-5-11 12:48:16 | 显示全部楼层
二者不同有点了解,但不细
发表于 2012-5-12 07:06:53 | 显示全部楼层
支持一下 谢谢
发表于 2012-5-12 08:58:13 | 显示全部楼层
回复 8# pusofalse


    呵,不过楼主没有说清楚,要创建什么样的DLL
若不是创建au3源代码→DLL的,而是创建如把图片等文件组成的DLL,还是非常容易的
当然创建个只有DLL结构的空DLL也很容易,这些都要不到几行代码就可以写成
发表于 2012-5-12 09:59:14 | 显示全部楼层
回复  pusofalse


    呵,不过楼主没有说清楚,要创建什么样的DLL
若不是创建au3源代码→DLL的,而是 ...
happytc 发表于 2012-5-12 08:58


还请happytc兄科普.多谢
发表于 2012-5-12 19:16:08 | 显示全部楼层
还请happytc兄科普.多谢
3mile 发表于 2012-5-12 09:59



不好意思,今明两天烂事多,很忙。    等我过了这两天有时间了,试着用au3写个创建纯资源的DLL。
发表于 2012-5-12 20:45:49 | 显示全部楼层
回复 25# happytc
翘首以盼,快乐兄尽快啊!
发表于 2012-5-12 22:26:23 | 显示全部楼层
回复 25# happytc
兄台客气了.
即然是请教,哪敢占用happytc兄的时间.
只是完全不懂dll,所以冒失提问,还请理解.
发表于 2012-5-13 00:14:25 | 显示全部楼层
回复 27# 3mile
貌似resource udf可以,不过我没试成功
发表于 2012-5-13 01:19:28 | 显示全部楼层
回复 28# netegg
多谢蛋蛋兄指教,回头我试下.
发表于 2012-5-13 09:09:55 | 显示全部楼层
回复 28# netegg


    快快多试一下,若是别人已经写过可用,我就不用费大脑细胞去重造轮子了
希望蛋兄和三哥测试你们说的那个UDF(我从来没有用过,不知道),在这里给出测试结果,谢谢了
发表于 2012-5-13 11:53:33 | 显示全部楼层
回复 8# pusofalse

估计效率不会太高吧?
求P版来个示例以饱大伙眼福。
自已创建DLL,可能可以解决报毒问题?
发表于 2012-5-13 12:53:29 | 显示全部楼层
本帖最后由 netegg 于 2012-5-13 12:57 编辑

回复 30# happytc
那个resource udf,不是写资源表,是把外部文件整合进最后的exe,不用释放,或者这么说不太对,我用reshacker查了查,rcdata有,但是是个压缩后的资源,打不开
发表于 2012-5-13 16:59:30 | 显示全部楼层
本帖最后由 happytc 于 2012-5-13 17:03 编辑

回复 32# netegg


    呵,本来正准备写一个的
想着30楼说的,于是在官网搜了下,居然很巧的
有个家伙昨天就这个写了个脚本,不会这个老外明白中文,知道我们在讨论这个,于是连夜给我们写了个
下面是官网的链接

http://www.autoitscript.com/forum/topic/140449-createresourcedll/

他的脚本,我直接帖在下面了,英文不好的,就直接用下面的脚本就可以了

#include <WinAPIEx.au3>
#include <Array.au3>
#include <APIConstants.au3>
#include <GDIPlus.au3>
#include <Memory.au3>
#include <StaticConstants.au3>

Global $sDLL = @ScriptDir & "\Resourcen.dll"
Global $sTempFile, $aFiles[1]

Global Const $tagICONDIRENTRY = "BYTE bWidth;BYTE bHeight;BYTE bColorCount;BYTE bReserved;WORD wPlanes;WORD wBitCount;DWORD dwBytesInRes;DWORD dwImageOffset"
Global Const $tagGRPICONDIRENTRY = "BYTE bWidth;BYTE bHeight;BYTE bColorCount;BYTE bReserved;WORD wPlanes;WORD wBitCount;DWORD dwBytesInRes;WORD nID"

Global Const $SS_REALSIZECONTROL = 0x40


While 1
    $sTempFile = FileOpenDialog("Select resource files", @ScriptDir, "All files (*.*)|Icons (*.ico)|Bitmaps (*.bmp)", 3)
    If @error Then ExitLoop
    If $aFiles[0] = "" Then
        $aFiles[0] = $sTempFile
    Else
        _ArrayAdd($aFiles, $sTempFile)
    EndIf
WEnd

_CreateResourceDLL($sDLL, $aFiles)

Global $aIcon = _ArrayFindAll($aFiles, ".ico", 0, 0, 0, 1, 0)
Global $aBitmap = _ArrayFindAll($aFiles, ".bmp", 0, 0, 0, 1, 0)
Global $aJpg = _ArrayFindAll($aFiles, ".jpg", 0, 0, 0, 1, 0)

GUICreate("Resource DLL", 800, 800)

If IsArray($aIcon) Then
    For $i = 0 To UBound($aIcon) - 1
        GUICtrlCreateIcon($sDLL, $aFiles[$aIcon[$i]], 10, 10 + 40 * $i, 32, 32, $SS_SUNKEN)
        GUICtrlCreateLabel($aFiles[$aIcon[$i]], 50, 10 + 40 * $i, 120, 32, $SS_CENTERIMAGE)
    Next
EndIf

If IsArray($aBitmap) Then
    For $i = 0 To UBound($aBitmap) - 1
        GUICtrlCreatePic("", 200, 30 + 120 * $i, 100, 100, BitOR($SS_REALSIZECONTROL, $SS_SUNKEN))
        _SetImagefromResource(-1, $aFiles[$aBitmap[$i]], $sDLL, $RT_BITMAP)
        GUICtrlCreatePic("", 310, 30 + 120 * $i, 100, 100, BitOR($SS_CENTERIMAGE, $SS_SUNKEN))
        _SetImagefromResource(-1, $aFiles[$aBitmap[$i]], $sDLL, $RT_BITMAP)
        GUICtrlCreateLabel($aFiles[$aBitmap[$i]], 200, 10 + 120 * $i, 120, 20, 0x200)
    Next
EndIf

If IsArray($aJpg) Then
    For $i = 0 To UBound($aJpg) - 1
        GUICtrlCreatePic("", 440, 30 + 120 * $i, 100, 100, BitOR($SS_REALSIZECONTROL, $SS_SUNKEN))
        _SetImagefromResource(-1, $aFiles[$aJpg[$i]], $sDLL, $RT_RCDATA)
        GUICtrlCreatePic("", 550, 30 + 120 * $i, 100, 100, BitOR($SS_CENTERIMAGE, $SS_SUNKEN))
        _SetImagefromResource(-1, $aFiles[$aJpg[$i]], $sDLL, $RT_RCDATA)
        GUICtrlCreateLabel($aFiles[$aJpg[$i]], 440, 10 + 120 * $i, 120, 20, 0x200)
    Next
EndIf

GUISetState()

Do
Until GUIGetMsg() = -3


Func _CreateResourceDLL($sDLL, ByRef $aFiles)
    If Not IsArray($aFiles) Or $aFiles[0] = "" Then Return SetError(1, 0, 0)
    _CreateEmptyDLL($sDLL)

    Local $hUpdate = _WinAPI_BeginUpdateResource($sDLL, 0)
    If @error Then Return SetError(2, 0, 0)

    Local $hFile, $bFile, $lFile, $tFile, $pFile, $sName, $sExt, $RT_TYPE, $Resource_ID = 0
    Local $tICONDIR, $tICONDIRENTRY, $tGRPICONDIR, $pGRPICONDIR
    Local $Temp
    Local $nSize

    For $i = 0 To UBound($aFiles) - 1
        If Not FileExists($aFiles[$i]) Then SetError(3, 0, 0)

        $hFile = FileOpen($aFiles[$i], 0)
        $bFile = FileRead($hFile)
        FileClose($hFile)
        $lFile = FileGetSize($aFiles[$i])
        $tFile = DllStructCreate("char[" & $lFile & "]")
        DllStructSetData($tFile, 1, $bFile)
        $pFile = DllStructGetPtr($tFile)
        $sName = StringUpper(StringTrimLeft($aFiles[$i], StringInStr($aFiles[$i], "\", 0, -1)))
        $sExt = StringTrimLeft($aFiles[$i], StringInStr($aFiles[$i], ".", 0, -1))

        $aFiles[$i] = $sName

        Switch $sExt
            Case "bmp"
                $RT_TYPE = $RT_BITMAP
                $lFile = $lFile - 14
                $pFile = Ptr($pFile + 14)

            Case "ico"
                $RT_TYPE = $RT_ICON

                Local $tB_Input_Header = DllStructCreate("short res;short type;short ImageCount;char rest[" & $lFile - 5 & "]", $pFile)
                Local $pB_Input_Header = DllStructGetPtr($tB_Input_Header)

                Local $IconType = DllStructGetData($tB_Input_Header, "Type")
                Local $IconCount = DllStructGetData($tB_Input_Header, "ImageCount")

                Local $tB_IconGroupHeader = DllStructCreate("short Res;short Type;short ImageCount;char Rest[" & $IconCount * 14 & "]")
                Local $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader)

                DllStructSetData($tB_IconGroupHeader, "Res", 0)
                DllStructSetData($tB_IconGroupHeader, "Type", $IconType)
                DllStructSetData($tB_IconGroupHeader, "ImageCount", $IconCount)

                For $X = 1 To $IconCount
                    Local $pB_Input_IconHeader = DllStructGetPtr($tB_Input_Header, 4) + ($X - 1) * 16
                    Local $tB_Input_IconHeader = DllStructCreate($tagICONDIRENTRY, $pB_Input_IconHeader)
                    Local $IconWidth = DllStructGetData($tB_Input_IconHeader, "bWidth")
                    Local $IconHeigth = DllStructGetData($tB_Input_IconHeader, "bHeight")
                    Local $IconColors = DllStructGetData($tB_Input_IconHeader, "bColorCount")
                    Local $IconPlanes = DllStructGetData($tB_Input_IconHeader, "wPlanes")
                    Local $IconBitPerPixel = DllStructGetData($tB_Input_IconHeader, "wBitCount")
                    Local $IconImageSize = DllStructGetData($tB_Input_IconHeader, "dwBytesInRes")
                    Local $IconImageOffset = DllStructGetData($tB_Input_IconHeader, "dwImageOffset")

                    $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader, 4) + ($X - 1) * 14
                    Local $tB_GroupIcon = DllStructCreate($tagGRPICONDIRENTRY, $pB_IconGroupHeader)
                    DllStructSetData($tB_GroupIcon, "bWidth", $IconWidth)
                    DllStructSetData($tB_GroupIcon, "bHeigth", $IconHeigth)
                    DllStructSetData($tB_GroupIcon, "bColorCount", $IconColors)
                    DllStructSetData($tB_GroupIcon, "bReserved", 0)
                    DllStructSetData($tB_GroupIcon, "wPlanes", $IconPlanes)
                    DllStructSetData($tB_GroupIcon, "wBitCount", $IconBitPerPixel)
                    DllStructSetData($tB_GroupIcon, "dwBytesInRes", $IconImageSize)
                    $Resource_ID += 1
                    DllStructSetData($tB_GroupIcon, "nID", $Resource_ID)
                    Local $PB_IconData = DllStructGetPtr($tB_Input_Header) + $IconImageOffset
                    _WinAPI_UpdateResource($hUpdate, $RT_TYPE, $Resource_ID, Int("0x" & @OSLang), $PB_IconData, $IconImageSize)
                Next

                $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader)

            Case "jpg", "jpeg", "gif"
                $RT_TYPE = $RT_RCDATA

;~          Case "cur"
;~              $RT_TYPE = $RT_CURSOR
;~          Case "txt", "au3", "ini", "c", "cpp", "h"
;~              $RT_TYPE = $RT_STRING

            Case Else
                ContinueLoop
        EndSwitch

        If $RT_TYPE = $RT_ICON Then
            _WinAPI_UpdateResource($hUpdate, $RT_GROUP_ICON, $sName, Int("0x" & @OSLang), $pB_IconGroupHeader, DllStructGetSize($tB_IconGroupHeader))
        Else
            $Resource_ID += 1
            _WinAPI_UpdateResource($hUpdate, $RT_TYPE, $sName, Int("0x" & @OSLang), $pFile, $lFile)
        EndIf
;~      If @error Then SetError(4, $i, 0)
        $tFile = 0
    Next

    _WinAPI_EndUpdateResource($hUpdate)
    If @error Then Return SetError(5, @extended)
    Return 1
EndFunc   ;==>_CreateResourceDLL

Func _CreateEmptyDLL($sFilePath)
    Local $bEmptyDll = _Empty_DLL()
    Local $hFile = FileOpen($sFilePath, 18) ;Binary mode + Write mode (Erase old content!)
    FileWrite($hFile, $bEmptyDll)
    FileClose($hFile)
EndFunc   ;==>_CreateEmptyDLL

Func _Empty_DLL()
    Local $Empty_DLL
    $Empty_DLL &= 'TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAEFAP6WNU0AAAAAAAAAAOAADiELAQIyAAQAAAAGAAAAAAAAABAAAAAQAAAAMAAAAAAAEAAQAAAAAgAABAAAAAAAAAAEAAAAAAAAAABgAAAABAAAAAAAAAMAAAAAABAAABAAAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAAAAAwAAA8AAAAAFAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAC'
    $Empty_DLL &= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABUMAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC5jb2RlAAAAYwAAAAAQAAAAAgAAAAQAAAAAAAAAAAAAAAAAACAAAGAudGV4dAAAABgAAAAAIAAAAAIAAAAGAAAAAAAAAAAAAAAAAAAgAABgLmRhdGEAAADMAAAAADAAAAACAAAACAAAAAAAAAAAAAAAAAAAQAAAwC5yZWxvYwAAIAAAAABAAAAAAgAAAAoAAAAAAAAAAAAAAAAAAEAAAEIucnNyYwAAABAAAAAAUAAAAAIAAAAMAAAAAAAAAAAAAAAAAABAAAB'
    $Empty_DLL &= StringRepeat("A", 598) & 'IN8JAgBdQ6LRCQEo8QwABDoIgAAAIN8JAgCdQCDfCQIAHUF6CkAAACDfCQIA3UAuAEAAADCDABoAAAAAGgAEAAAaAAAAADouw8AAKPAMAAQw+gMAAAA/zXAMAAQ6KsPAADDww'
    $Empty_DLL &= StringRepeat("A", 550) & '/yVUMAAQ/yVcMAAQ/yVgMAAQ/yVkMAAQ'
    $Empty_DLL &= StringRepeat("A", 651)
    $Empty_DLL &= '8MAAAAAAAAAAAAAB2MAAAVDAAAEQwAAAAAAAAAAAAALIwAABcMAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsMAAAAAAAAIIwAACQMAAAnjAAAAAAAABsMAAAAAAAAIIwAACQMAAAnjAAAAAAAACZAm1lbXNldAAATVNWQ1JULmRsbAAApAJIZWFwQ3JlYXRlAAClAkhlYXBEZXN0cm95APoBR2V0TW9kdWxlSGFuZGxlVwAAS0VSTkVMMzIuZGxs'
    $Empty_DLL &= StringRepeat("A", 431) & 'QAAAQAAAADDBMMFgwAAAAIAAAEAAAAAIwCDAOMBQw'
    $Empty_DLL &= StringRepeat("A", 645) & 'BSXNk0DAAc'
    $Empty_DLL &= StringRepeat("A", 668) & '='
    Return Binary(_Base64Decode($Empty_DLL))
EndFunc   ;==>_Empty_DLL

Func _Base64Decode($input_string)
    Local $struct = DllStructCreate("int")
    Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(1, 0, "")
    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Decode

Func StringRepeat($sChar, $nCount)
    $tBuffer = DllStructCreate("char[" & $nCount + 1 & "]")
    DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DllStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount)
    Return DllStructGetData($tBuffer, 1)
EndFunc   ;==>StringRepeat

Func _SetImagefromResource($CtrlID, $Resname, $Resfile = -1, $ResType = 10)
    ;Raupi
    ;Diese Funktion basiert auf der UDF von Zedna@Autitscript.com und Code von Progandy@AutoIt.de
    Local Const $IMAGE_BITMAP = 0
    Local Const $STM_SETIMAGE = 0x0172
    Local $hmod, $hwnd, $InfoBlock, $ResSize, $Mem, $pMem, $dll, $dll2, $hData, $pData, $pStream, $ret, $hBitmap, $pBitmap
    If $Resfile = -1 Then
        $hmod = _WinAPI_GetModuleHandle("")
    Else
        $hmod = _WinAPI_LoadLibrary($Resfile)
    EndIf
    If $ResType = $RT_BITMAP Then
        $hBitmap = _WinAPI_LoadImage($hmod, $Resname, $IMAGE_BITMAP, 0, 0, 0)
        If @error Then Return SetError(1, 0, 0)
        $hwnd = GUICtrlGetHandle($CtrlID)
        If $hwnd = 0 Then Return SetError(2, 0, 0)
        DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hwnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
        If @error Then Return SetError(3, 0, 0)
    Else
        $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceA", "int", $hmod, "str", $Resname, "long", $ResType)
        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)
        $hwnd = GUICtrlGetHandle($CtrlID)
        If $hwnd = 0 Then Return SetError(11, 0, 0)
        DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hwnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
        If @error Then Return SetError(12, 0, 0)
        _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 $Resfile <> -1 Then _WinAPI_FreeLibrary($hmod)
    EndIf
EndFunc   ;==>_SetImagefromResource
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-28 19:37 , Processed in 0.107275 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表