Sign in to follow this  
Followers 0
John

Dll compiler in AutoIt

2 posts in this topic

Actually a very very basic resource compiler written with AutoIt. It's limited to one resource, just a proof of concept compiler. I also cheated and padded the template, hence the input limits. I'm considering writing a full resource compiler that doesn't cheat with padding and supports multiple resources (maybe too much work). I messed up the version info a little but few will notice. You shouldn't be able to trick it into making an invalid resource file anyway. If you want more use RC.exe or check out Zedna's link:

http://www.autoitscript.com/forum/index.ph...=51103&st=0

Posted Image

The "Script File" label is clickable and opens a file open dialog. It take that script (java, html, pic, etc) and compiles it into a newly created resource dll in the same directory as the AutoRC script. Once created the bottom field "Resource URL" becomes visible and you can click that label to open the URL. The labels have descriptive ToolTips.

If the code is hard to read sorry, I don't use include files of ANY kind. Runs 'as is' in the latest AutoIt and beta. I can think of better ways to handle the code but the concept is limitless.

Opt("MustDeclareVars",1)
Opt("GUIOnEventMode",1)
#Region GUI
Dim $URL
Dim $GUI=GUICreate("AutoRC",500,245,-1,-1,0x80C70000)
GUISetBkColor(0x999999)

