#Region ;**** Directives created by AutoIt3Wrapper_GUI ***** #AutoIt3Wrapper_Icon=AutoIt3Wrapper.ico #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Res_Comment=Compile,Run,Check,Tidy or Strip your AutoIt3 script including options to update the resource information. #AutoIt3Wrapper_Res_Description=Compile,Run,Check,Tidy or Strip your AutoIt3 script including options to update the resource information. #AutoIt3Wrapper_Res_Fileversion=15.503.1200.2 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2014 Jos van der Zande #AutoIt3Wrapper_Res_Field=Made By|Jos van der Zande #AutoIt3Wrapper_Res_Field=Email|jdeb at autoitscript dot com #AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% #AutoIt3Wrapper_Res_Field=Compile Date|%date% %time% #AutoIt3Wrapper_Res_Field=Productname|AutoIt3Wrapper for AutoIt3 scripts #AutoIt3Wrapper_Res_ProductVersion=2.2 #AutoIt3Wrapper_Res_Field=CompanyName|Jos van der Zande #AutoIt3Wrapper_Res_Field=Credits|wraithdu - Updating the Resource UDFs allowing other sections to be included. #AutoIt3Wrapper_Res_Field=Credits|jchd - Added support for UTF files. #AutoIt3Wrapper_Au3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_Au3Check=y #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_Run_After=copy "%in%" "..\..\Programs_Updates\AutoIt3Wrapper" #AutoIt3Wrapper_Run_After=copy "%out%" "..\..\Programs_Updates\AutoIt3Wrapper" #AutoIt3Wrapper_Run_After=copy "directives.au3" "..\..\Programs_Updates\AutoIt3Wrapper" #AutoIt3Wrapper_Run_After=aaCopy2Prod.exe "%scriptfile%" "AutoIt3Wrapper" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper" "%in%" %fileversion% %fileversionnew% #AutoIt3Wrapper_Run_Au3Stripper=y ;~ #Au3Stripper_Parameters=/debug #AutoIt3Wrapper_Versioning=v #AutoIt3Wrapper_Versioning_Parameters=/Comments %fileversion% #AutoIt3Wrapper_ShowProgress=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ***** ;Regions -> "AutoIt General Settings & Includes" and "Declare variables" coming from AutoIt3Wrapper #Region AutoIt General Settings & Includes ;~ #Tidy_Parameters=/gen_doc #Tidy_Parameters=/sort_funcs /reel #include #include #include #include #include #include #include #include #include #include #include ; ; get program version for display purpose Global $VERSION = FileGetVersion(@ScriptFullPath) ;~ $VERSION = StringLeft($VERSION, StringInStr($VERSION, ".", 0, -1) - 1) OnAutoItExitRegister("OnAutoItExit") #Region SciTE Director Init ; Try to update the file directly in SciTE in stead of externally by means of the Director interface. Opt("WinSearchChildren", 1) Global $SciTECmd Global $SciTE_hwnd = WinGetHandle("DirectorExtension") ; Get My GUI Handle numeric Global $My_Hwnd = GUICreate("SciTE interface", 300, 600, Default, Default, Default, $WS_EX_TOPMOST) Global $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) Global $SciTE_Dir = _PathFull(@ScriptDir & "..\..") ;Register COPYDATA message. GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA") ; Get SciTE prograqm directory If Not FileExists($SciTE_Dir & "\SciTE.exe") Then $SciTE_Dir = StringReplace(SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd, "askproperty:SciteDefaultHome"), "\\", "\") ; When it stilll isn't found it is assumed that the path to the editor it one higher than the AutoIt3Wrapper script directory If Not FileExists($SciTE_Dir) Then $SciTE_Dir = _PathFull(@ScriptDir & "..\..") EndIf EndIf #EndRegion SciTE Director Init ; Only show general info for the main script If Not StringInStr($CMDLINERAW, "/watcher") _ And Not StringInStr($CMDLINERAW, "/au3record") _ And Not StringInStr($CMDLINERAW, "/au3info") _ And Not StringInStr($CMDLINERAW, "/Jump2FirstError") _ Then AutoItWinSetTitle("AutoIt3Compiler_Main") ConsoleWrite("+>" & @HOUR & ":" & @MIN & ":" & @SEC & " Starting AutoIt3Wrapper v." & $VERSION) If FileExists($SciTE_Dir & "\SciTE.exe") Then ConsoleWrite(' SciTE v.' & FileGetVersion($SciTE_Dir & "\SciTE.exe") & " ") ConsoleWrite(" Keyboard:" & @KBLayout & " OS:" & @OSVersion & "/" & @OSServicePack & " CPU:" & @CPUArch & " OS:" & @OSArch) ConsoleWrite(' Environment(Language:' & @OSLang) ConsoleWrite(")" & @CRLF) EndIf ; Use Appdata @LocalAppDataDir & "\AutoIt v3\SciTE\Au3toIt3Wrapper" Global $UserData Global $AutoIt3WapperIni ; Check for SCITE_USERHOME Env variable and used that when specified. ; Else use Program directory If EnvGet("SCITE_USERHOME") <> "" And FileExists(EnvGet("SCITE_USERHOME") & "\AutoIt3Wrapper") Then $AutoIt3WapperIni = EnvGet("SCITE_USERHOME") & "\AutoIt3Wrapper\AutoIt3Wrapper.ini" $UserData = EnvGet("SCITE_USERHOME") & "\AutoIt3Wrapper" ElseIf EnvGet("SCITE_HOME") <> "" And FileExists(EnvGet("SCITE_HOME") & "\AutoIt3Wrapper") Then $AutoIt3WapperIni = EnvGet("SCITE_HOME") & "\AutoIt3Wrapper\AutoIt3Wrapper.ini" $UserData = EnvGet("SCITE_HOME") & "\AutoIt3Wrapper" Else $AutoIt3WapperIni = @ScriptDir & "\AutoIt3Wrapper.ini" $UserData = @ScriptDir EndIf ; Only display in case None of these tools are started If Not StringInStr($CMDLINERAW, "/watcher") _ And Not StringInStr($CMDLINERAW, "/au3record") _ And Not StringInStr($CMDLINERAW, "/au3info") _ And Not StringInStr($CMDLINERAW, "/Jump2FirstError") _ Then ConsoleWrite("+> SciTEDir => " & $SciTE_Dir) ConsoleWrite(" UserDir => " & $UserData) If EnvGet("SCITE_HOME") <> "" Then ConsoleWrite(' SCITE_HOME => ' & EnvGet("SCITE_HOME") & " ") If EnvGet("SCITE_USERHOME") <> "" Then ConsoleWrite(' SCITE_USERHOME => ' & EnvGet("SCITE_USERHOME") & " ") ConsoleWrite("" & @CRLF) EndIf #EndRegion AutoIt General Settings & Includes #Region Declare variables Global $ShowGUI = 0 ; ; RESOURCE CONSTANTS ; Global Const $IMAGE_DOS_SIGNATURE = 0x5A4D Global Const $tagIMAGE_SECTION_HEADER = _ "byte Name[8];" & _ "dword Misc;" & _ "dword VirtualAddress;" & _ "dword SizeOfRawData;" & _ "dword PointerToRawData;" & _ "dword PointerToRelocations;" & _ "dword PointerToLinenumber;" & _ "ushort NumberOfRelocations;" & _ "ushort NumberOfLinenumbers;" & _ "dword Characteristics" Global Const $tagIMAGE_DOS_HEADER = _ "ushort emagic;" & _ "ushort ecblp;" & _ "ushort ecp;" & _ "ushort ecrlc;" & _ "ushort ecparhdr;" & _ "ushort eminalloc;" & _ "ushort emaxalloc;" & _ "ushort ess;" & _ "ushort esp;" & _ "ushort ecsum;" & _ "ushort eip;" & _ "ushort ecs;" & _ "ushort elfarlc;" & _ "ushort eovno;" & _ "ushort eres[4];" & _ "ushort eoemid;" & _ "ushort eoeminfo;" & _ "ushort eres2[10];" & _ "long elfanew" Global Const $tagIMAGE_FILE_HEADER = _ "ushort Machine;" & _ "ushort NumberOfSections;" & _ "dword TimeDateStamp;" & _ "dword PointerToSymbolTable;" & _ "dword NumberOfSymbols;" & _ "ushort SizeOfOptionalHeader;" & _ "ushort Characteristics" Global $tagTEMP = _ "ushort Magic;" & _ ; Standard fields "byte MajorLinkerVersion;" & _ "byte MinorLinkerVersion;" & _ "dword SizeOfCode;" & _ "dword SizeOfInitializedData;" & _ "dword SizeOfUninitializedData;" & _ "dword AddressOfEntryPoint;" & _ "dword BaseOfCode;" & _ "dword BaseOfData;" & _ "dword ImageBase;" & _ ; NT additional fields "dword SectionAlignment;" & _ "dword FileAlignment;" & _ "ushort MajorOperatingSystemVersion;" & _ "ushort MinorOperatingSystemVersion;" & _ "ushort MajorImageVersion;" & _ "ushort MinorImageVersion;" & _ "ushort MajorSubsystemVersion;" & _ "ushort MinorSubsystemVersion;" & _ "dword Win32VersionValue;" & _ "dword SizeOfImage;" & _ "dword SizeOfHeaders;" & _ "dword CheckSum;" & _ "ushort Subsystem;" & _ "ushort DllCharacteristics;" & _ "dword SizeOfStackReserve;" & _ "dword SizeOfStackCommit;" & _ "dword SizeOfHeapReserve;" & _ "dword SizeOfHeapCommit;" & _ "dword LoaderFlags;" & _ "dword NumberOfRvaAndSizes" ; assign indexes to each IMAGE_DATA_DIRECTORY struct so we can find them later For $i = 0 To 15 $tagTEMP &= ";ulong VirtualAddress" & $i & ";ulong Size" & $i Next Global Const $tagIMAGE_OPTIONAL_HEADER = $tagTEMP $tagTEMP = 0 Global Const $tagIMAGE_NT_HEADERS = _ "dword Signature;" & _ $tagIMAGE_FILE_HEADER & ";" & _ ; offset = 4 $tagIMAGE_OPTIONAL_HEADER ; offset = 24 Global $g_aResNamesAndLangs[1][2] = [[0, 0]] ; reset array Global $rh, $hLangCallback Global $aVersionInfo, $aManifestInfo, $aTemp Global $IconFileInfo Global $ScriptFile_In = "", $ScriptFile_In_Ext = "", $ScriptFile_In_stripped = "", $ScriptFile_Out = "", $ScriptFile_Out_x86 = "", $ScriptFile_Out_x64 = "", $ScriptFile_Out_Type = "" Global $INP_Compile_Both = 0 Global $INP_Icon = "", $INP_Compression = "", $INP_AutoIt3_Version = "" Global $AutoIt3_PGM = "", $AUT2EXE_PGM = "", $INP_AutoItDir = "" Global $Pragma_Used = 0 Global $Pragma_Out = "", $Pragma_Icon = "n", $Pragma_RES_requestedExecutionLevel = "", $Pragma_UseUpx = "", $Pragma_Change2CUI = "", $Pragma_Compression = "", $Pragma_RES_Compatibility = "" Global $Pragma_Out_x64 = "", $Pragma_Comment = "", $Pragma_Company = "", $Pragma_Description = "", $Pragma_Fileversion = "", $Pragma_InternalName = "", $Pragma_LegalCopyright = "", $Pragma_LegalTradeMarks = "" Global $Pragma_Productname = "", $Pragma_ProductVersion = "" Global $INP_Run_Debug_Mode = 0, $INP_UseUpx = "", $INP_Upx_Parameters = "", $INP_UseAnsi = "n", $INP_UseX64 = "", $INP_Comment = "", $INP_Description = "", $INP_Res_SaveSource = "" Global $INP_Res_Language = "", $INP_Res_requestedExecutionLevel = "", $INP_RES_HiDpi = "", $INP_Res_Compatibility = "", $INP_Fileversion = "", $INP_Fileversion_New = "", $INP_Fileversion_AutoIncrement = "", $INP_Fileversion_First_Increment = "", $INP_LegalCopyright = "" Global $INP_ProductVersion = "", $INP_CompiledScript = "", $INP_FieldName1 = "", $INP_FieldValue1 = "", $INP_FieldName2 = "", $INP_FieldValue2 = "", $INP_Res_FieldCount = 0, $INP_FieldName[16] Global $INP_FieldValue[16], $INP_Run_Tidy = "", $INP_Run_Au3Stripper = "", $INP_Tidy_Stop_OnError = "Y", $INP_Run_AU3Check = "", $INP_Jump_To_First_Error = "Y", $INP_Add_Constants = "", $INP_Run_SciTE_Minimized = "n", $INP_Run_SciTE_OutputPane_Minimized = "n" Global $INP_AU3Check_Stop_OnWarning, $INP_AU3Check_Parameters, $INP_Run_Before[2], $INP_Run_After[2], $INP_Run_Before_Admin[2], $INP_Run_After_Admin[2], $INP_Run_Versioning, $INP_Versioning_Parameters Global $INP_Plugin, $INP_Change2CUI, $INP_Icons[1], $INP_Icons_cnt = 0, $INP_Res_Files[1], $INP_Res_Files_Cnt = 0, $TempFile, $TempFile2, $TempDir Global $INP_Au3check_Plugin, $INP_Tidy_Parameters = "", $INP_Au3Stripper_Parameters = "", $INP_AutoIt3Wrapper_LogFile = "", $INP_AutoIt3Wrapper_If = "", $INP_AutoIt3Wrapper_Testing = "N" Global $INP_Run_PreExpand = "N" Global $INP_ShowStatus = "" Global $ScriptFile_In_Org Global $H_Resource, $H_Comment, $H_Description, $H_Fileversion, $H_Fileversion_AutoIncrement_n, $H_Fileversion_AutoIncrement_p, $H_Fileversion_AutoIncrement_y Global $H_LegalCopyright, $H_FieldNameEdit, $H_Res_Language Global $IconResBase = 49 Global $Au3StripperCmdLine Global $DebugIcon = "" Global $Parameter_Mode = 0 Global $Debug = 0 Global $Registry = "HKCU\Software\AutoIt v3" Global $RegistryLM = "HKLM\Software\AutoIt v3\AutoIt" Global $Option = "Compile" Global $s_CMDLine = "" Global $ToTalFile Global $H_Outf Global $CurSciTEFile, $CurSciTELine, $FindVer, $CurSelection Global $dummy, $V_Arg, $T_Var, $H_Cmp, $H_au3, $rc, $Save_Workdir, $AUT2EXE_DIR, $AUT2EXE_PGM_N, $msg, $AUT2EXE_PGM_VER Global $LSCRIPTDIR, $AutoIt_Icon, $INP_Icon_Temp, $AutoIt_Icon_Dir Global $InputFileIsUTF8 = 0 Global $InputFileIsUTF16 = 0 Global $InputFileIsUTF32 = 0 Global $ProcessBar_Title Global $Pid, $Handle, $Return_Text, $ExitCode Global $sCmd Global $SrceUnicodeFlag, $UTFtype Global $Found_Old_ObfuscatorDirective = 0 ; Global $CurrentAutoIt_InstallDir = _PathFull(@ScriptDir & "..\..\..") If StringLeft($SciTE_Dir, 3) = "\\\" Then $SciTE_Dir = StringMid($SciTE_Dir, 2) If StringLeft($CurrentAutoIt_InstallDir, 3) = "\\\" Then $CurrentAutoIt_InstallDir = StringMid($CurrentAutoIt_InstallDir, 2) ;~ If StringInStr($SciTE_Dir, "\", '', -1) > 0 Then $SciTE_Dir = StringLeft($SciTE_Dir, StringInStr($SciTE_Dir, "\", '', -1) - 1) ; #EndRegion Declare variables #Region Input retrieval/validation ;some operations here...-> ;------------------------------------------------------------------------------------------- ; Get Predefined settings from the Scriptfile itself. These will override all other settings Retrieve_PreProcessor_Info() ;A bunch of $variable are modified in Wrapper's Global scope. ;last operations here...-> #EndRegion Input retrieval/validation #Region Functions ;last Func/EndFunc....-> ;some Func/EndFunc....-> ; ; Update Variables in a string. Func Convert_Variables($I_String, $text = 0) ;No changes made, this func is coming from AutoIt3Wrapper $I_String = StringReplace($I_String, "%in%", $ScriptFile_In_Org) $I_String = StringReplace($I_String, "%out%", $ScriptFile_Out) $I_String = StringReplace($I_String, "%outx64%", $ScriptFile_Out_x64) $I_String = StringReplace($I_String, "%usex64%", $INP_UseX64) $I_String = StringReplace($I_String, "%icon%", $INP_Icon) $I_String = StringReplace($I_String, "%fileversion%", $INP_Fileversion) $I_String = StringReplace($I_String, "%fileversionnew%", $INP_Fileversion_New) Local $ScriptName = StringTrimLeft($ScriptFile_In_Org, StringInStr($ScriptFile_In_Org, "\", 0, -1)) Local $ScriptDir = StringLeft($ScriptFile_In_Org, StringInStr($ScriptFile_In_Org, "\", 0, -1) - 1) $I_String = StringReplace($I_String, "%scriptfile%", StringReplace($ScriptName, $ScriptFile_In_Ext, '')) $I_String = StringReplace($I_String, "%scriptdir%", $ScriptDir) $I_String = StringReplace($I_String, "%scitedir%", $SciTE_Dir) $I_String = StringReplace($I_String, "%autoitdir%", $CurrentAutoIt_InstallDir) $I_String = StringReplace($I_String, "%AutoItVer%", $AUT2EXE_PGM_VER) $I_String = StringReplace($I_String, "%Date%", _NowDate()) $I_String = StringReplace($I_String, "%LongDate%", _DateTimeFormat(_NowCalcDate(), 1)) $I_String = StringReplace($I_String, "%Time%", _NowTime()) ; These should only be done on text Items, strings containing a File/Path will give problems If $text Then $I_String = StringReplace($I_String, "\n", @CRLF) EndIf ; translater any environment variable in Directives $I_String = _WinAPI_ExpandEnvironmentStrings($I_String) ; Return $I_String EndFunc ;==>Convert_Variables ;other Func/EndFunc....-> ; ; Retrieve the compiler settings from the scriptfile when available Func Retrieve_PreProcessor_Info() Local $In_File = Retrieve_Processor_Info() ;In case of error, $In_File = [0]. If @error > 0 Then Return SetError(@error, 0, 0) Local $SetVars = [[0, 1]] ;[[arraysize, $rcount][Variable Name, value]] Local $CommentBlock = False While $SetVars < $In_File[0] _SelectOpt($SetVars, $In_File, $CommentBlock) $SetVars[0][1] += 1 ;$rcount += 1 (old) WEnd ;Waiting for $ScriptFile_PreprocessorOut (or alike) $ScriptFile_In = @TempDir & StringTrimLeft($ScriptFile_In, StringInStr($ScriptFile_In, "\", 0, -1) - 1) _FileWriteFromArray($ScriptFile_In, $In_File) If @error > 0 Then Return SetError(@error, 0, 0) If $Found_Old_ObfuscatorDirective Then ConsoleWriteLine('! Obfuscator support has been discontinued and is replaced by Au3Stripper using "#Au3Stripper_" directives.') ConsoleWriteLine('! The directive to run Au3Stripper is: #AutoIt3Wrapper_Run_Au3Stripper=y ; Default is n') ConsoleWriteLine('! #Au3Stripper_Parameters options are: ' & @CRLF & _ "! /so or /striponly : This is the default when no parameters are provided. same as /sf=1 /sv=1" & @CRLF & _ "! /sf or /StripFunctions : 1=Strip all unused Func's (1=default)" & @CRLF & _ "! /sv or /StripVariables : 1=Strip all unused Global var records (1=default)" & @CRLF & _ "! /mo or /mergeonly : Just merges the Include files into the source and strips the Comments, just like aut2exe would do." & @CRLF & _ "! /soi or /striponlyincludes: same as /striponly but will leave master script untouched." & @CRLF & _ "! /mi or /MaxIterations : Sets the maximum Iterations Au3Stripper will perform. Default is 5." & @CRLF & _ "! /Beta : Use Beta Includes. Dont use AutoIt3Wrapper_Run_Au3Stripper.") EndIf EndFunc ;==>Retrieve_PreProcessor_Info #EndRegion Functions #Region UDFs Func _ArrayGetKeyValue(ByRef $array, $keyName) Return $array[_ArrayKeyPos($array, $keyName)][1] EndFunc ;==>_ArrayGetKeyValue Func _ArrayKeyFromString($text, $sep = "=") Local $array = [0, 0] $text = StringStripWS($text, 3) $array[0] = StringStripWS(StringInStr($text, $sep) > 0 ? StringLeft($text, StringInStr($text, $sep) - 1) : $text, 3) $array[1] = StringStripWS(StringInStr($text, $sep) > 0 ? StringTrimLeft($text, StringInStr($text, $sep) + StringLen($sep) - 1) : "", 3) Return $array EndFunc ;==>_ArrayKeyFromString Func _ArrayKeyPos($array, $Key) Local $i = 1, $found = 0 While $i < UBound($array) And $found = 0 If $array[$i][0] = $Key Then $found = $i WEnd Return $found EndFunc ;==>_ArrayKeyPos Func _ArraySetKeyValue(ByRef $array, $Key, $value) Local $arrayPos = _ArrayKeyPos($array, $Key) If $arrayPos = 0 Then ReDim $array[UBound($array, 1) + 1][UBound($array, 2)] $array[0][0] += 1 $arrayPos = $array[0][0] EndIf $array[$arrayPos][0] = $Key $array[$arrayPos][1] = $value EndFunc ;==>_ArraySetKeyValue Func _SelectOpt(ByRef $SetVars, ByRef $In_File, ByRef $CommentBlock) Local $s_Opt = $In_File[$SetVars[0][1]] If StringInStr($s_Opt, ";") > 0 Then $s_Opt = StringLeft($s_Opt, StringInStr($s_Opt, ";") - 1) $s_Opt = StringStripWS($s_Opt, 3) ;StringUpper() ? Local $opt = _ArrayKeyFromString($s_Opt, " ") Local $Key = _ArrayKeyFromString($opt[1]) #Region return conditions If StringLeft($opt[0], 1) <> "#" Then Return $opt ;Ignore non- pre-processor lines ; Ignore commentblocks If $opt[0] = "#cs" Or $opt[0] = "#comments-start" Then $CommentBlock = True If $opt[0] = "#ce" Or $opt[0] = "#comments-end" Then $CommentBlock = False If $CommentBlock Then Return $opt ;~ ;Mandatory #-starting keywords here ? ;~ If StringLeft($opt[0], 16) <> "#AutoIt3Wrapper_" _ ;~ And StringLeft($opt[0], 5) <> "#Run_" _ ;~ And StringLeft($opt[0], 6) <> "#Tidy_" _ ;~ And StringLeft($opt[0], 12) <> "#Obfuscator_" _ ;~ And StringLeft($opt[0], 13) <> "#Au3Stripper_" _ ;~ And StringLeft($opt[0], 5) <> "#Run_" _ ;~ And StringLeft($opt[0], 7) <> "#Pragma" _ ;~ And StringLeft($opt[0], 4) <> "#Set" _ ;~ And StringLeft($opt[0], 3) <> "#If" _ ;~ And StringLeft($opt[0], 5) <> "#Else" _ ;~ And StringLeft($opt[0], 3) <> "#Fi" _ ;~ Then Return $opt #EndRegion return conditions #Region old AutoIt3Wrapper detection ; we added AutoIt3Wrapper_ for clearity to the compiler directives. If StringLeft($opt[0], 12) = "#Obfuscator_" Then $Found_Old_ObfuscatorDirective = 1 $opt[0] = StringReplace($opt[0], "#Obfuscator", "#Au3Stripper") EndIf If $opt[0] = "#AutoIt3Wrapper_Run_Obfuscator" Then $Found_Old_ObfuscatorDirective = 1 $opt[0] = StringReplace($opt[0], "#AutoIt3Wrapper_Run_Obfuscator", "#AutoIt3Wrapper_Run_Au3Stripper") EndIf #EndRegion old AutoIt3Wrapper detection Switch $opt[0] Case "#Pragma" ; Read the Pragma Lines for later processing&decisions ;~ $Pragma_Used = 1 ;Exemple : #pragma compile(AutoItExecuteAllowed, true) --> $PragmaOption = ["AutoItExecuteAllowed", "true"] Local $PragmaOption = StringRegExp($opt[1], "(?i)compile\h*\(\h*(.*?)\h*[,]\h*(.*?)\h*\)", 3) If Not @error Then If UBound($PragmaOption) < 2 Then ReDim $PragmaOption[2] ; avoid errors in case the parameter is not read fully. Switch $PragmaOption[0] Case "out" $Pragma_Out = $PragmaOption[1] Case "Icon" $Pragma_Icon = $PragmaOption[1] Case "ExecLevel" $Pragma_RES_requestedExecutionLevel = $PragmaOption[1] Case "UPX" $Pragma_UseUpx = $PragmaOption[1] Case "Console" $Pragma_Change2CUI = $PragmaOption[1] Case "Compression" $Pragma_Compression = $PragmaOption[1] Case "Compatibility" $Pragma_RES_Compatibility = $PragmaOption[1] Case "x64" $Pragma_Out_x64 = $PragmaOption[1] Case "inputboxres" ;$pragma_ = $PragmaOption[1] Case "Comments" $Pragma_Comment = $PragmaOption[1] Case "CompanyName" $Pragma_Company = $PragmaOption[1] Case "FileDescription" $Pragma_Description = $PragmaOption[1] Case "FileVersion" $Pragma_Fileversion = $PragmaOption[1] Case "InternalName" $Pragma_InternalName = $PragmaOption[1] Case "LegalCopyright" $Pragma_LegalCopyright = $PragmaOption[1] Case "LegalTrademarks" $Pragma_LegalTradeMarks = $PragmaOption[1] Case "OriginalFilename" ;~ $Pragma_ = $PragmaOption[1] Case "ProductName" $Pragma_Productname = $PragmaOption[1] Case "ProductVersion" $Pragma_ProductVersion = $PragmaOption[1] Case "AutoItExecuteAllowed" ; Ignore Case Else ConsoleWriteLine("- #pragma directive " & $PragmaOption[0] & " found but don't understand it so will ignore: " & $opt[0]) EndSwitch EndIf ; ================ Other ========================================================================= Case "#Au3Stripper_Parameters" $INP_Au3Stripper_Parameters = $opt[1] ;Case StringLeft($opt[0], 13) = "#Au3Stripper_" ; skip other #Au3Stripper directives Case "#Tidy_Parameters" If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_Tidy_Parameters = $opt[1] ;Case StringLeft($opt[0], 6) = "#Tidy_" ; skip #Tidy directives ; ================ AutoIt3/Aut2EXE ========================================================================= Case "#AutoIt3Wrapper_ShowProgress" $INP_ShowStatus = $opt[1] Case "#AutoIt3Wrapper_Testing" $INP_AutoIt3Wrapper_Testing = $opt[1] If $INP_AutoIt3Wrapper_Testing = "y" Then ConsoleWriteLine("! Found #AutoIt3Wrapper_Testing=y directive => skipping Tidy, Au3Stripper, versionResourceupdate and Versioning for speed.") EndIf Case "#AutoIt3Wrapper_If_Run" $INP_AutoIt3Wrapper_If = "Run" If $ShowGUI Then $ShowGUI = 0 ConsoleWriteLine("! *************************************************************************") ConsoleWriteLine("! * GUI mode not supported in combination with #AutoIt3Wrapper_If_Run *") ConsoleWriteLine("! *************************************************************************") Exit EndIf Case "#AutoIt3Wrapper_If_AU3Check" $INP_AutoIt3Wrapper_If = "AU3Check" If $ShowGUI Then $ShowGUI = 0 ConsoleWriteLine("! ******************************************************************************") ConsoleWriteLine("! * GUI mode not supported in combination with #AutoIt3Wrapper_If_AU3Check *") ConsoleWriteLine("! ******************************************************************************") Exit EndIf Case "#AutoIt3Wrapper_If_Compile" $INP_AutoIt3Wrapper_If = "Compile" If $ShowGUI Then $ShowGUI = 0 ConsoleWriteLine("! *****************************************************************************") ConsoleWriteLine("! * GUI mode not supported in combination with #AutoIt3Wrapper_If_Compile *") ConsoleWriteLine("! *****************************************************************************") Exit EndIf Case "#AutoIt3Wrapper_EndIf" $INP_AutoIt3Wrapper_If = "" Case "#AutoIt3Wrapper_LogFile" $INP_AutoIt3Wrapper_LogFile = StringReplace($opt[1], '"', '') ;Case "#AutoIt3Wrapper_Prompt" ; Obsolete..... Only override the command line when an actual value is given Case "#AutoIt3Wrapper_Compile_both" $INP_Compile_Both = $opt[1] Case "#AutoIt3Wrapper_OutFile" $ScriptFile_Out = Convert_Variables(StringReplace($opt[1], '"', '')) Case "#AutoIt3Wrapper_OutFile_x64" $ScriptFile_Out_x64 = Convert_Variables(StringReplace($opt[1], '"', '')) Case "#AutoIt3Wrapper_OutFile_x86" $ScriptFile_Out_x86 = Convert_Variables(StringReplace($opt[1], '"', '')) Case "#AutoIt3Wrapper_OutFile_Type" $ScriptFile_Out_Type = $opt[1] If $ScriptFile_Out_Type <> "A3X" And $ScriptFile_Out_Type <> "EXE" Then $ScriptFile_Out_Type = "" ConsoleWriteLine("- Skipping #AutoIt3Wrapper_OutFile_Type directive. Invalid type:" & $opt[1] & ". Can only be A3X or EXE") Else ; Only use the "#AutoIt3Wrapper_OutFile_Type" when "#AutoIt3Wrapper_OutFile" isn't given If $ScriptFile_Out = "" Then $ScriptFile_Out = StringTrimRight($ScriptFile_In, StringLen($ScriptFile_In_Ext)) & '.' & $ScriptFile_Out_Type EndIf EndIf Case "#AutoIt3Wrapper_Icon" $INP_Icon = StringReplace($opt[1], '"', '') $DebugIcon = $DebugIcon & "Comp directive icon: " & $INP_Icon & @CRLF Case "#AutoIt3Wrapper_Compression" $INP_Compression = $opt[1] ;Case "#AutoIt3Wrapper_PassPhrase" ;~ $INP_PassPhrase = $opt[1] ;~ $INP_PassPhrase2 = $opt[1] Case "#AutoIt3Wrapper_Version" If $opt[1] = "b" Or $opt[1] = "Beta" Then $INP_AutoIt3_Version = "Beta" Else $INP_AutoIt3_Version = "prod" EndIf Case "#AutoIt3Wrapper_AutoIt3Dir" If StringReplace($opt[1], '"', '') <> "" Then $INP_AutoItDir = StringReplace($opt[1], '"', '') If Not FileExists($INP_AutoItDir) Or Not StringInStr(FileGetAttrib($INP_AutoItDir), "D") Then ConsoleWriteLine("! Skipping #AutoIt3Wrapper_AutoIt3Dir because the Directory is not found. Specified:" & $INP_AutoItDir) $INP_AutoItDir = "" ElseIf Not FileExists($INP_AutoItDir & "\Autoit3.exe") Then ConsoleWriteLine("! Skipping #AutoIt3Wrapper_AutoIt3Dir because the Directory doesn't contain AutoIt3.exe. specified:" & $INP_AutoItDir) $INP_AutoItDir = "" EndIf EndIf Case "#AutoIt3Wrapper_AutoIt3" If StringReplace($opt[1], '"', '') <> "" Then $AutoIt3_PGM = StringReplace($opt[1], '"', '') If Not FileExists($AutoIt3_PGM) Then ConsoleWriteLine("- Skipping #AutoIt3Wrapper_AutoIt3 because the file is not found:" & $AutoIt3_PGM) $AutoIt3_PGM = "" EndIf EndIf ;Case "#AutoIt3Wrapper_AU3Check_Dat" ; Obsolete..... Only override the command line when an actual value is given Case "#AutoIt3Wrapper_AUT2EXE" If StringReplace($opt[1], '"', '') <> "" Then $AUT2EXE_PGM = StringReplace($opt[1], '"', '') If Not FileExists($AUT2EXE_PGM) Then ConsoleWriteLine("- Skipping #AutoIt3Wrapper_AUT2EXE because the file is not found:" & $AUT2EXE_PGM) $AUT2EXE_PGM = "" EndIf EndIf Case "#AutoIt3Wrapper_UseUpx" $INP_UseUpx = $opt[1] Case "#AutoIt3Wrapper_UPX_Parameters" $INP_Upx_Parameters = $opt[1] Case "#AutoIt3Wrapper_UseAnsi" ConsoleWriteLine("- Skipping #AutoIt3Wrapper_UseAnsi directive because ANSI is not supported anymore.") $INP_UseAnsi = "N" Case "#AutoIt3Wrapper_UseX64" $INP_UseX64 = $opt[1] ;Case "#AutoIt3Wrapper_Allow_Decompile" ; Obsolete..... $INP_Allow_Decompile = $opt[1] Case "#Run_Debug_Mode", "#AutoIt3Wrapper_Run_Debug_Mode" If $opt[1] = "y" Or $opt[1] = 1 Then $INP_Run_Debug_Mode = 1 ;Case "#AutoIt3Wrapper_run_debug" ; debug on or off direction ; ================ Resources ========================================================================= Case "#AutoIt3Wrapper_Res_Language" $INP_Res_Language = Number($opt[1]) If $INP_Res_Language = 0 Then $INP_Res_Language = 2057 Case "#AutoIt3Wrapper_Res_Comment" $INP_Comment = $opt[1] Case "#AutoIt3Wrapper_Res_Description" $INP_Description = $opt[1] Case "#AutoIt3Wrapper_Res_Fileversion" $INP_Fileversion = $opt[1] Case "#AutoIt3Wrapper_Res_FileVersion_AutoIncrement" $INP_Fileversion_AutoIncrement = $opt[1] Case "#AutoIt3Wrapper_Res_Fileversion_First_Increment" $INP_Fileversion_First_Increment = $opt[1] Case "#AutoIt3Wrapper_Res_ProductVersion" $INP_ProductVersion = Convert_Variables($opt[1]) Case "#AutoIt3Wrapper_Res_LegalCopyright" $INP_LegalCopyright = $opt[1] ; limited number of free format resource info fields Case "#AutoIt3Wrapper_Res_Icon_Add" If $opt[1] <> "" Then $INP_Icons_cnt += 1 ReDim $INP_Icons[$INP_Icons_cnt + 1] $INP_Icons[$INP_Icons_cnt] = Convert_Variables(StringReplace($opt[1], '"', '')) $IconFileInfo = StringSplit($INP_Icons[$INP_Icons_cnt], ",") If Not FileExists($IconFileInfo[1]) Then ConsoleWriteLine('- => Skipping #AutoIt3Wrapper_Res_Icon_Add because the Ico file is not found:"' & $INP_Icons[$INP_Icons_cnt] & '"') $INP_Icons_cnt -= 1 EndIf EndIf Case "#AutoIt3Wrapper_Res_File_Add" If $opt[1] <> "" Then $INP_Res_Files_Cnt += 1 ReDim $INP_Res_Files[$INP_Res_Files_Cnt + 1] $INP_Res_Files[$INP_Res_Files_Cnt] = Convert_Variables(StringReplace($opt[1], '"', '')) Local $ResFileInfo $ResFileInfo = StringSplit($INP_Res_Files[$INP_Res_Files_Cnt], ",") If Not FileExists($ResFileInfo[1]) Then ConsoleWriteLine("- Skipping #AutoIt3Wrapper_Res_File_Add because the file is not found:" & $INP_Res_Files[$INP_Res_Files_Cnt]) $INP_Res_Files_Cnt -= 1 EndIf EndIf Case "#AutoIt3Wrapper_Res_Remove" If $opt[1] <> "" Then $INP_Res_Files_Cnt += 1 ReDim $INP_Res_Files[$INP_Res_Files_Cnt + 1] ; add leading ',' so StringSplit during later processing creates empty array value ; an empty value for input will remove the resource $INP_Res_Files[$INP_Res_Files_Cnt] = Convert_Variables(StringReplace("," & $opt[1], '"', '')) EndIf Case "#AutoIt3Wrapper_Res_SaveSource" $INP_Res_SaveSource = $opt[1] Case "#AutoIt3Wrapper_Res_Field" $Temp_Val = StringSplit($opt[1], "|") If $INP_Res_FieldCount > 14 Then ConsoleWriteLine("- Skipping #AutoIt3Wrapper_Res_Field directive. You can only have 15 field max:" & $opt[1]) ElseIf $Temp_Val[0] <> 2 Then ConsoleWriteLine("- Skipping #AutoIt3Wrapper_Res_Field directive. Doesn't have a | in it:" & $opt[1]) Else $INP_Res_FieldCount = $INP_Res_FieldCount + 1 $INP_FieldName[$INP_Res_FieldCount] = $Temp_Val[1] $INP_FieldValue[$INP_Res_FieldCount] = $Temp_Val[2] EndIf ; Old format for Resource fields Case "#AutoIt3Wrapper_Res_Field1Value" $INP_FieldValue1 = $opt[1] Case "#AutoIt3Wrapper_Res_Field1Name" $INP_FieldName1 = $opt[1] Case "#AutoIt3Wrapper_Res_Field2Value" $INP_FieldValue2 = $opt[1] Case "#AutoIt3Wrapper_Res_Field2Name" $INP_FieldName2 = $opt[1] Case "#AutoIt3Wrapper_Res_requestedExecutionLevel" ;None, asInvoker, highestAvailable or requireAdministrator (default=None)" Switch $opt[1] Case "" $INP_Res_requestedExecutionLevel = "" Case "asInvoker", "highestAvailable", "requireAdministrator", "None" $INP_Res_requestedExecutionLevel = $opt[1] Case Else $INP_Res_requestedExecutionLevel = "" ConsoleWriteLine("- Skipping #AutoIt3Wrapper_res_requestedExecutionLevel directive. Invalid value:" & $opt[1]) EndSwitch Case "#AutoIt3Wrapper_Res_HiDpi" $INP_RES_HiDpi = $opt[1] Case "#AutoIt3Wrapper_Res_Compatibility" ;? $INP_Res_Compatibility = $opt[1] $Temp_Val = StringSplit($opt[1], ",") For $x = 1 To $Temp_Val[0] ;None, Vista, Windows7 (default=None)" Switch $Temp_Val[$x] Case "", "None" $INP_Res_Compatibility = "" Case "Vista", "Windows7", "win7", "win8", "win81" ; Case Else ConsoleWriteLine("- Skipping #AutoIt3Wrapper_res_Compatibility directive invalid value:" & $Temp_Val) EndSwitch Next ; ================ Other ========================================================================= Case "#AutoIt3Wrapper_Run_AU3Check" If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_Run_AU3Check = $opt[1] EndIf Case "#AutoIt3Wrapper_Jump_To_First_Error" If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_Jump_To_First_Error = $opt[1] EndIf Case "#AutoIt3Wrapper_AU3Check_Parameters" If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_AU3Check_Parameters = $opt[1] EndIf Case "#AutoIt3Wrapper_AU3Check_Stop_OnWarning" If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_AU3Check_Stop_OnWarning = $opt[1] EndIf Case "#AutoIt3Wrapper_Run_Tidy" If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_Run_Tidy = $opt[1] EndIf Case "#AutoIt3Wrapper_Tidy_Stop_OnError" If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_Tidy_Stop_OnError = $opt[1] EndIf Case "#AutoIt3Wrapper_Run_Au3Stripper" $INP_Run_Au3Stripper = $opt[1] Case "#AutoIt3Wrapper_Run_Before" $INP_Run_Before[0] += 1 ReDim $INP_Run_Before[$INP_Run_Before[0] + 1] ReDim $INP_Run_Before_Admin[$INP_Run_Before[0] + 1] $INP_Run_Before[$INP_Run_Before[0]] = $opt[1] $INP_Run_Before_Admin[$INP_Run_Before[0]] = $INP_Run_Before_Admin[0] Case "#AutoIt3Wrapper_Run_After" $INP_Run_After[0] += 1 ReDim $INP_Run_After[$INP_Run_After[0] + 1] ReDim $INP_Run_After_Admin[$INP_Run_After[0] + 1] $INP_Run_After[$INP_Run_After[0]] = $opt[1] $INP_Run_After_Admin[$INP_Run_After[0]] = $INP_Run_After_Admin[0] Case "#AutoIt3Wrapper_Run_Before_Admin" ; Set the [0] value to what we want to use for the subsequent run commands If $opt[1] = "y" Or $opt[1] = 1 Then $INP_Run_Before_Admin[0] = 1 Else $INP_Run_Before_Admin[0] = 0 EndIf Case "#AutoIt3Wrapper_Run_After_Admin" ; Set the [0] value to what we want to use for the subsequent run commands If $opt[1] = "y" Or $opt[1] = 1 Then $INP_Run_After_Admin[0] = 1 Else $INP_Run_After_Admin[0] = 0 EndIf Case "#AutoIt3Wrapper_Run_CvsWrapper" $INP_Run_Versioning = $opt[1] Case "#AutoIt3Wrapper_Versioning" $INP_Run_Versioning = $opt[1] Case "#AutoIt3Wrapper_CvsWrapper_Parameters" $INP_Versioning_Parameters = $opt[1] Case "#AutoIt3Wrapper_Versioning_Parameters" $INP_Versioning_Parameters = $opt[1] Case "#AutoIt3Wrapper_PlugIn_Funcs" $INP_Plugin = $opt[1] Case "#AutoIt3Wrapper_Change2CUI" $INP_Change2CUI = $opt[1] Case "#AutoIt3Wrapper_Add_Constants" $INP_Add_Constants = $opt[1] Case "#AutoIt3Wrapper_ShowGui" $ShowGUI = $opt[1] Case "#AutoIt3Wrapper_Run_SciTE_Minimized" $INP_Run_SciTE_Minimized = $opt[1] Case "#AutoIt3Wrapper_Run_SciTE_OutputPane_Minimized" $INP_Run_SciTE_OutputPane_Minimized = $opt[1] Case "#AutoIt3Wrapper_Run_PreExpand" ; expirimental option which might be removed again. If $INP_AutoIt3Wrapper_If = "" Or $INP_AutoIt3Wrapper_If = $Option Then $INP_Run_PreExpand = $opt[1] EndIf ; === UDF operations ===== Case "#Set" _ArraySetKeyValue($SetVars, $Key[0], $Key[1]) Case "#If" $if = (_ArrayGetKeyValue($SetVars, $Key[0]) = $Key[1]) While $SetVars[0][1] < $In_File[0] And $opt[0] <> "#Fi" $SetVars[0][1] += 1 $opt = _SelectOpt($SetVars, $In_File, $CommentBlock) If $opt[0] = "#Else" Then $if = Not $if ElseIf $opt[0] <> "#Fi" Then If ($if) And ($opt[0] = "#" Or StringLeft($opt[0], 2) = "# ") Then $In_File[$SetVars[0][1]] = StringReplace($In_File[$SetVars[0][1]], "# ", "", 0) If (Not $if) And ($opt[0] <> "#" And StringLeft($opt[0], 2) <> "# ") Then $In_File[$SetVars[0][1]] = "# " & $In_File[$SetVars[0][1]] EndIf WEnd Case "#Else", "#Fi", "#" ;Nothing. Case Else ConsoleWriteLine('! Invalid AutoIt3Wrapper directive Keyword:' & $opt[0] & ' with value:' & $opt[1]) EndSwitch Return $opt EndFunc ;==>_SelectOpt Func ConsoleWriteLine($s) ConsoleWrite($s & @CRLF) EndFunc ;==>ConsoleWriteLine Func Retrieve_Processor_Info() Local $hTest_UTF = FileOpen($ScriptFile_In, 16) Local $Test_UTF = FileRead($hTest_UTF, 4) FileClose($hTest_UTF) ;~ 00 00 FE FF UTF-32, big-endian ;~ FF FE 00 00 UTF-32, little-endian ;~ FE FF UTF-16, big-endian ;~ FF FE UTF-16, little-endian ;~ EF BB BF UTF-8 Select Case BinaryMid($Test_UTF, 1, 4) = '0x0000FEFF' ; UTF-32 BE $UTFtype = '32BE' $SrceUnicodeFlag = 0 $InputFileIsUTF32 = 1 Case BinaryMid($Test_UTF, 1, 4) = '0xFFFE0000' ; UTF-32 LE $UTFtype = '32LE' $SrceUnicodeFlag = 0 $InputFileIsUTF32 = 1 Case BinaryMid($Test_UTF, 1, 2) = '0xFEFF' ; UTF-16 BE $UTFtype = '16BE' $SrceUnicodeFlag = 64 $InputFileIsUTF16 = 1 Case BinaryMid($Test_UTF, 1, 2) = '0xFFFE' ; UTF-16 LE $UTFtype = '16LE' $SrceUnicodeFlag = 32 $InputFileIsUTF16 = 1 Case BinaryMid($Test_UTF, 1, 3) = '0xEFBBBF' ; UTF-8 $UTFtype = '8' $SrceUnicodeFlag = 128 $InputFileIsUTF8 = 1 Case Else $UTFtype = '' $SrceUnicodeFlag = 0 $InputFileIsUTF8 = 0 $InputFileIsUTF16 = 0 $InputFileIsUTF32 = 0 EndSelect ; ------------------------------------------------------------------------------------------------------------------------------------------------------------- Local $aFile Local $hFile = FileOpen($ScriptFile_In, 16384) If $hFile = -1 Then Return SetError(1, 0, 0);; unable to open the file ; Read the file and dump into an Array and also check if the Filesize is different from the Read Characters which will be an indication of UTF8 without BOM Local $aFile_tot = FileRead($hFile) Local $aFile_len = @extended FileClose($hFile) ; Write warning for UTF encoded files or else check for UTF8 without BOM files If $InputFileIsUTF8 Then ;~ ConsoleWriteLine("! ***************************************************************************************************") ;~ ConsoleWriteLine("! * Input file is UTF" & $UTFtype & " encoded, Au3Stripper do not support UNICODE and will be skipped.*") ;~ ConsoleWriteLine("! ***************************************************************************************************") ElseIf $InputFileIsUTF16 Or $InputFileIsUTF32 Then ;~ ConsoleWriteLine("! ***************************************************************************************************") ;~ ConsoleWriteLine("! * Input file is UTF" & $UTFtype & " encoded, Tidy and Au3Stripper do not support UNICODE and will be skipped.*") ;~ ConsoleWriteLine("! ***************************************************************************************************") Else ; check for UTF8 without BOM, if so Warn and tell them the file will be changed to UTF8 with BOM If $aFile_len > StringLen($aFile_tot) Then $UTFtype = '8 Without BOM' $SrceUnicodeFlag = 256 $InputFileIsUTF8 = 9 EndIf EndIf ; build Array If StringInStr($aFile_tot, @LF) Then Return StringSplit(StringStripCR($aFile_tot), @LF) ElseIf StringInStr($aFile, @CR) Then ;; @LF does not exist so split on the @CR Return StringSplit($aFile_tot, @CR) Else ;; unable to split the file If StringLen($aFile_tot) Then ;$aFile_tot &= @LF ;$In_File = StringSplit(StringStripCR($aFile_tot), @LF) Local $In_File = [1, $aFile_tot] ;Very transient var Return $In_File ;Return does not accept the Return [values] syntax Else SetError(2, 0, 0) Local $In_File = [0] ;Same thing here Return $In_File EndIf EndIf EndFunc ;==>Retrieve_Processor_Info #EndRegion UDFs