Jump to content

TurboBooster for your scripts...


KaFu
 Share

Recommended Posts

HiHo Community,

TurboBooster is about an idea I'm tinkering on for quite some time now, without making any big progress (or real code up to now). So... please regard this dirty piece of code as a proof of concept and an invitation to help me to improve the script.

We had a discussion about the speed of scripts sometime ago. One issue about the speed is the length of the variable and function names themselves. TurboBooster reads them from the source (Obfuscator is just used to include all necessary #includes into one script) by regex (needs improvement) and replaces them with the shortest possible alternative (well, a shorter one at least, that could be improved too I guess) by looping through the source (in a most inefficient way).

Prerequisite

Your script must compile correctly when obfuscated with these options:

#Obfuscator_Parameters=/striponly

1. Compile your script with obfuscation activated (SciTE Editor):

#AutoIt3Wrapper_Run_Obfuscator=y

#Obfuscator_Parameters=/striponly

2. Obfuscater will create an updated version of your source script in the scriptdir, called "[sOURCENAME]_Obfuscated.au3". This one is the source for TurboBooster.

3. TurboBooster will create a file called "[sOURCENAME]_Obfuscated_TB.au3". Add all necessary additional directives to that script from the original source (#AutoIt3Wrapper for adding resources etc.) and compile this one to the final script.

TurboBooster.au3

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.0
    Author:         KaFu

    Script Function:
    TurboBooster for your scripts... v0.14
    ... or an invitation to help me to improve it...

#ce ----------------------------------------------------------------------------

Opt("GUIOnEventMode", 1)

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <sqlite.au3>
#include <sqlite.dll.au3>

Global Const $sTitle = "TurboBooster v0.14"
Global $_BCaddlNums[37] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "_", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

Global $hQuery, $aRow
_SQLite_Startup()
_SQLite_Open()
OnAutoItExitRegister("_Exit_SQLite_Shutdown")

Dim $aVars_Ignore[2]=["$CmdLine","$CmdLineRaw"]
; Tested Var and Func names up to 30.000 for invalid combos
Dim $aFuncs_Skip[24]=["do", "in","if","or","to","abs","and","asc","chr","cos","dec","dim","exp","for","hex","int","log","mod","not","opt","ptr","run","sin","tan"]

$h_Gui = GUICreate($sTitle, 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$c_edit = GUICtrlCreateEdit("", 5, 5, 390, 390)

$sText = "The target .au3 Script needs to be obfuscated first with following directives:" & @CRLF & @CRLF & "#AutoIt3Wrapper_Run_Obfuscator=y" & @CRLF & "#Obfuscator_Parameters=/striponly" & @CRLF & @CRLF & "Other directives (adding resources etc.) should then be" & @CRLF & "applied to the _TB.au3 script for the final compilation."
$sText &= @crlf & @crlf & '- Function names must be unique to functions, e.g. a function called' & @CRLF & '"GetWindowLong" and a dllcall like' & @CRLF & 'DllCall($user_dll, "int", "GetWindowLong", "hwnd"", $hWnd, "int", $nIndex)' & @CRLF & 'will break TBs result. Rename the function resp., e.g. by adding an' & @CRLF & 'underscore (_GetWindowLong)'
$sText &= @crlf & @crlf &  "- Call() and Execute() might break, didn't take a look into that up to now"

GUICtrlSetData($c_edit, $sText)
GUISetState()

$sFile = FileOpenDialog($sTitle & " - Select obfuscated script", @ScriptDir, "Obfuscated au3 script (*_Obfuscated.au3)", $h_Gui)
If @error Then Exit
$sTargetFilename = StringReplace($sFile, ".au3", "_TB.au3")

If FileExists($sTargetFilename) Then
    If MsgBox(1 + 48 + 262144, "TurboBooster", "Target file" & @CRLF & @CRLF & $sTargetFilename & @CRLF & @CRLF & "already exists and will be deleted if you proceed...", 0, $h_Gui) = 2 Then Exit
EndIf
FileDelete($sTargetFilename)

Global $hFile = FileOpen($sFile, 0)
Global $sSrc
Global $aVars, $aFuncs

If $hFile = -1 Then Exit
$sSrc = FileRead($hFile)
FileClose($hFile)

$iSourceLenOld = StringLen($sSrc)
$sClean = StringRegExpReplace($sSrc, '"(?:[^"]+|"")*"|''(?:[^'']+|'''')*''|;.*', '')


#Region Replace Funcs
$aFuncs = StringRegExp($sClean, '(?i)(?x)(\bfunc\s+\w+\s*( \( ( (?>[^()]+) | (?2) )* \) ))', 3)
$sSQLite_Query = "Create table tbl_raw_Funcs (Funcs UNIQUE);"
_SQLite_Exec(-1, $sSQLite_Query)

$ubound = UBound($aFuncs) - 1
For $i = 0 To $ubound
    $s_Edit_New = "Preparing Funcs " & $i + 1 & " of " & $ubound + 1
    GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))
    If StringInStr($aFuncs[$i], "Func ") Then
        $sSQLite_Query = 'INSERT INTO tbl_raw_Funcs (Funcs) VALUES ("' & StringLower(StringLeft(StringReplace($aFuncs[$i], "Func ", ""), StringInStr(StringReplace($aFuncs[$i], "Func ", ""), "(") - 1)) & '");'
        _SQLite_Exec(-1, $sSQLite_Query)
    EndIf
Next

Local $aRow[1]
$aRow[0] = 0
_SQLite_QuerySingleRow(-1, "SELECT count(*) FROM tbl_raw_Funcs", $aRow)
If $aRow[0] > 0 Then
    ReDim $aFuncs[$aRow[0]]
    $i = 0
    _SQLite_Query(-1, "SELECT * FROM tbl_raw_Funcs ORDER BY Funcs DESC;", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        $aFuncs[$i] = $aRow[0]
        $i += 1
    WEnd
    _SQLite_QueryFinalize($hQuery)
EndIf

$var_offset = 1
$ubound = UBound($aFuncs) - 1

For $i = 0 To $ubound
    $s_Edit_New = "Renaming Funcs " & $i + 1 & " of " & $ubound + 1
    GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))

    $sFuncsNew = _BasetoBase($i + $var_offset, 10, 37)
    $sLeft = StringLeft($sFuncsNew,1)

    If  Asc($sLeft) < 58 Or _StringInArray($sFuncsNew, $aFuncs) or _StringInArray($sFuncsNew, $aFuncs_Skip) Then
        $i -= 1
        $var_offset += 1
        ContinueLoop
    EndIf

    $sSrc = StringReplace($sSrc, @LF & $aFuncs[$i] & "(", @LF & $sFuncsNew & "(")
    $sSrc = StringReplace($sSrc, " " & $aFuncs[$i] & "(", " " & $sFuncsNew & "(")
    $sSrc = StringReplace($sSrc, "(" & $aFuncs[$i] & "(", "(" & $sFuncsNew & "(")
    $sSrc = StringReplace($sSrc, "[" & $aFuncs[$i] & "(", "[" & $sFuncsNew & "(")
    $sSrc = StringReplace($sSrc, """" & $aFuncs[$i] & """", """" & $sFuncsNew & """")
    $sSrc = StringReplace($sSrc, "'" & $aFuncs[$i] & "'", "'" & $sFuncsNew & "'")

    $s_Edit_New = "New Source length: " & StringLen($sSrc)
    GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))
Next

#EndRegion Replace Funcs



#Region Replace Vars
$s_Edit_New = "Extracting Vars..."
GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))
$aVars = StringRegExp($sClean, '\$\w+', 3)
$sSQLite_Query = "Create table tbl_raw_Vars (Vars UNIQUE);"
_SQLite_Exec(-1, $sSQLite_Query)

$ubound = UBound($aVars) - 1
For $i = 0 To $ubound
    $s_Edit_New = "Preparing Vars " & $i + 1 & " of " & $ubound + 1
    GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))
    If $aVars[$i] = $aVars_Ignore[0] Or $aVars[$i] = $aVars_Ignore[1] Then ContinueLoop
    $sSQLite_Query = 'INSERT INTO tbl_raw_Vars (Vars) VALUES ("' & StringLower($aVars[$i]) & '");'
    _SQLite_Exec(-1, $sSQLite_Query)
Next

Local $aRow[1]
$aRow[0] = 0
_SQLite_QuerySingleRow(-1, "SELECT count(*) FROM tbl_raw_Vars", $aRow)
If $aRow[0] > 0 Then
    ReDim $aVars[$aRow[0]]
    $i = 0
    _SQLite_Query(-1, "SELECT * FROM tbl_raw_Vars ORDER BY Vars DESC;", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        $aVars[$i] = $aRow[0]
        $i += 1
    WEnd
    _SQLite_QueryFinalize($hQuery)
EndIf

$var_offset = 1
$ubound = UBound($aVars) - 1
For $i = 0 To $ubound
    $s_Edit_New = "Renaming Var " & $aVars[$i] & " #"& $i & " of " & $ubound
    GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))

    $sVarNew = "$" & _BasetoBase($i + $var_offset , 10, 37)
    If _StringInArray($sVarNew, $aVars) Then
        $i -= 1
        $var_offset += 1
        ContinueLoop
    EndIf

    $sSrc = StringReplace($sSrc, $aVars[$i], $sVarNew)
    $sSrc = StringReplace($sSrc, "IsDeclared(""" & StringRight($aVars[$i], StringLen($aVars[$i]) - 1), "IsDeclared(""" & StringRight($sVarNew, StringLen($sVarNew) - 1))
    $s_Edit_New = "New Source length: " & StringLen($sSrc)
    GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))
Next
#EndRegion Replace Vars


$s_Edit_New = "Writing new source to target file..."
GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))
$hFile = FileOpen($sTargetFilename, 2)
If $hFile = -1 Then
    ClipPut($sSrc)
    $s_Edit_New = @CRLF & "TurboBooster - Error" & @CRLF & "Could not write to target file" & @CRLF & @CRLF & $sTargetFilename & @CRLF & @CRLF & "Changed source has been copied to clipboard (manually paste to new file)."
    GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))
    MsgBox(16 + 262144, "TurboBooster - Error", "Could not write to target file" & @CRLF & @CRLF & $sTargetFilename & @CRLF & @CRLF & "Changed source has been copied to clipboard (manually paste to new file).", 0, $h_Gui)
    Exit
EndIf
FileWrite($hFile, $sSrc)
FileClose($hFile)

$s_Edit_New = "New source length: " & @TAB & @TAB & StringLen($sSrc) & @CRLF & "Old source length: " & @TAB & @TAB & $iSourceLenOld & @CRLF & @CRLF & "=======================" & @CRLF
GUICtrlSetData($c_edit, $s_Edit_New & @CRLF & stringleft(GUICtrlRead($c_edit),4096))

While 1
    sleep(10)
WEnd

Func _Exit_SQLite_Shutdown()
    _SQLite_Close()
    _SQLite_Shutdown()
EndFunc   ;==>_Exit_SQLite_Shutdown

; =======================
; StringInArray
; =======================
Func _StringInArray($string, $array)
    If IsArray($array) Then
        For $i = 0 To UBound($array) - 1
            If $array[$i] = $string Then Return True
        Next
    EndIf
    Return False
EndFunc   ;==>_StringInArray

Func _Exit()
    if MsgBox(1 + 16 + 262144, "TurboBooster", "Do you really want to exit TurboBooster?", 0, $h_Gui) = 2 then Return
    Exit
EndFunc

; =======================
; ToBase Functions
; =======================

; http://www.autoitscript.com/forum/index.php?showtopic=81189
; james3mg

;   Function:   _ToDec()
;   Author:     james3mg
;   Summary:    Converts a number represented in a string from any positive base less than base 63 into decimal (base 10)
;               Numbers greater than 9 should be represented by English letters in ascending alphabetical order; capitols first.  CASE SENSITIVE!
;               See the $_BCaddlNums array at the top of this file for an ordered ranking of digits.
;               Negative bases are not supported; they confuse me too much in practice, though the theory is elegant.
;               Fractional bases (i.e. base 10.25) are correctly supported, but I can't imagine a useful application of them.
;   Arguments:
;               $_BCnum     The string to convert to decimal (base 10) (required)
;               $_BCbase    The base to convert $_BCnum from (optional: default is 16)
;   Return value:
;               Success:    A string representing the number expressed in the base requested
;               Failure:    Returns a blank string ("") and sets @error as following:
;                           @error=1    number string contains non-alphanumeric digits
;                           @error=2    invalid base number provided
;                           @error=3    a digit provided was not in the base provided (for instance a 2 occured in an allegedly binary string)

Func _ToDec($_BCnum, $_BCbase = 16);converts the string from any positive base less than 63 into decimal (base 10)
    If $_BCbase = -1 Or $_BCbase = Default Then $_BCbase = 16
    If Not IsNumber($_BCbase) Or $_BCbase > 62 Or $_BCbase < 1 Then Return SetError(2)
    Local $_BCsign = ""
    If StringLeft($_BCnum, 1) = "-" Then
        $_BCsign = "-"
        $_BCnum = StringTrimLeft($_BCnum, 1)
    EndIf
    Local $_SplitNum = StringSplit(String($_BCnum), "."), $_SplitNumInt = StringSplit($_SplitNum[1], ""), $_i, $_n, $_BCreturnVal = ""
    If Not StringIsAlNum($_SplitNum[1]) Then Return SetError(1);number contains non-alphanumeric digits (to the left of the decimal)
    If $_SplitNum[0] <> 1 Then
        If $_SplitNum[0] <> 2 Then Return SetError(1);number contains non-alphanumeric digits (in this particular case, too many decimal points)
        If Not StringIsAlNum($_SplitNum[2]) Then Return SetError(1);number contains non-alphanumeric digits (to the right of the decimal)
        Local $_SplitNumDec = StringSplit($_SplitNum[2], "")
    EndIf
    ;from here, we can guarentee the number passed the function could be a number in some base
    For $_i = 1 To $_SplitNumInt[0]
        For $_n = 10 To $_BCbase - 1
            If $_SplitNumInt[$_i] == $_BCaddlNums[$_n] Then
                $_SplitNumInt[$_i] = $_n
                ExitLoop
            EndIf
        Next
        If Not StringIsInt($_SplitNumInt[$_i]) Or $_SplitNumInt[$_i] > $_BCbase Then Return SetError(3);digit out of base range (for instance, 3 included in string given as binary)
    Next
    If $_SplitNum[0] = 2 Then;if there was a decimal point
        For $_i = 1 To $_SplitNumDec[0]
            For $_n = 10 To $_BCbase - 1
                If $_SplitNumDec[$_i] == $_BCaddlNums[$_n] Then
                    $_SplitNumDec[$_i] = $_n
                    ExitLoop
                EndIf
            Next
            If Not StringIsInt($_SplitNumDec[$_i]) Or $_SplitNumDec[$_i] > $_BCbase Then Return SetError(3);digit out of base range
        Next
    EndIf

    For $_i = 1 To $_SplitNumInt[0]
        $_BCreturnVal += $_BCbase ^ ($_i - 1) * $_SplitNumInt[$_SplitNumInt[0] - ($_i - 1)]
    Next
    If $_SplitNum[0] = 2 Then;if there was a decimal point
        For $_i = 1 To $_SplitNumDec[0]
            $_BCreturnVal += $_BCbase ^ (0 - $_i) * $_SplitNumDec[$_i]
        Next
    EndIf
    Return SetError(0, 0, $_BCsign & $_BCreturnVal)
EndFunc   ;==>_ToDec

;   Function:   _ToBase()
;   Author:     james3mg
;   Summary:    Converts a number represented in a string from any positive base less than base 63 into decimal (base 10)
;               Numbers greater than 9 are represented by English letters in ascending alphabetical order; capitols first.  CASE SENSITIVE!
;               See the $_BCaddlNums array at the top of this file for an ordered ranking of digits.
;               Decimals are supported, but remember that 1.1 in binary is represented by 1.5 in decimal, since .1 is HALF of a whole number in binary! (Doubling .1 in binary will give you 1.0)
;   !!!         NOTE: the output of this function is a STRING!  Do not expect AutoIt to know how to perform mathematical operations on the result in the correct base!
;               If you want to perform such operations, convert into decimal, run the operation, and convert back.
;               Negative bases are not supported; they confuse me too much in practice, though the theory is elegant.
;               Fractional bases (i.e. base 10.25) are correctly supported, but I can't imagine a useful application of them.
;   Arguments:
;               $_BCnum     The string to convert to the specified base (required)
;               $_BCbase    The base to convert $_BCnum into (optional: default is 16)
;               $_BClimit   The maximum number of decimal points returned (numbers to the RIGHT of the decimal point).  (optional: default is 12)  Note this has no effect on the number of digits to the left of the point (or if there is no point).
;   Return value:
;               Success:    A string representing the number expressed in the base requested
;               Failure:    Returns a blank string ("") and sets @error as following:
;                           @error=1    string is not a decimal (base 10) number
;                           @error=2    invalid base number provided

Func _ToBase($_BCnum, $_BCbase = 16, $_BClimit = 12);converts the decimal (base 10) string into any positive base less than 63
    If $_BCbase = -1 Or $_BCbase = Default Then $_BCbase = 16
    If $_BClimit = -1 Or $_BClimit = Default Then $_BCbase = 12
    If Not IsNumber($_BCbase) Or $_BCbase > 62 Or $_BCbase < 1 Then Return SetError(2)
    Local $_BCsign = ""
    If StringLeft($_BCnum, 1) = "-" Then
        $_BCsign = "-"
        $_BCnum = StringTrimLeft($_BCnum, 1)
    EndIf
    Local $_SplitNum = StringSplit(String($_BCnum), "."), $_i, $_BCreturnVal = ""
    If Not StringIsDigit($_SplitNum[1]) Then Return SetError(1);not a decimal number
    If $_SplitNum[0] <> 1 Then
        If $_SplitNum[0] <> 2 Then Return SetError(1);not a decimal number (too many decimal points)
        If Not StringIsDigit($_SplitNum[2]) Then Return SetError(1);not a decimal number right of the decimal point
    EndIf
    ;now we can assume the number is valid
    Local $_MaxExp = Floor(Log($_BCnum) / Log($_BCbase));find out the digit length in destination base (actual digit length is 1 greater than this number, since 1 has a length of 1 and is 10^0)
    For $_i = $_MaxExp To 0 Step -1;loop through each digit to find the highest multiplier without going over
        $_BCreturnVal &= $_BCaddlNums[Floor($_BCnum / ($_BCbase ^ $_i))]
        $_BCnum -= Floor($_BCnum / ($_BCbase ^ $_i)) * $_BCbase ^ $_i
    Next
    If $_SplitNum[0] = 1 Then Return SetError(0, 0, $_BCsign & $_BCreturnVal)
    ;if you get here, there's still decimal points to tally
    $_BCreturnVal &= "."
    For $_i = -1 To $_BClimit * - 1 Step -1
        $_BCreturnVal &= $_BCaddlNums[Floor($_BCnum / ($_BCbase ^ $_i))]
        $_BCnum -= Floor($_BCnum / ($_BCbase ^ $_i)) * $_BCbase ^ $_i
        If $_BCnum = 0 Then ExitLoop;don't add trailing zeros if an exact conversion is found
    Next
    Return SetError(0, 0, $_BCsign & $_BCreturnVal)
EndFunc   ;==>_ToBase

;   Function:   _BaseToBase()
;   Author:     james3mg
;   Summary:    Converts a number represented in a string from any positive base less than base 63 into decimal (base 10)
;               Numbers greater than 9 are represented by English letters in ascending alphabetical order; capitols first.  CASE SENSITIVE!
;               See the $_BCaddlNums array at the top of this file for an ordered ranking of digits.
;               Decimals are supported, but remember that 1.1 in binary is represented by 1.5 in decimal, since .1 is HALF of a whole number in binary!
;   !!!         NOTE: the output of this function is a STRING!  Do not expect AutoIt to know how to perform mathematical operations on the result in the correct base!
;               If you want to perform such operations, convert into decimal, run the operation, and convert back.
;               Negative bases are not supported; they confuse me too much in practice, though the theory is elegant.
;               Fractional bases (i.e. base 10.25) are correctly supported, but I can't imagine a useful application of them.
;   Arguments:
;               $_BCnum         The string to convert to the specified base (required)
;               $_BCbaseOrig    The base to convert $_BCnum from (optional: default is 16)
;               $_BCbaseFinal   The base to convert $_BCnum into (optional: default is 2)
;               $_BClimit       The maximum number of decimal points returned (numbers to the RIGHT of the decimal point).  (optional: default is 12)  Note this has no effect on the number of digits to the left of the point (or if there is no point).
;   Return value:
;               Success:        A string representing the number expressed in the base requested
;               Failure:        Returns a blank string ("") and sets @error as following:
;                               @error=1    number string contains non-alphanumeric digits
;                               @error=2    invalid input base number provided
;                               @error=3    a digit provided was not in the base provided (for instance a 2 occured in an allegedly binary string)
;                               @error=4    unknown error (this should never happen- it means that _ToDec misfired somehow
;                               @error=5    invalid output base number provided

Func _BaseToBase($_BCnum, $_BCbaseOrig = 16, $_BCbaseFinal = 2, $_BClimit = 12);errors 1-3 match errors 1-3 in _ToDec(); errors 4-5 match errors 1-2 in _ToBase()
    Local $_BCconv = _ToDec($_BCnum, $_BCbaseOrig)
    If @error Then Return SetError(@error)
    $_BCconv = _ToBase($_BCconv, $_BCbaseFinal, $_BClimit)
    If @error Then Return SetError(@error + 3)
    Return SetError(0, 0, $_BCconv)
EndFunc   ;==>_BaseToBase

I tested it on several scripts, e.g. the Toast example from Melba23, heres an already obfuscated copy of that to test TurboBooster... 17 KB before, 13 KB after boosting...

The gain in speed of course is determined by your scripts design. How long are your variable and function names? How often are they called? Does you script process the longest names in the tightest loops? But as far as I understood, you should at least gain some speed (where the extra seconds counts). Truth to be told, I'm looking for a way to further improve the speed of SMF :(...

Toast_Example_Obfuscated.au3

Func _StringSize($sText, $iSize = Default, $iWeight = Default, $iAttrib = Default, $sName = Default, $iWidth = 0)
Local $avSize_Info[4], $aRet, $iLine_Width = 0, $iLast_Word, $iWrap_Count
Local $hLabel_Handle, $hFont, $hDC, $oFont, $tSize = DllStructCreate("int X;int Y")
If Not IsString($sText) Then Return SetError(1, 1, 0)
If Not IsNumber($iSize) And $iSize <> Default Then Return SetError(1, 2, 0)
If Not IsInt($iWeight) And $iWeight <> Default Then Return SetError(1, 3, 0)
If Not IsInt($iAttrib) And $iAttrib <> Default Then Return SetError(1, 4, 0)
If Not IsString($sName) And $sName <> Default Then Return SetError(1, 5, 0)
If Not IsNumber($iWidth) Then Return SetError(1, 6, 0)
Local $hGUI = GUICreate("", 1200, 500, 10, 10)
If $hGUI = 0 Then Return SetError(2, 0, 0)
GUISetFont($iSize, $iWeight, $iAttrib, $sName)
$avSize_Info[0] = $sText
If StringInStr($sText, @CRLF) = 0 Then StringRegExpReplace($sText, "[\x0a|\x0d]", @CRLF)
Local $asLines = StringSplit($sText, @CRLF, 1)
Local $hText_Label = GUICtrlCreateLabel($sText, 10, 10)
Local $aiPos = ControlGetPos($hGUI, "", $hText_Label)
GUISetState(@SW_HIDE)
GUICtrlDelete($hText_Label)
$avSize_Info[1] =($aiPos[3] - 8)/ $asLines[0]
$avSize_Info[2] = $aiPos[2]
$avSize_Info[3] = $aiPos[3] - 4
If $aiPos[2] > $iWidth And $iWidth > 0 Then
$avSize_Info[0] = ""
$avSize_Info[2] = $iWidth
Local $iLine_Count = 0
For $j = 1 To $asLines[0]
$hText_Label = GUICtrlCreateLabel($asLines[$j], 10, 10)
$aiPos = ControlGetPos($hGUI, "", $hText_Label)
GUICtrlDelete($hText_Label)
If $aiPos[2] < $iWidth Then
$iLine_Count += 1
$avSize_Info[0] &= $asLines[$j] & @CRLF
Else
$hText_Label = GUICtrlCreateLabel("", 0, 0)
$hLabel_Handle = ControlGetHandle($hGUI, "", $hText_Label)
$aRet = DllCall("User32.dll", "hwnd", "GetDC", "hwnd", $hLabel_Handle)
If @error Then _StringSize_Error(3, 1, $hLabel_Handle, 0, $hGUI)
$hDC = $aRet[0]
$aRet = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hLabel_Handle, "int", 0x0031, "wparam", 0, "lparam", 0)
If @error Then _StringSize_Error(3, 2, $hLabel_Handle, $hDC, $hGUI)
$hFont = $aRet[0]
$aRet = DllCall("GDI32.dll", "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hFont)
If @error Then _StringSize_Error(3, 3, $hLabel_Handle, $hDC, $hGUI)
$oFont = $aRet[0]
If $oFont = 0 Then _StringSize_Error(3, 4, $hLabel_Handle, $hDC, $hGUI)
$iWrap_Count = 0
While 1
$iLine_Width = 0
$iLast_Word = 0
For $i = 1 To StringLen($asLines[$j])
If StringMid($asLines[$j], $i, 1) = " " Then $iLast_Word = $i - 1
Local $sTest_Line = StringMid($asLines[$j], 1, $i)
GUICtrlSetData($hText_Label, $sTest_Line)
$iSize = StringLen($sTest_Line)
DllCall("GDI32.dll", "int", "GetTextExtentPoint32", "hwnd", $hDC, "str", $sTest_Line, "int", $iSize, "ptr", DllStructGetPtr($tSize))
If @error Then _StringSize_Error(3, 5, $hLabel_Handle, $hDC, $hGUI)
$iLine_Width = DllStructGetData($tSize, "X")
If $iLine_Width >= $iWidth - Int($iSize / 2) Then ExitLoop
Next
If $i > StringLen($asLines[$j]) Then
$iWrap_Count += 1
$avSize_Info[0] &= $sTest_Line & @CRLF
ExitLoop
Else
$iWrap_Count += 1
If $iLast_Word = 0 Then
_StringSize_Error(4, 0, $hLabel_Handle, $hDC, $hGUI)
EndIf
$avSize_Info[0] &= StringLeft($sTest_Line, $iLast_Word) & @CRLF
$asLines[$j] = StringTrimLeft($asLines[$j], $iLast_Word)
$asLines[$j] = StringStripWS($asLines[$j], 1)
EndIf
WEnd
$iLine_Count += $iWrap_Count
DllCall("User32.dll", "int", "ReleaseDC", "hwnd", $hLabel_Handle, "hwnd", $hDC)
If @error Then _StringSize_Error(3, 6, $hLabel_Handle, $hDC, $hGUI)
GUICtrlDelete($hText_Label)
EndIf
Next
$avSize_Info[3] =($iLine_Count * $avSize_Info[1]) + 4
EndIf
GUIDelete($hGUI)
Return $avSize_Info
EndFunc
Func _StringSize_Error($iError, $iExtended, $hLabel_Handle, $hDC, $hGUI)
DllCall("User32.dll", "int", "ReleaseDC", "hwnd", $hLabel_Handle, "hwnd", $hDC)
GUIDelete($hGUI)
Return SetError($iError, $iExtended, 0)
EndFunc
Global $iDef_Toast_Font_Size = _Toast_GetDefFont(0)
Global $sDef_Toast_Font_Name = _Toast_GetDefFont(1)
Global $hToast_Handle = 0
Global $hToast_Close_X = 9999
Global $iToast_Move = 0
Global $iToast_Style = 1
Global $aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8)
Global $iToast_Header_BkCol = $aRet[0]
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5)
Global $iToast_Header_Col = $aRet[0]
Global $iToast_Message_BkCol = $iToast_Header_Col
Global $iToast_Message_Col = $iToast_Header_BkCol
Global $iToast_Font_Size = $iDef_Toast_Font_Size
Global $sToast_Font_Name = $sDef_Toast_Font_Name
Global $iToast_Timer = 0
Global $iToast_Start = 0
Global $fToast_Close = False
Func _Toast_Set($vJust, $iHdr_BkCol = -1, $iHdr_Col = -1, $iMsg_BkCol = -1, $iMsg_Col = -1, $iFont_Size = -1, $sFont_Name = "")
Switch $vJust
Case Default
$iToast_Style = 1
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8)
$iToast_Header_BkCol = $aRet[0]
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5)
$iToast_Header_Col = $aRet[0]
$iToast_Message_BkCol = $iToast_Header_Col
$iToast_Message_Col = $iToast_Header_BkCol
$sToast_Font_Name = $sDef_Toast_Font_Name
$iToast_Font_Size = $iDef_Toast_Font_Size
Return
Case 0, 1, 2, 4, 5, 6
$iToast_Style = $vJust
Case -1
Case Else
Return SetError(1, 1, 0)
EndSwitch
Switch $iHdr_BkCol
Case Default
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8)
$iToast_Header_BkCol = $aRet[0]
Case 0 To 0xFFFFFF
$iToast_Header_BkCol = Int($iHdr_BkCol)
Case -1
Case Else
Return SetError(1, 2, 0)
EndSwitch
Switch $iHdr_Col
Case Default
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 5)
$iToast_Header_Col = $aRet[0]
Case 0 To 0xFFFFFF
$iToast_Header_Col = Int($iHdr_Col)
Case -1
Case Else
Return SetError(1, 3, 0)
EndSwitch
Switch $iMsg_BkCol
Case Default
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8)
$iToast_Message_BkCol = $aRet[0]
Case 0 To 0xFFFFFF
$iToast_Message_BkCol = Int($iMsg_BkCol)
Case -1
Case Else
Return SetError(1, 4, 0)
EndSwitch
Switch $iMsg_Col
Case Default
$aRet = DllCall("User32.dll", "int", "GetSysColor", "int", 8)
$iToast_Message_Col = $aRet[0]
Case 0 To 0xFFFFFF
$iToast_Message_Col = Int($iMsg_Col)
Case -1
Case Else
Return SetError(1, 5, 0)
EndSwitch
Switch $iFont_Size
Case Default
$iToast_Font_Size = $iDef_Toast_Font_Size
Case 8 To 72
$iToast_Font_Size = Int($iFont_Size)
Case -1
Case Else
Return SetError(1, 6, 0)
EndSwitch
Switch $sFont_Name
Case Default
$sToast_Font_Name = $sDef_Toast_Font_Name
Case ""
Case Else
If IsString($sFont_Name) Then
$sToast_Font_Name = $sFont_Name
Else
Return SetError(1, 7, 0)
EndIf
EndSwitch
Return 1
EndFunc
Func _Toast_Show($sTitle, $sMessage, $iDelay = 0, $fWait = True)
Local $nOldOpt = Opt('GUIOnEventMode', 0)
If $hToast_Handle <> 0 Then _Toast_Hide()
$hToast_Close_X = 9999
Local $iToast_Width_max = 500
Local $iToast_Width_min = 150
Local $aLabel_Pos = _StringSize($sMessage, $iToast_Font_Size, Default, Default, $sToast_Font_Name, $iToast_Width_max - 20)
$sMessage = $aLabel_Pos[0]
Local $iLine_Height = $aLabel_Pos[1]
Local $iLabelwidth = $aLabel_Pos[2]
Local $iLabelheight = $aLabel_Pos[3]
Local $iToast_Width = $iLabelwidth + 20
If $iToast_Width < $iToast_Width_min Then
$iToast_Width = $iToast_Width_min
$iLabelwidth = $iToast_Width_min - 20
EndIf
Local $iTitle_Height = 0
If $sTitle = "" Then
If $iDelay < 0 Then $iTitle_Height = 5
Else
$iTitle_Height = $iLine_Height + 2
If $iDelay < 0 Then
If $iTitle_Height < 17 Then $iTitle_Height = 17
EndIf
EndIf
Local $iToast_Height = $iLabelheight + $iTitle_Height + 20
Local $aToast_Data = _Toast_Locate($iToast_Width, $iToast_Height)
$hToast_Handle = GUICreate("", $iToast_Width, $iToast_Height, $aToast_Data[0], $aToast_Data[1], 0x80880000, BitOr(0x00000080, 0x00000008))
If @error Then
$nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
Return SetError(1, 0, -1)
EndIf
GUISetFont($iToast_Font_Size, Default, Default, $sToast_Font_Name)
GUISetBkColor($iToast_Message_BkCol)
Local $iLabel_Style = 0
If BitAND($iToast_Style, 1) = 1 Then
$iLabel_Style = 1
ElseIf BitAND($iToast_Style, 2) = 2 Then
$iLabel_Style = 2
EndIf
If $sTitle <> "" Then
GUICtrlCreateLabel("", 0, 0, $iToast_Width, $iTitle_Height)
GUICtrlSetBkColor(-1, $iToast_Header_BkCol)
GUICtrlSetState(-1, 128)
Local $iTitle_Width = $iToast_Width - 10
If $iDelay < 0 Then
Local $iX_YCoord = Int(($iTitle_Height - 17) / 2)
$hToast_Close_X = GUICtrlCreateLabel("T", $iToast_Width - 18, $iX_YCoord, 17, 17)
GUICtrlSetFont(-1, 14, Default, Default, "Wingdings 2")
GUICtrlSetBkColor(-1, -2)
GUICtrlSetColor(-1, $iToast_Header_Col)
$iTitle_Width -= 18
EndIf
GUICtrlCreateLabel($sTitle, 10, 0, $iTitle_Width, $iTitle_Height, 0x0200)
GUICtrlSetBkColor(-1,$iToast_Header_BkCol)
GUICtrlSetColor(-1, $iToast_Header_Col)
If BitAND($iToast_Style, 4) = 4 Then GUICtrlSetFont(-1, $iToast_Font_Size, 600)
Else
If $iDelay < 0 Then
$hToast_Close_X = GUICtrlCreateLabel("T", $iToast_Width - 18, 0, 17, 17)
GUICtrlSetFont(-1, 14, Default, Default, "Wingdings 2")
GUICtrlSetBkColor(-1, -2)
GUICtrlSetColor(-1, $iToast_Message_Col)
EndIf
EndIf
GUICtrlCreateLabel($sMessage, 10, 10 + $iTitle_Height, $iLabelwidth, $iLabelheight)
GUICtrlSetStyle(-1, $iLabel_Style)
If $iToast_Message_Col <> Default Then GUICtrlSetColor(-1, $iToast_Message_Col)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 1000, "long", $aToast_Data[2])
GUISetState(@SW_SHOWNOACTIVATE, $hToast_Handle)
If $fWait = True Then
Local $iTimeout_Begin = TimerInit()
While 1
If GUIGetMsg() = $hToast_Close_X Or TimerDiff($iTimeout_Begin) / 1000 >= Abs($iDelay) Then ExitLoop
WEnd
ElseIf Abs($iDelay) > 0 Then
$iToast_Timer = Abs($iDelay * 1000)
$iToast_Start = TimerInit()
AdlibRegister("_Toast_Timer_Check", 100)
GUIRegisterMsg(0x0021, "_Toast_WM_EVENTS")
EndIf
$nOldOpt = Opt('GUIOnEventMode', $nOldOpt)
Local $aToast_Data[3] = [$iToast_Width, $iToast_Height, $iLine_Height]
Return $aToast_Data
EndFunc
Func _Toast_Hide()
If $hToast_Handle = 0 Then Return SetError(1, 0, -1)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hToast_Handle, "int", 500, "long", $iToast_Move)
GUIDelete($hToast_Handle)
$hToast_Handle = 0
EndFunc
Func _Toast_Locate($iToast_Width, $iToast_Height)
Local $aToast_Data[3]
Local $iPrevMode = Opt("WinTitleMatchMode", 4)
Local $aTray_Pos = WinGetPos("[CLASS:Shell_TrayWnd]")
Opt("WinTitleMatchMode", $iPrevMode)
If Not IsArray($aTray_Pos) Then Return SetError(2, 0, -1)
If $aTray_Pos[1] > 0 Then
$iToast_Move = 0x00050004
$aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
$aToast_Data[1] = $aTray_Pos[1] - $iToast_Height
$aToast_Data[2] = 0x00040008
Elseif $aTray_Pos[0] > 0 Then
$iToast_Move = 0x00050001
$aToast_Data[0] = $aTray_Pos[0] - $iToast_Width
$aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
$aToast_Data[2] = 0x00040002
ElseIf $aTray_Pos[2] = @DesktopWidth Then
$iToast_Move = 0x00050008
$aToast_Data[0] = @DesktopWidth - $iToast_Width - 10
$aToast_Data[1] = $aTray_Pos[1] + $aTray_Pos[3]
$aToast_Data[2] = 0x00040004
ElseIf $aTray_Pos[3] = @DesktopHeight Then
$iToast_Move = 0x00050002
$aToast_Data[0] = $aTray_Pos[0] + $aTray_Pos[2]
$aToast_Data[1] = @DesktopHeight - $iToast_Height - 10
$aToast_Data[2] = 0x00040001
EndIf
Return $aToast_Data
EndFunc
Func _Toast_Timer_Check()
If TimerDiff($iToast_Start) < $iToast_Timer And $fToast_Close = False Then Return
GUIRegisterMsg(0x0021, "")
AdlibUnRegister("_Toast_Timer_Check")
$fToast_Close = False
_Toast_Hide()
EndFunc
Func _Toast_WM_EVENTS($hWnd, $Msg, $wParam, $lParam)
#forceref $wParam, $lParam
If $hWnd = $hToast_Handle Then
If $Msg = 0x0021 Then
Local $aPos = GUIGetCursorInfo($hToast_Handle)
If $aPos[4] = $hToast_Close_X Then $fToast_Close = True
EndIf
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc
Func _Toast_GetDefFont($iData)
Local $tNONCLIENTMETRICS = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]")
DLLStructSetData($tNONCLIENTMETRICS, 1, DllStructGetSize($tNONCLIENTMETRICS))
DLLCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($tNONCLIENTMETRICS), "ptr", DllStructGetPtr($tNONCLIENTMETRICS), "int", 0)
Local $tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DLLStructGetPtr($tNONCLIENTMETRICS, 15))
Switch $iData
Case 0
Return Int((Abs(DllStructGetData($tLOGFONT, 1)) + 1) * .75)
Case 1
Return DllStructGetData($tLOGFONT, 14)
EndSwitch
EndFunc
Local $sMsg, $hProgress, $aRet[3]
$sMsg = "The message text goes in this area" & @CRLF & @CRLF
$sMsg &= "This Toast uses the System colours and font"
$aRet = _Toast_Show("The Title text goes here", $sMsg, 5)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
_Toast_Hide()
$sMsg = "This Toast uses colours and font defined in a _Toast_Set call." & @CRLF & @CRLF
$sMsg &= "Subsequent Toasts will use these values until they are reset by another _Toast_Set call" & @CRLF & @CRLF
$sMsg &= "The next Toast has a very small message to show the pre-set minimum size"
_Toast_Set(5, 0xFF00FF, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show("User-defined Colours and Bold Header", $sMsg, 10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
_Toast_Hide()
$aRet = _Toast_Show("", "Tiny", 2)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
_Toast_Hide()
$sMsg = "These lines are of medium length" & @CRLF & @CRLF
$sMsg &= "The width is set by the longest" & @CRLF & @CRLF
$sMsg &= "No wrapping occurs here" & @CRLF & @CRLF
$sMsg &= "Note increased font size"
_Toast_Set(-1, -1, -1, -1, -1, 15)
$aRet = _Toast_Show("Mid Width", $sMsg, 5)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
_Toast_Hide()
$sMsg = "This is a long message set to left justified and a much larger font using _Toast_Set" & @CRLF & @CRLF
$sMsg &= "The Toast is automatically set to the maximum preset width and the message text "
$sMsg &= "is wrapped as necessary to fit within the margins of the Toast" & @CRLF & @CRLF
$sMsg &= "The Toast colours and weight have been changed by another _Toast_Set call" & @CRLF & @CRLF
$sMsg &= "Note the closure [X] on the title bar.  This Toast will time out in 30 secs "
$sMsg &= "but clicking the [X] will resume the script immediately"
_Toast_Set(0, -1, 0xFFFF00, 0x00FF00, 0x000000, 15, "Courier New")
$aRet = _Toast_Show("Max Width and Normal Header", $sMsg, -30)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
_Toast_Hide()
$sMsg = "Note how Toasts adjust automatically in height to display all of the message "
$sMsg &= "regardless of whether there is a title bar to display, the font used, "
$sMsg &= "the number of lines or whether wrapping occurs" & @CRLF & @CRLF
$sMsg &= "This Toast will retract automatically when the next Toast is called "
$sMsg &= "or when the [X] is clicked"
_Toast_Set(5, 0xFF00FF, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10, "Arial")
$aRet = _Toast_Show("", $sMsg, -10)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
$sMsg = "This Toast has several blank lines inserted. "
$sMsg &= "This can be useful if you want to leave space to add other controls, "
$sMsg &= "such as a progress bar, to the Toast once it is displayed" & @CRLF & @CRLF & @CRLF & @CRLF
$sMsg &= "The Toast size and line height are returned by the function so you can easily calculate "
$sMsg &= "where to place the other controls.  "
$sMsg &= "This example script writes the size in the SciTE console" & @CRLF & @CRLF
$sMsg &= "Note that Toast colours and font have been reset to Default"
_Toast_Set(Default)
$aRet = _Toast_Show("Progress Bar", $sMsg, 0)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
$hProgress = GUICtrlCreateProgress(10, $aRet[2] * 5.5, $aRet[0] - 20, 20)
For $i = 1 To 100
GUICtrlSetData($hProgress, $i)
Sleep(50)
Next
Sleep(5000)
_Toast_Hide()
$sMsg = "This Toast has the 'Wait' flag set to False. " & @CRLF & @CRLF
$sMsg &= "That means that the script will continue while the Toast is displayed as "
$sMsg &= "as you can see from this counter." & @CRLF & @CRLF & @CRLF
$sMsg &= "Clicking the [X] will retract the Toast immediately but it will "
$sMsg &= "automatically retract after 20 seconds in any event"
_Toast_Set(5, 0xFF00FF, 0xFFFF00, 0x0000FF, 0xFFFFFF, 10)
$aRet = _Toast_Show("Script Continuing", $sMsg, -20, False)
ConsoleWrite("Toast size: " & $aRet[0] & " x " & $aRet[1] & " - " & "Line height: " & $aRet[2] & @CRLF)
$hLabel = GUICtrlCreateLabel("",($aRet[0] - 20) / 2, $aRet[2] * 6, 20, 20)
GUICtrlSetBkColor(-1, -2)
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetFont(-1, 12)
$iCount = 0
Do
$iCount += 1
GUICtrlSetData($hLabel, $iCount)
Sleep(1000)
Until $iCount = 60 Or $hToast_Handle = 0
Exit

For sure there a some more stumbling blocks hidden in the code... and I'm happy about any correction :)... lazy me :idea:...

Overall I think the best would be to include a comparable feature directly in the Obfuscator itself... but that's not up to me :)...

Edit

"Toast" example conversion

/striponly = 17.210 Bytes

/om = 13.423 Bytes

TB v0.14 = 12.824 Bytes

SMF compiled .exe of current dev version

/striponly = 2.540.412 Bytes, scanned 34.000 files in 40 seconds for duplicates

/om = 2.434.598 Bytes, scanned 34.000 files in 40 seconds for duplicates

TB v0.14 = 2.430.890 Bytes, scanned 34.000 files in 38 seconds for duplicates, gain of ~5% in size and speed to /so switch, about ~0,2% compared to /om, not really as much as I would like :), but just had to test it.

I guess it's worth to pre-sort var and func nams by number of occurrence and to assign the shortest names to to most often used names... will try to check that out too :)...

Regards

Edited by KaFu
Link to comment
Share on other sites

Yes, Obfuscator can do this already. The full parameter name is /ObfuscateMinimum

Here's the options you want to use:

#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0

Yeah, I've read that... but I guess I've set the parameters wrong :idea:... didn't thought that the results were so similar, thought Obfuscators results were a little longer. They are by 1 character it seems.

Link to comment
Share on other sites

Link to comment
Share on other sites

Tested the /om switch, and it breaks my script where #Obfuscator_Parameters=/cs=0 /cn=0 /cf=0 /cv=0 /sf=1 /sv=1 doesn't.

Can you post a reproducible script? I'm sure Jos would like to look into it if it's a legitimate error. I've had no problems personally using /om.

edit/

FYI, your params there are the same as just /so (/StripOnly)...

Edited by wraithdu
Link to comment
Share on other sites

Can you post a reproducible script? I'm sure Jos would like to look into it if it's a legitimate error. I've had no problems personally using /om.

SMF 1.1.7.2 compiles fine with /so. If I use /sf /sv /om /cs=0 /cn=0 instead it also compiles, but during the search the progress is not updated anymore. Progress update is triggered by a timer, that's somehow corrupted with the second switch and not the first one.

$gui_SMF_Search_Main_Timer_Progress_Update = _Timer_SetTimer($gui_SMF_Search_Main, 2000, "_Timer_Progress_Update")

Link to comment
Share on other sites

@KaFu

Actually, any type of real obfuscation (not just stripping) will break your script. Your actual timer function name is obfuscated, while the SetTimer function still calls that function by its string name, "_Timer_Progress_Update". You should have seen an Obfuscator warning about this.

Try adding your timer func to the ignore list:

#Obfuscator_Ignore_Funcs=_Timer_Progress_Update

Link to comment
Share on other sites

Why don't you try using AdlibRegister instead, SetTimer is so old fashioned :idea:

I started that script in the old ages when only one adlib was allowed... actually that idea came to my mind yesterday when I posted, will do that :(...

Try adding your timer func to the ignore list:

Ups, you're right :), added all sorts of functions to the ignore list but missed this one. My plan is not to obfuscate the script but just to replace var and func names to minimal length to speed it up... will test that too :)...
Link to comment
Share on other sites

my original-script: 126.976 bytes

after obfuscated_TB: 114.688 bytes

compiled version is smaller too, 131.072 bytes less.

:idea:

but:

in the first step i get this:

-### StripOnly Error: Found ObjEvent() statement using unsolvable Func, which will/could lead to removal of Funcs that are used by the Call() statement.
>### current Func: _IEErrorHandlerRegister
C:\Program Files (x86)\AutoIt3\include\IE.au3(3102,1) Warning for line:$oIEErrorHandler = ObjEvent("AutoIt.Error", $s_functionName) 

-### StripOnly Error: Found ObjEvent() statement using unsolvable Func, which will/could lead to removal of Funcs that are used by the Call() statement.
>### current Func: __IEInternalErrorHandlerDeRegister
C:\Program Files (x86)\AutoIt3\include\IE.au3(3746,1) Warning for line:$oIEErrorHandler = ObjEvent("AutoIt.Error", $sIEUserErrorHandler) 

-#############################################################################################
-#### Obfuscator Found   2 Error(s)!!!!    This means your script could have problems running properly.  ####
-#############################################################################################

and with TB i get some of this:

!   SQLite.au3 Error
--> Function: _SQLite_Exec
--> Query:    INSERT INTO tbl_raw_Vars (Vars) VALUES ("$es_wantreturn");
--> Error:    column Vars is not unique

i will test the tb-compiled script if there are errors.

Edited by andygo
Link to comment
Share on other sites

in the first step i get this:

-### StripOnly Error: Found ObjEvent() statement...

That's an error warning by Obfuscator that it might break the script. I've got that too for the ObjEvent() statements in SMF but it does not seem to break the script. Looking at these special statements I can't see why it should break.

and with TB i get some of this:

!   SQLite.au3 Error
--> Function: _SQLite_Exec
--> Query:    INSERT INTO tbl_raw_Vars (Vars) VALUES ("$es_wantreturn");
--> Error:    column Vars is not unique

That's not a true error. I defined the column Vars as unique, that's why sqlite is complaining if a var which it tries to add already exists... my dirty way to make the extracted list of var and func names unique :idea:, error by design :). In this special case it means $es_wantreturn is already in the database table for vars. I think it's faster then _ArrayUnique() for large number of Vars and Funcs. Will test if adding the names to a temp table and extracting them with a group by statement is faster. Edited by KaFu
Link to comment
Share on other sites

The reason for that Obfuscator warning is this: Obfuscator removes all functions that it finds are not used. In functions such as ObjEvent, Call, Execute, etc. where a function is given as a string, Obfuscator reads these functions names and knows not to remove them. However if you use a runtime variable as the function name, Obfuscator has no way to know what that function name is supposed to be. If the function isn't called explicity from somewhere else, then it will be removed. You can safeguard against this with the #Obfuscator_Ignore_Funcs directive as well.

Edited by wraithdu
Link to comment
Share on other sites

Obfuscator is used as a pre-pre-processor to include all #include files and strip the overall size by deleting unnecessary functions and vars. I'll take a look into adding an optional part that does the inclusion from the original script without stripping (enough samples out there :idea:), then these kind of issues will not occur. Of course then the size is also not reduced to it's possible minimum, but on the other hand the speed should still be improved, your choice.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...