GUICtrlCreateLabel("Script File",0,0,125,20,4097)
GUICtrlSetTip(-1,"Selects the html, java, etc. script file you want to compile.","Click here to open a file.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
GUICtrlSetOnEvent(-1,"Fopen")
Dim $Script=GUICtrlCreateInput("D:\Windows\Desktop\AutoItDLL\script.js",125,0,374,20)

GUICtrlCreateLabel("Resource Name",0,20,125,20,4097)
GUICtrlSetTip(-1,"Name your resource.","Limit: 20 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $ResName=GUICtrlCreateInput("RES",125,20,374,20,0x0008)

GUICtrlCreateLabel("File Name",0,40,125,20,4097)
GUICtrlSetTip(-1,"Enter a name for your file with extension."&@CRLF&"No path, creates in the script directory.","Limit: 30 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $Filename=GUICtrlCreateInput("Script.dll",125,40,374,20)

GUICtrlCreateLabel("Company Name",0,60,125,20,4097)
GUICtrlSetTip (-1,"Enter your company name.","Limit: 30 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont (-1,10,600)
Dim $Company=GUICtrlCreateInput("Dead Dog Productions.",125,60,374,20)

GUICtrlCreateLabel("Description",0,80,125,20,4097)
GUICtrlSetTip(-1,"Enter a description.","Limit: 50 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $Description=GUICtrlCreateInput("AutoIt resource compiler.",125,80,374,20)

GUICtrlCreateLabel("File Version",0,100,125,20,4097)
GUICtrlSetTip(-1,"Enter the file version.","Limit: 12 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $FileVersion=GUICtrlCreateInput("1,0,0,0",125,100,374,20)

GUICtrlCreateLabel("Copyright",0,120,125,20,4097)
GUICtrlSetTip(-1,"Copyright.","Limit: 30 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $Copyright=GUICtrlCreateInput("Dead Dog Productions.",125,120,374,20)

GUICtrlCreateLabel("Product Name",0,140,125,20,4097)
GUICtrlSetTip(-1,"Enter the product Name.","Limit: 30 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $ProductName=GUICtrlCreateInput("AutoIt resource dll.",125,140,374,20)

GUICtrlCreateLabel("Product Version",0,160,125,20,4097)
GUICtrlSetTip(-1,"Enter the product version.","Limit: 12 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $ProductVersion=GUICtrlCreateInput("1,0,0,0",125,160,374,20)

GUICtrlCreateLabel("Comments",0,180,125,20,4097)
GUICtrlSetTip(-1,"Comments.","Limit: 75 Characters.")
GUICtrlSetResizing(-1,512)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetColor(-1,0x00FF00)
GUICtrlSetFont(-1,10,600)
Dim $Comments=GUICtrlCreateInput("If it blows up your computer and kills your dog don't come crying to me.",125,180,374,20)

GUICtrlCreateButton("Compile",210,200,80,25,0x8000)
GUICtrlSetOnEvent(-1,"Go")
GUISetOnEvent(-3,"Xit",$GUI)
GUISetState(@SW_SHOW,$GUI)

Sleep(3600000); Should have an infinite option Sleep() for GUIOnEventMode=1.

#endregion GUI

Func Go()
    Local $Res,$Sc,$Sl,$Rns,$Rn,$Rl,$Fn,$Dn,$Cp,$Ds,$Fvs,$Fv,$Cr,$Pn,$Pvs,$Pv,$Cm
        $Sc=FileRead(GUICtrlRead($Script))
        $Sc=HexIt($Sc,2,0,0)
        $Sl=HexIt($Sc,2,0,1); $Script length
        $Rns=GUICtrlRead($ResName)
        $Rl=HexIt($Rns,4,1,1); $Resource name length
        $Rn=HexIt($Rns,4,20,0)
        If @error Then Return
        $Dn=GUICtrlRead($Filename); Two copies here (ASCII)
        $Fn=HexIt($Dn,4,30,0)   ;and here (Hex)
        If @error Then Return
        $Cp=HexIt(GUICtrlRead($Company),4,30,0)
        If @error Then Return
        $Ds=HexIt(GUICtrlRead($Description),4,50,0)
        If @error Then Return
        $Cr=HexIt(GUICtrlRead($Copyright),4,30,0)
        If @error Then Return
        $Pn=HexIt(GUICtrlRead($ProductName),4,30,0)
        If @error Then Return
        $Cm=HexIt(GUICtrlRead($Comments),4,75,0)
        If @error Then Return
        $Fvs=GUICtrlRead($FileVersion)
        $Pvs=GUICtrlRead($ProductVersion)
        If $Fvs="" Then $Fvs="1,0,0,0"
        If $Pvs="" Then $Pvs="1,0,0,0"
    If Not StringInStr($Fvs,",",0,3) Or StringLen($Fvs)>12 Then
        msg("Badly formatted or limit exceeded file version. Use commas, limit 12 charcters."&$Fvs)
        Return
    EndIf
    If Not StringInStr($Pvs,",",0,3) Then
        msg("Badly formatted Product Version. Use commas, limit 12 charcters."&$Pvs)
        Return
    EndIf
        $Fv=StringSplit($Fvs,",")
        $Pv=StringSplit($Fvs,",")
    For $i=1 To 4
        $Fv[$i]=Hex($Fv[$i],4)
        $Fv[$i]=StringRight($Fv[$i],2)&StringLeft($Fv[$i],2)
    Next
        $Fv=$Fv[2]&$Fv[1]&$Fv[4]&$Fv[3]
    For $i=1 To 4
        $Pv[$i]=Hex($Pv[$i],4)
        $Pv[$i]=StringRight($Pv[$i],2)&StringLeft($Pv[$i],2)
    Next
        $Pv=$Pv[2]&$Pv[1]&$Pv[4]&$Pv[3]
        $Fvs=HexIt(StringReplace($Fvs,",","."),4,12,0)
        If @error Then Return
        $Pvs=HexIt($Pvs=StringReplace($Pvs,",","."),4,12,0)
        If @error Then Return
    FileDelete(@ScriptDir&"\"&$Dn)
$Res="0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000"
$Res&="000000000000000000000000000000000000000000000000000000000B00000"
$Res&="000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6"
$Res&="E6F742062652072756E20696E20444F53206D6F64652E0D0D0A240000000000"
$Res&="0000F92D54D9BD4C3A8ABD4C3A8ABD4C3A8A9A8A468ABC4C3A8A9A8A428ABC4"
$Res&="C3A8A52696368BD4C3A8A0000000000000000504500004C01020077AF334300"
$Res&="00000000000000E00002210B010800000000000008000000000000000000000"
$Res&="010000000100000000044630010000000020000050000000800000004000A00"
$Res&="000000000030000000020000E17E00000300000400001000001000000000100"
$Res&="000100000000000001000000000000000000000000000000000000000001000"
$Res&="005705000000000000000000000000000000000000002000000800000000000"
$Res&="000000000000000000000000000000000000000000000000000000000000000"
$Res&="000000000000000000000000000000000000000000000000000000000000000"
$Res&="000000000000000000000000000002E72737263000000570500000010000000"
$Res&="06000000020000000000000000000000000000400000402E72656C6F6300000"
$Res&="800000000200000000200000008000000000000000000000000000040000042"
$Res&="000000000000000000000000000000000000000000000200100000002000008"
$Res&="017000000380000800000000000000000000000000000010001000000500000"
$Res&="8000000000000000000000000001000000A0000080680000800000000000000"
$Res&="000000000000000010009040000800000000000000000000000000000000000"
$Res&="01000904000090000000CC10000088040000000000000000000054150000"
$Res&=$Sl&"00000000000000000000"&$Rl&$Rn
$Res&="0000880434000000560053005F00560045005200530049004F004E005F004900"
$Res&="4E0046004F0000003400BD04EFFE00000100"&$Fv&$Pv
$Res&="3F000000000000000400000002000000000000000000000000000000E8030000"
$Res&="000053007400720069006E006700460069006C00650049006E0066006F000000"
$Res&="C4030000000030003400300039003000340042003000000060003E0001004300"
$Res&="6F006D00700061006E0079004E0061006D00650000000000"&$Cp
$Res&="00000000900066000100460069006C0065004400650073006300720069007000"
$Res&="740069006F006E0000000000"&$Ds
$Res&="000000003C001A000100460069006C006500560065007200730069006F006E00"
$Res&="00000000"&$Fvs
$Res&="0000000060003E00010049006E007400650072006E0061006C004E0061006D00"
$Res&="65000000"&$Fn
$Res&="000000006800420001004C006500670061006C0043006F007000790072006900"
$Res&="6700680074000000A9002000"&$Cr
$Res&="0000000068003E0001004F0072006900670069006E0061006C00460069006C00"
$Res&="65006E0061006D0065000000"&$Fn
$Res&="0000000060003E000100500072006F0064007500630074004E0061006D006500"
$Res&="00000000"&$Pn
$Res&="0000000040001A000100500072006F0064007500630074005600650072007300"
$Res&="69006F006E000000"&$Pvs
$Res&="00000000B0009800010043006F006D006D0065006E00740073000000"&$Cm
$Res&="0000440000000000560061007200460069006C00650049006E0066006F000000"
$Res&="00002400040000005400720061006E0073006C006100740069006F006E000000"
$Res&="00000904B004"&$Sc
$Res=FileWrite(@ScriptDir&"\"&$Dn,Binary($Res))
If $Res Then
    GUICtrlCreateLabel("Resource URL",0,225,125,20,4097)
    GUICtrlSetTip(-1,"The URL of your compiled resource.","Click to open:")
    GUICtrlSetOnEvent(-1,"Nav")
    GUICtrlSetResizing(-1,512)
    GUICtrlSetBkColor(-1,0x000000)
    GUICtrlSetColor(-1,0x00FF00)
    GUICtrlSetFont(-1,10,600)
    $URL=GUICtrlCreateInput("res://"&@ScriptDir&"\"&$Dn&"/"&$Rns,125,225,374,20)
    GUISetState(@SW_SHOW,$GUI)
Else
    msg("Failed to compile "&$Dn&". Unknown error."
EndIf
EndFunc

Func HexIt($str,$x,$y,$z)
; $x sets/gets 2 or 4 bit encoding (input resource length {$z>1} and return in string {$z>0}.
; $y designates Hex string return length if {$z=0}.
; $z Resource length type {$z=0} or Hex string type {$z=1}
    Local $H,$Hs,$Ar;Hex character, hex string, and array
    If $z Then
        If $x=2 Then $str=StringLen($str)/2
        If $x=4 Then $str=Hex(StringLen($str),4)
        $str=Hex($str,4)
        $str=StringRight($str,2)&StringLeft($str,2)
        Return $str
    EndIf
    If $y>0 And StringLen($str)>$y Then
        msg('Character limit exceeded - "'&$str&'".')
        SetError(1)
        Return @error
    EndIf
        $str=StringSplit($str,"")
    For $i=1 To $str[0]
        $H=Hex(Asc($str[$i]),$x)
        If $x=4 Then $H=StringRight($H,2)&StringLeft($H,2)
        $Hs&=$H
    Next
        If $x=2 And Mod(StringLen($Hs)/2,2)<>0 Then $Hs&="00"
        $y=$y*4
    While StringLen($Hs)<$y
        $Hs&="0000"
    WEnd
    Return $Hs
EndFunc

Func Xit()
    Exit
EndFunc

Func Fopen()
    Local $re=FileOpenDialog("Select Script",@ScriptDir,"All (*.*)",3)
    If @error Then Return
    GUICtrlSetData($Script,$re)
EndFunc

Func Nav()
    ShellExecute(GUICtrlRead($URL))
EndFunc

Func msg($x)
    MsgBox(48,"Error! Try again.",$x)
EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0