SHARE
TWEET

CryptoDragon Obfuscator with var and func hashing

KekSec Sep 6th, 2019 (edited) 768 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Crypt.au3>
  2. ; Title: CryptoDragon AutoIt Obfuscator
  3. ; Version: v1.4.0.1
  4. ; Requirements: AutoIt Version 3.1.1.0 (Beta is NOT required)
  5. ; Date: November 6th, 2018
  6. ; Authors: Freak, taurus905
  7. ; Purpose: This script obfuscates an AutoIt script by identifying, counting and replacing all
  8. ;          variables and functions within that script, as well as encrypting strings. according to the following notes.
  9. ; Notes: Variables that are all UPPERCASE, such as, $GUI_EVENT_CLOSE, will not be obfuscated.
  10. ;        All strings with single and double quotes are to be encrypted with a multikey XOR algo. (in order)
  11. ;        Add arguments in the "Functions_NOT_to_obfuscate_section:" to bypass these functions.
  12. ;        Uncomment: (in the script)
  13. ;             Global $Show_Messages = "Yes"
  14. ;                  to show Message Boxes and Array Displays during execution.
  15. ; Input:            An AutoIt Script --> OriginalScriptName.au3
  16. ; Output: Variables to be Obfuscated --> OriginalScriptName - Vars to Obfuscate.txt
  17. ;         Functions to be Obfuscated --> OriginalScriptName - Funcs to Obfuscate.txt
  18. ;                       Random Names --> OriginalScriptName - Random Names.txt
  19. ;           CryptoDragon Obfuscated Script --> OriginalScriptName - CryptoDragon Obfuscated.au3
  20. ; Modified by Freak to encrypt all strings in target program with multichar XOR, also added bug fixes.
  21. ; :::ChAnGeLoG::::
  22. ;  v1.2     - Original "Simple Obfuscator" by taurus905
  23. ;  v1.3     - Freak creates CryptoDragon project based off taurus905's "Simple Obfuscator"
  24. ;  v1.3.4   - Added improved speed
  25. ;  v1.3.5.1 - Improved functionality
  26. ;  v1.3.6   - Added string length to _CryptoDragon_Crypt function for improved stability handling funny strings in version
  27. ;  v1.4     - Improved security on encryption algorythm. Also obfuscator automatically writes encryption function to top of file automatically.
  28. ;  v1.4.0.1 - Fixed encrypt function writing process.
  29. ; ===================================================================================================
  30. #include <GUIConstants.au3>
  31. #include <Array.au3>
  32. Func _CryptoDragon_Crypt($s_String, $s_Key, $iLen, $xorK2 = 0x12, $s_Level = 1.337)
  33.     Local $s_Encrypted = "", $fin_Encrypted = "", $s_kc = 1
  34.     If StringLen($s_Key) = 0 Or $s_Level < 1 Then Return 0
  35.     $s_Key = StringSplit($s_Key, '')
  36.     $s_String = StringSplit($s_String, '')
  37.     For $x = 1 To $s_String[0]
  38.         If $s_kc > $s_Key[0] Then $s_kc = 1
  39.         $s_Encrypted = $s_Key[$s_kc]
  40.         $s_Encrypted += Floor(Asc($s_Key[$s_kc]) * $s_Level);
  41.         $s_Encrypted = BitNOT($s_Encrypted);
  42.         $s_Encrypted = BitXOR($s_Encrypted, Floor(Asc($s_Key[$s_kc]) * $s_Level));
  43.         $s_Encrypted += Floor(Asc($s_Key[$s_kc]) * $s_Level);
  44.         $s_Encrypted -= Floor(Asc($s_Key[$s_kc]) * $s_Level);
  45.         $s_Encrypted = BitXOR($s_Encrypted, Floor(Asc($s_Key[$s_kc]) * $s_Level));
  46.         $s_Encrypted = $s_Encrypted - 1;
  47.         $s_Encrypted = BitXOR($s_Encrypted, Floor(Asc($s_Key[$s_kc]) * $s_Level));
  48.         $s_Encrypted = $s_Encrypted + 1;
  49.         $s_Encrypted += Floor(Asc($s_Key[$s_kc]) * $s_Level);
  50.         $s_Encrypted = BitXOR($s_Encrypted, $xorK2);
  51.         $s_Encrypted = BitNOT($s_Encrypted);
  52.         $s_Encrypted += Floor(Asc($s_Key[$s_kc]) * $s_Level);
  53.         $fin_Encrypted &= Chr(BitXOR(Asc($s_String[$x]), Floor(Asc($s_Key[$s_kc]) * $s_Level)))
  54.         $s_kc += 1
  55.     Next
  56.     Return StringLeft($fin_Encrypted, $iLen)
  57. EndFunc   ;==>_CryptoDragon_Crypt
  58. Global $Show_Messages = "No"
  59. ; Uncomment the following line to see progress messages and arrays during execution.
  60. ;Global $Show_Messages = "Yes"
  61. ; ===================================================================================================
  62.  
  63. Global $file_Script_to_Obfuscate
  64. _Choose_Script_to_Obfuscate() ; Choose Script to Obfuscate
  65.  
  66. ; ===================================================================================================
  67. ; Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines
  68.  
  69. Global $Num_of_Lines
  70. _Count_Lines() ; Count Lines of Script to Obfuscate
  71. If $Show_Messages = "Yes" Then MsgBox(0, "$Num_of_Lines", $Num_of_Lines)
  72.  
  73. Global $Array_of_Lines[$Num_of_Lines + 1]
  74. _Read_Lines_to_Array() ; Read Lines to Array
  75. If $Show_Messages = "Yes" Then _ArrayDisplay($Array_of_Lines, "$Array_of_Lines")
  76.  
  77. ; Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines
  78. ; ===================================================================================================
  79. ; Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars
  80.  
  81. Global $Num_of_Vars
  82. _Count_Vars() ; Count Variables in Script to Obfuscate
  83. If $Show_Messages = "Yes" Then MsgBox(0, "$Num_of_Vars", $Num_of_Vars)
  84.  
  85. Global $Array_of_Vars[$Num_of_Vars + 1]
  86. _Read_Vars_to_Array() ; Read Variables to Array
  87. If $Show_Messages = "Yes" Then _ArrayDisplay($Array_of_Vars, "$Array_of_Vars")
  88.  
  89. _Sort_Array_of_Vars() ; Sort Array of Variables
  90. If $Show_Messages = "Yes" Then _ArrayDisplay($Array_of_Vars, "$Array_of_Vars")
  91.  
  92. Global $Num_of_Unique_Vars
  93. _Count_Unique_Vars() ; Count Unique Variables
  94. If $Show_Messages = "Yes" Then MsgBox(0, "$Num_of_Unique_Vars", $Num_of_Unique_Vars)
  95.  
  96. Global $Array_of_Unique_Vars[$Num_of_Unique_Vars + 1]
  97. _Read_Unique_Vars_to_Array() ; Read Unique Variables to Array
  98. If $Show_Messages = "Yes" Then _ArrayDisplay($Array_of_Unique_Vars, "$Array_of_Unique_Vars")
  99.  
  100. _Write_Unique_Vars_to_File() ; Write Unique Variables to File
  101.  
  102. ; Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars
  103. ; ===================================================================================================
  104. ; Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs
  105.  
  106. Global $Num_of_Funcs
  107. _Count_Funcs() ; Count Functions in Script to Obfuscate
  108. If $Show_Messages = "Yes" Then MsgBox(0, "$Num_of_Funcs", $Num_of_Funcs)
  109.  
  110. Global $Array_of_Funcs[$Num_of_Funcs + 1]
  111. _Read_Funcs_to_Array() ; Read Functions to Array
  112. If $Show_Messages = "Yes" Then _ArrayDisplay($Array_of_Funcs, "$Array_of_Funcs")
  113.  
  114. _Sort_Array_of_Funcs() ; Sort Array of Functions
  115. If $Show_Messages = "Yes" Then _ArrayDisplay($Array_of_Funcs, "$Array_of_Funcs")
  116.  
  117. ; Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs
  118. ; ===================================================================================================
  119. ; Random - Random - Random - Random - Random - Random - Random - Random - Random - Random - Random
  120.  
  121. Global $Num_of_Random_Names
  122. _Find_Random_Name_Count() ; Find Random Name Count
  123.  
  124. Global $Random_Name[$Num_of_Random_Names + 1]
  125. _Read_Random_Names_to_Array() ; Read Random Names to Array
  126. If $Show_Messages = "Yes" Then _ArrayDisplay($Random_Name, "$Random_Name")
  127.  
  128. _Write_Random_Names_to_File() ; Write Random Names to File
  129.  
  130. ; Random - Random - Random - Random - Random - Random - Random - Random - Random - Random - Random
  131. ; ===================================================================================================
  132. ; Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace
  133.  
  134. Global $New_Array_of_Lines[$Num_of_Lines + 1]
  135. _Remove_Comments() ; Remove Comments
  136. _ArraySortDblDel($Array_of_Unique_Vars)
  137. _ArraySortDblDel($Array_of_Funcs)
  138. $vars_finished = False
  139. $func_finished = False
  140. $Script_Data = _ArrayToString($Array_of_Lines, @CRLF)
  141. For $iii = 0 To $Num_of_Lines
  142.     For $jjj = UBound($Array_of_Unique_Vars) - 1 To 1 Step -1
  143.         If $vars_finished Then ExitLoop
  144.         If $Array_of_Unique_Vars[$jjj] <> $Array_of_Unique_Vars[1] Then
  145.             If $Array_of_Unique_Vars[$jjj] <> "_" And $Array_of_Unique_Vars[$jjj] <> "$'" And StringLower($Array_of_Unique_Vars[$jjj]) <> "$cmdline" Then
  146.                 If StringInStr($Array_of_Unique_Vars[$jjj], ".") Then
  147.                     $temp = StringSplit($Array_of_Unique_Vars[$jjj], ".")
  148.                     $Array_of_Unique_Vars[$jjj] = $temp[1]
  149.                 EndIf
  150.                 If StringRight($Array_of_Unique_Vars[$jjj], 1) = "&" Then
  151.                     $Array_of_Unique_Vars[$jjj] = StringTrimRight($Array_of_Unique_Vars[$jjj], 1)
  152.                 EndIf
  153.                 $Script_Data = StringReplace($Script_Data, $Array_of_Unique_Vars[$jjj], "$_" &StringTrimLeft( _Crypt_HashData($Array_of_Unique_Vars[$jjj], $CALG_MD4), 2))
  154.                 ConsoleWrite($Array_of_Unique_Vars[$jjj] & ":$_" &StringTrimLeft( _Crypt_HashData($Array_of_Unique_Vars[$jjj], $CALG_MD4), 2) & @CRLF)
  155.             EndIf
  156.         Else
  157.             If $Array_of_Unique_Vars[$jjj] <> "_" And $Array_of_Unique_Vars[$jjj] <> "$'" Then
  158.                 If StringInStr($Array_of_Unique_Vars[$jjj], ".") Then
  159.                     $temp = StringSplit($Array_of_Unique_Vars[$jjj], ".")
  160.                     $Array_of_Unique_Vars[$jjj] = $temp[1]
  161.                 EndIf
  162.                 If StringRight($Array_of_Unique_Vars[$jjj], 1) = "&" Then
  163.                     $Array_of_Unique_Vars[$jjj] = StringTrimRight($Array_of_Unique_Vars[$jjj], 1)
  164.                 EndIf
  165.                 $Script_Data = StringReplace($Script_Data, $Array_of_Unique_Vars[$jjj], "$_" &StringTrimLeft( _Crypt_HashData($Array_of_Unique_Vars[$jjj], $CALG_MD4), 2))
  166.                 ConsoleWrite($Array_of_Unique_Vars[$jjj] & ":$_" &StringTrimLeft( _Crypt_HashData($Array_of_Unique_Vars[$jjj], $CALG_MD4), 2) & @CRLF)
  167.             EndIf
  168.             $vars_finished = True
  169.         EndIf
  170.     Next
  171. Next
  172. For $iii = 0 To $Num_of_Lines
  173.     For $jjj = UBound($Array_of_Funcs) - 1 To 1 Step -1
  174. ;       If StringLeft($Array_of_Funcs[$jjj], 1) = "_" Then ContinueLoop
  175.         If $func_finished Then ExitLoop
  176.         If $Array_of_Funcs[$jjj] <> $Array_of_Funcs[1] Then
  177.             If StringInStr($Array_of_Funcs[$jjj], "=") Then ContinueLoop ; Au3wrapper, not a function.
  178.             $Script_Data = StringReplace($Script_Data, $Array_of_Funcs[$jjj], "_" & StringTrimLeft(StringToBinary( _Crypt_HashData($Array_of_Funcs[$jjj], $CALG_MD4)), 2))
  179.             ConsoleWrite($Array_of_Funcs[$jjj] & ":" & "_" & StringTrimLeft(StringToBinary( _Crypt_HashData($Array_of_Funcs[$jjj], $CALG_MD4)), 2) & @CRLF)
  180.         Else
  181.             If StringInStr($Array_of_Funcs[$jjj], "=") Then
  182.                 $func_finished = True
  183.                 ContinueLoop ; Au3wrapper, not a function.
  184.             EndIf
  185.             $Script_Data = StringReplace($Script_Data, $Array_of_Funcs[$jjj], "_" & StringTrimLeft(StringToBinary( _Crypt_HashData($Array_of_Funcs[$jjj], $CALG_MD4)), 2))
  186.             ConsoleWrite($Array_of_Funcs[$jjj] & ":" & "_" & StringTrimLeft(StringToBinary( _Crypt_HashData($Array_of_Funcs[$jjj], $CALG_MD4)), 2) & @CRLF)
  187.             $func_finished = True
  188.         EndIf
  189.     Next
  190. Next
  191. If $Show_Messages = "Yes" Then _ArrayDisplay($Array_of_Lines, "$New_Array_of_Lines")
  192.  
  193. ; Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace
  194. ; ===================================================================================================
  195.  
  196. _Write_CryptoDragon_Obfuscated_File($Script_Data) ; Write CryptoDragon Obfuscated Script
  197. Exit
  198. Func _ArraySortDblDel(ByRef $ARRAY, $CASESENS=0, $iDESCENDING=0, $iDIM=0, $iSORT=0)
  199.     Local $arTmp1D[1], $arTmp2D[1][2], $dbl = 0
  200.     $arTmp1D[0] = ""
  201.     $arTmp2D[0][0] = ""
  202.     If $iDIM = 0 Then $iDIM = 1
  203.     _ArraySort($ARRAY,$iDESCENDING,0,0,$iDIM,$iSORT)
  204.     Switch $iDIM
  205.         Case 1 ; 1D
  206.             For $i = 0 To UBound($ARRAY)-1
  207.                 $dbl = 0
  208.                 For $k = 0 To UBound($arTmp1D)-1
  209.                     Switch $CASESENS
  210.                         Case 0
  211.                             If $arTmp1D[$k] = $ARRAY[$i] Then $dbl = 1
  212.                         Case 1
  213.                             If $arTmp1D[$k] == $ARRAY[$i] Then $dbl = 1
  214.                     EndSwitch
  215.                 Next
  216.                 If $dbl = 0 Then
  217.                     If $arTmp1D[0] = "" Then
  218.                         $arTmp1D[0] = $ARRAY[$i]
  219.                     Else
  220.                         _ArrayAdd($arTmp1D, $ARRAY[$i])
  221.                     EndIf
  222.                 Else
  223.                     $dbl = 0
  224.                 EndIf
  225.             Next
  226.             $ARRAY = $arTmp1D
  227.         Case 2 ; 2D
  228.             For $i = 0 To UBound($ARRAY)-1
  229.                 $dbl = 0
  230.                 For $k = 0 To UBound($arTmp2D)-1
  231.                     Switch $CASESENS
  232.                         Case 0
  233.                             If  ( $arTmp2D[$k][0] = $ARRAY[$i][0] ) And _
  234.                                 ( $arTmp2D[$k][1] = $ARRAY[$i][1] ) Then $dbl = 1
  235.                         Case 1
  236.                             If  ( $arTmp2D[$k][0] == $ARRAY[$i][0] ) And _
  237.                                 ( $arTmp2D[$k][1] == $ARRAY[$i][1] ) Then $dbl = 1
  238.                     EndSwitch
  239.                 Next
  240.                 If $dbl = 0 Then
  241.                     If $arTmp2D[0][0] = "" Then
  242.                         $arTmp2D[0][0] = $ARRAY[$i][0]
  243.                         $arTmp2D[0][1] = $ARRAY[$i][1]
  244.                     Else
  245.                         ReDim $arTmp2D[UBound($arTmp2D)+1][2]
  246.                         $arTmp2D[UBound($arTmp2D)-1][0] = $ARRAY[$i][0]
  247.                         $arTmp2D[UBound($arTmp2D)-1][1] = $ARRAY[$i][1]
  248.                     EndIf
  249.                 Else
  250.                     $dbl = 0
  251.                 EndIf
  252.             Next
  253.             $ARRAY = $arTmp2D
  254.     EndSwitch
  255. EndFunc ; ==>_ArraySortDblDel
  256. ; ###################################################################################################
  257. ; ===================================================================================================
  258. Func _Choose_Script_to_Obfuscate() ; Choose Script to Obfuscate
  259.     $file_Script_to_Obfuscate = FileOpenDialog("Choose an AutoIt Script to Obfuscate:", @ScriptDir, "Scripts (*.au3)", 1 + 2)
  260.     If @error Then Exit
  261. EndFunc ; ==> _Choose_Script_to_Obfuscate
  262. ; ===================================================================================================
  263. ; Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines
  264. Func _Count_Lines() ; Count Lines of Script to Obfuscate
  265.     FileOpen($file_Script_to_Obfuscate, 0) ; Open File to Obfuscate
  266.     $Num_of_Lines = 0
  267.     While 1
  268.         $Num_of_Lines = $Num_of_Lines + 1
  269.         FileReadLine($file_Script_to_Obfuscate, $Num_of_Lines) ; Read All Lines for Count
  270.         If @error = -1 Then ExitLoop
  271.     WEnd
  272. EndFunc ; ==> _Count_Lines
  273. ; ===================================================================================================
  274. Func _Read_Lines_to_Array() ; Read Lines to Array
  275.     For $iii = 1 To $Num_of_Lines
  276.         $Array_of_Lines[$iii] = FileReadLine($file_Script_to_Obfuscate, $iii) ; Read All Lines
  277.     Next
  278.     FileClose($file_Script_to_Obfuscate) ; Close File to Obfuscate
  279. EndFunc ; ==> _Read_Lines_to_Array
  280. ; Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines - Lines
  281. ; ===================================================================================================
  282. ; Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars
  283. Func _Count_Vars() ; Count Variables in Script to Obfuscate
  284.     $Num_of_Vars = 0
  285.     For $iii = 1 To $Num_of_Lines
  286.         Local $quote_on = "No"
  287.         $Array_of_Lines[0] = $Array_of_Lines[$iii]
  288.         Local $line_length = StringLen($Array_of_Lines[0])
  289.         For $jjj = 1 To $line_length
  290.             Local $char = StringLeft($Array_of_Lines[0], 1)
  291.             If $char = Chr(34) And $quote_on = "No" Then
  292.                 $quote_on = "Yes"
  293.             ElseIf $char = Chr(34) And $quote_on = "Yes" Then
  294.                 $quote_on = "No"
  295.             EndIf
  296.             If $char = ";" And $quote_on = "No" Then ExitLoop
  297.             If $char = "$" And $quote_on = "No" Then $Num_of_Vars = $Num_of_Vars + 1
  298.             $Array_of_Lines[0] = StringTrimLeft($Array_of_Lines[0], 1)
  299.         Next
  300.     Next
  301. EndFunc ; ==> _Count_Vars
  302. ; ===================================================================================================
  303. Func _Read_Vars_to_Array() ; Read Variables to Array
  304.     Local $var_ct = 0
  305.     For $iii = 1 To $Num_of_Lines
  306.         Local $quote_on = "No"
  307.         $Array_of_Lines[0] = $Array_of_Lines[$iii]
  308.         Local $line_length = StringLen($Array_of_Lines[0])
  309.         For $jjj = 1 To $line_length
  310.             Local $char = StringLeft($Array_of_Lines[0], 1)
  311.             If $char = Chr(34) And $quote_on = "No" Then
  312.                 $quote_on = "Yes"
  313.             ElseIf $char = Chr(34) And $quote_on = "Yes" Then
  314.                 $quote_on = "No"
  315.             EndIf
  316.             If $char = ";" And $quote_on = "No" Then ExitLoop
  317.             If $char = "$" And $quote_on = "No" Then ; Read One Variable
  318.                 $var_ct = $var_ct + 1
  319.                 $Array_of_Vars[$var_ct] = ""
  320.                 For $kkk = 1 To 256
  321.                     $char = StringLeft($Array_of_Lines[0], 1)
  322.                     If $char = " " Or _
  323.                             $char = "   " Or _
  324.                             $char = "=" Or _
  325.                             $char = "[" Or _
  326.                             $char = "]" Or _
  327.                             $char = "," Or _
  328.                             $char = ")" Or _
  329.                             $char = ";" Or _
  330.                             $char = "+" Or _
  331.                             $char = "-" Or _
  332.                             $char = "*" Or _
  333.                             $char = "/" Or _
  334.                             $char = Chr(34) Then ExitLoop
  335.                     $Array_of_Vars[$var_ct] = $Array_of_Vars[$var_ct] & $char
  336.                     $Array_of_Lines[0] = StringTrimLeft($Array_of_Lines[0], 1)
  337.                 Next
  338.             EndIf
  339.             $Array_of_Lines[0] = StringTrimLeft($Array_of_Lines[0], 1)
  340.         Next
  341.     Next
  342. EndFunc ; ==> _Read_Vars_to_Array
  343. ; ===================================================================================================
  344. Func _Sort_Array_of_Vars() ; Sort Array of Variables
  345.     _ArraySortDblDel($Array_of_Vars)
  346. EndFunc ; ==> _Sort_Array_of_Vars
  347. ; ===================================================================================================
  348. Func _Count_Unique_Vars() ; Count Unique Variables
  349.     $Num_of_Unique_Vars = 0
  350.     For $iii = 1 To UBound($Array_of_Vars) - 1
  351.         If $Array_of_Vars[$iii] <> $Array_of_Vars[$iii - 1] Then
  352.             If StringIsUpper(StringTrimLeft(StringReplace($Array_of_Vars[$iii], "_", ""), 1)) Then ContinueLoop ; Don't write any system variables that are all UPPERCASE, such as, $GUI_EVENT_CLOSE
  353.             $Num_of_Unique_Vars = $Num_of_Unique_Vars + 1
  354.         EndIf
  355.     Next
  356. EndFunc ; ==> _Count_Unique_Vars
  357. ; ===================================================================================================
  358. Func _Read_Unique_Vars_to_Array() ; Read Unique Variables to Array
  359.     Local $var_unique_ct = 0
  360.     For $iii = 1 To UBound($Array_of_Vars) - 1
  361.         If $Array_of_Vars[$iii] <> $Array_of_Vars[$iii - 1] Then
  362.             If StringIsUpper(StringTrimLeft(StringReplace($Array_of_Vars[$iii], "_", ""), 1)) Then ContinueLoop ; Don't read any System Variables that are all UPPERCASE, such as, $GUI_EVENT_CLOSE
  363.             $var_unique_ct = $var_unique_ct + 1
  364.             $Array_of_Unique_Vars[$var_unique_ct] = $Array_of_Vars[$iii]
  365.         EndIf
  366.     Next
  367. EndFunc ; ==> _Read_Unique_Vars_to_Array
  368. ; ===================================================================================================
  369. Func _Write_Unique_Vars_to_File() ; Write Unique Variables to File
  370.     Local $file_Unique_Vars = StringTrimRight($file_Script_to_Obfuscate, 4) & " - Vars to Obfuscate.txt" ; Create Unique Variables Filename
  371.     FileOpen($file_Unique_Vars, 2) ; Open File to Write Unique Variables
  372.     For $iii = 1 To $Num_of_Unique_Vars
  373.         FileWrite($file_Unique_Vars, $Array_of_Unique_Vars[$iii] & @CRLF)
  374.     Next
  375.     FileClose($file_Unique_Vars) ; Close Unique Variables File
  376. EndFunc ; ==> _Write_Unique_Vars_to_File
  377. ; Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars - Vars
  378. ; ===================================================================================================
  379. ; Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs
  380. Func _Count_Funcs() ; Count Functions in Script to Obfuscate
  381.     $Num_of_Funcs = 0
  382.     For $iii = 1 To $Num_of_Lines
  383.         Local $quote_on = "No"
  384.         Local $var_on = "No"
  385.         Local $func_on = "No"
  386.         $Array_of_Lines[0] = $Array_of_Lines[$iii]
  387.         Local $line_length = StringLen($Array_of_Lines[0])
  388.         For $jjj = 1 To $line_length
  389.             Local $char = StringLeft($Array_of_Lines[0], 1)
  390.             If $char = "(" Or $char = " " Then $func_on = "No"
  391.             If $char = "$" And $quote_on = "No" Then $var_on = "Yes"
  392.             If $char = "@" And $quote_on = "No" Then $var_on = "Yes"
  393.             If $char = "<" And $quote_on = "No" Then $var_on = "Yes"
  394.             If $char = " " And $quote_on = "No" Then $var_on = "No"
  395.             If $char = Chr(34) And $quote_on = "No" Then
  396.                 $quote_on = "Yes"
  397.             ElseIf $char = Chr(34) And $quote_on = "Yes" Then
  398.                 $quote_on = "No"
  399.             EndIf
  400.             If $char = ";" And $quote_on = "No" Then ExitLoop
  401.             If $quote_on = "No" And $func_on = "No" And $var_on = "No" Then
  402.                 $func_on = "Yes"
  403.                 $Num_of_Funcs = $Num_of_Funcs + 1
  404.             EndIf
  405.             $Array_of_Lines[0] = StringTrimLeft($Array_of_Lines[0], 1)
  406.         Next
  407.     Next
  408. EndFunc ; ==> _Count_Funcs
  409. ; ===================================================================================================
  410. Func _Read_Funcs_to_Array() ; Read Functions to Array
  411.     Local $func_ct = 0
  412.     For $iii = 1 To $Num_of_Lines
  413.         Local $quote_on = "No"
  414.         Local $var_on = "No"
  415.         Local $func_on = "No"
  416.         $Array_of_Lines[0] = $Array_of_Lines[$iii]
  417.         Local $line_length = StringLen($Array_of_Lines[0])
  418.         For $jjj = 1 To $line_length
  419.             Local $char = StringLeft($Array_of_Lines[0], 1)
  420.             If $char = "(" Or $char = " " Then $func_on = "No"
  421.             If $char = "$" And $quote_on = "No" Then $var_on = "Yes"
  422.             If $char = "@" And $quote_on = "No" Then $var_on = "Yes"
  423.             If $char = "<" And $quote_on = "No" Then $var_on = "Yes"
  424.             If $char = " " And $quote_on = "No" Then $var_on = "No"
  425.             If $char = Chr(34) And $quote_on = "No" Then
  426.                 $quote_on = "Yes"
  427.             ElseIf $char = Chr(34) And $quote_on = "Yes" Then
  428.                 $quote_on = "No"
  429.             EndIf
  430.             If $char = ";" And $quote_on = "No" Then ExitLoop
  431.             If $char = "_" And $quote_on = "No" And $func_on = "No" And $var_on = "No" Then ; Read One Function
  432.                 $func_ct = $func_ct + 1
  433.                 $Array_of_Funcs[$func_ct] = ""
  434.                 For $kkk = 1 To 256
  435.                     $char = StringLeft($Array_of_Lines[0], 1)
  436.                     If $char = " " Or $char = "(" Then ExitLoop
  437.                     $Array_of_Funcs[$func_ct] = $Array_of_Funcs[$func_ct] & $char
  438.                     $Array_of_Lines[0] = StringTrimLeft($Array_of_Lines[0], 1)
  439.                 Next
  440.                 ; Functions_NOT_to_obfuscate_section:
  441.                 ; Add functions to the following lines that start with an underscore "_" that you
  442.                 ;    do NOT want to be obfuscated. Example:
  443.                 ; If $Array_of_Funcs[$func_ct] = "_ArraySortDblDel" Or _
  444.                 If $Array_of_Funcs[$func_ct] = "_ArraySortDblDel" Or _
  445.                         $Array_of_Funcs[$func_ct] = "_ArrayDisplay" Or _
  446.                         $Array_of_Funcs[$func_ct] = "_ChooseColor" Or _
  447.                         $Array_of_Funcs[$func_ct] = "_ChooseFont" Or _
  448.                         $Array_of_Funcs[$func_ct] = "_ImageGetSize" Or _
  449.                         $Array_of_Funcs[$func_ct] = "_IsPressed" Or _
  450.                         $Array_of_Funcs[$func_ct] = "_StringEncrypt" Or _
  451.                         $Array_of_Funcs[$func_ct] = "_" Then ; Do NOT Count Built-In Functions
  452.                     $func_ct = $func_ct - 1
  453.                 EndIf
  454.             EndIf
  455.             $Array_of_Lines[0] = StringTrimLeft($Array_of_Lines[0], 1)
  456.         Next
  457.     Next
  458. EndFunc ; ==> _Read_Funcs_to_Array
  459. ; ===================================================================================================
  460. Func _Sort_Array_of_Funcs() ; Sort Array of Functions
  461.     _ArraySortDblDel($Array_of_Funcs)
  462. EndFunc ; ==> _Sort_Array_of_Funcs
  463. ; ===================================================================================================
  464. ; Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs - Funcs
  465. ; ===================================================================================================
  466.  
  467. Func _Find_Random_Name_Count() ; Find Random Name Count
  468.     If $Num_of_Unique_Vars > $Num_of_Funcs Then
  469.         $Num_of_Random_Names = $Num_of_Vars
  470.     Else
  471.         $Num_of_Random_Names = $Num_of_Funcs
  472.     EndIf
  473. EndFunc ; ==> _Find_Random_Name_Count
  474. ; ===================================================================================================
  475. Func _Read_Random_Names_to_Array() ; Read Random Names to Array
  476.     Local $random[16]
  477.     For $iii = 1 To $Num_of_Random_Names
  478.         $Random_Name[$iii] = ""
  479.         For $jjj = 1 To Random(4, 15, 1) ; The number of random characters to use in each random name
  480.             $random[$jjj] = Random(48, 122, 1)
  481.             If $random[$jjj] > 64 And $random[$jjj] < 91 Or $random[$jjj] > 96 And $random[$jjj] < 123 Then
  482.                 $Random_Name[$iii] = $Random_Name[$iii] & Chr($random[$jjj])
  483.             Else
  484.                 $jjj = $jjj - 1
  485.                 ContinueLoop
  486.             EndIf
  487.         Next
  488.     Next
  489.     Return $Random_Name
  490. EndFunc ; ==> _Read_Random_Names_to_Array
  491. ; ===================================================================================================
  492. Func _Write_Random_Names_to_File() ; Write Random Names to File
  493.     Local $file_Random_Names = StringTrimRight($file_Script_to_Obfuscate, 4) & " - Random Names.txt" ; Create Random Names Filename
  494.     FileOpen($file_Random_Names, 2) ; Open File to Write Random Names
  495.     For $iii = 1 To $Num_of_Random_Names
  496.         FileWrite($file_Random_Names, $Random_Name[$iii] & @CRLF)
  497.     Next
  498.     FileClose($file_Random_Names) ; Close Random Names File
  499.     Return $Random_Name
  500. EndFunc ; ==> _Write_Random_Names_to_File
  501.  
  502. ; Random - Random - Random - Random - Random - Random - Random - Random - Random - Random - Random
  503. ; ===================================================================================================
  504. ; Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace
  505.  
  506. ; ===================================================================================================
  507. Func _Remove_Comments() ; Remove Comments
  508.     For $iii = 1 To $Num_of_Lines
  509.         Local $quote_on = "No"
  510.         $Array_of_Lines[0] = $Array_of_Lines[$iii]
  511.         Local $line_length = StringLen($Array_of_Lines[0])
  512.         $New_Array_of_Lines[$iii] = ""
  513.         For $jjj = 1 To $line_length
  514.             Local $char = StringLeft($Array_of_Lines[0], 1)
  515.             If $char = Chr(34) And $quote_on = "No" Then
  516.                 $quote_on = "Yes"
  517.             ElseIf $char = Chr(34) And $quote_on = "Yes" Then
  518.                 $quote_on = "No"
  519.             EndIf
  520.             If $char = ";" And $quote_on = "No" Then ExitLoop
  521.             $New_Array_of_Lines[$iii] = $New_Array_of_Lines[$iii] & $char
  522.             $Array_of_Lines[0] = StringTrimLeft($Array_of_Lines[0], 1)
  523.         Next
  524.     Next
  525.     Return $New_Array_of_Lines
  526. EndFunc ; ==> _Remove_Comments
  527.  
  528. ; Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace - Replace
  529. ; ===================================================================================================
  530. Func _StringBetween($S_STRING, $S_START, $S_END, $V_CASE = -1)
  531.     Local $S_CASE = ""
  532.     If $V_CASE = Default Or $V_CASE = -1 Then $S_CASE = "(?i)"
  533.     Local $S_PATTERN_ESCAPE = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)"
  534.     $S_START = StringRegExpReplace($S_START, $S_PATTERN_ESCAPE, "\\$1")
  535.     $S_END = StringRegExpReplace($S_END, $S_PATTERN_ESCAPE, "\\$1")
  536.     If $S_START = "" Then $S_START = "\A"
  537.     If $S_END = "" Then $S_END = "\z"
  538.     Local $A_RET = StringRegExp($S_STRING, "(?s)" & $S_CASE & $S_START & "(.*?)" & $S_END, 3)
  539.     If @error Then Return SetError(1, 0, 0)
  540.     Return $A_RET
  541. EndFunc   ;==>_STRINGBETWEEN
  542. Func _Add_Strings($aList, $AU3, $splitChar)
  543.     Local $doneEncryption = False
  544.     Local $newAU3 = $AU3
  545.     _ArraySortDblDel($aList)
  546.     For $A = 0 To UBound($aList) - 1
  547.         If $aList[$A] <> "" And StringInStr($aList[$A], "_CryptoDragon_Crypt") = False And StringLeft($aList[$A], 1) <> "'" And StringRight($aList[$A], 1) <> "'" And StringLeft($aList[$A], 1) <> '"' And StringRight($aList[$A], 1) <> '"' And StringLen($aList[$A]) > 1 Then
  548.             If StringInStr($aList[$A], @CRLF) Then
  549.                $aList[$A] = StringReplace($aList[$A], @CRLF, "")
  550.             EndIf
  551.             Global $sPass = ""
  552.             Dim $sRndChr[3]
  553.             Local $Digits = Random(4, 15, 1)
  554.             For $i = 1 To $Digits
  555.                  $sRndChr[0] = Chr(Random(65, 90, 1))
  556.                  $sRndChr[1] = Chr(Random(97, 122, 1))
  557.                  $sRndChr[2] = Chr(Random(48, 57, 1))
  558.                  $sPass &= $sRndChr[Random(0, 2, 1)]
  559.             Next
  560.             If StringLen($aList[$A]) >= 2000 Then
  561.                ContinueLoop
  562.             EndIf
  563.             If StringInStr($aList[$A], "&") Then
  564.                 If StringRight($aList[$A], 1) = "&" Then
  565.                     $newAU3 = StringReplace($newAU3, $splitChar & StringTrimRight($aList[$A], 1) & $splitChar, " & _CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimRight($aList[$A], 1), $sPass, StringLen(StringTrimRight($aList[$A], 1)))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A]) - 1) & ")&")
  566.                     ConsoleWrite($splitChar & StringTrimRight($aList[$A], 1) & $splitChar & ":_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimRight($aList[$A], 1), $sPass, StringLen(StringTrimRight($aList[$A], 1)))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A]) - 1) & ")&" & @CRLF)
  567.                 ElseIf StringRight($aList[$A], 2) = "& " Then
  568.                     $newAU3 = StringReplace($newAU3, $splitChar & StringTrimRight($aList[$A], 2) & $splitChar, "_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimRight($aList[$A], 2), $sPass, StringLen(String($aList[$A]) - 2))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A]) - 2) & ") & ")
  569.                     ConsoleWrite($splitChar & StringTrimRight($aList[$A], 2) & $splitChar & ":_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimRight($aList[$A], 2), $sPass, StringLen(String($aList[$A]) - 2))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A]) - 2) & ") &" & @CRLF)
  570.                 ElseIf StringLeft($aList[$A], 1) = "&" Then
  571.                     $newAU3 = StringReplace($newAU3, $splitChar & StringTrimLeft($aList[$A], 1) & $splitChar, "&_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimLeft($aList[$A], 2), $sPass, StringLen(String($aList[$A]) - 1))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A]) - 1) & ")")
  572.                     ConsoleWrite($splitChar & StringTrimLeft($aList[$A], 1) & $splitChar & ":&_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimLeft($aList[$A], 1), $sPass, StringLen(String($aList[$A]) - 1))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A]) - 1) & ")" & @CRLF)
  573.                 ElseIf StringLeft($aList[$A], 2) = " &" Then
  574.                     $newAU3 = StringReplace($newAU3, $splitChar & StringTrimLeft($aList[$A], 2) & $splitChar, " & _CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimLeft($aList[$A], 2), $sPass, StringLen(String($aList[$A]) - 2))) & "'), BinaryToString('" & StringToBinary($sPass) & "'))")
  575.                     ConsoleWrite($splitChar & StringTrimLeft($aList[$A], 2) & $splitChar & ": & _CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt(StringTrimLeft($aList[$A], 2), $sPass, StringLen(String($aList[$A]) - 2))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A]) - 2) & ")" & @CRLF)
  576.                 Else
  577.                     $newAU3 = StringReplace($newAU3, $splitChar & $aList[$A] & $splitChar, "_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt($aList[$A], $sPass, StringLen($aList[$A]))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A])) & ")")
  578.                     ConsoleWrite($splitChar & $aList[$A] & $splitChar & ":_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt($aList[$A], $sPass, StringLen($aList[$A]))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A])) & ")" & @CRLF)
  579.                 EndIf
  580.             Else
  581.                 $newAU3 = StringReplace($newAU3, $splitChar & $aList[$A] & $splitChar, "_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt($aList[$A], $sPass, StringLen($aList[$A]))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & StringLen($aList[$A]) & ")")
  582.                 ConsoleWrite($splitChar & $aList[$A] & $splitChar & ":_CryptoDragon_Crypt(BinaryToString('" & StringToBinary(_CryptoDragon_Crypt($aList[$A], $sPass, StringLen($aList[$A]))) & "'), BinaryToString('" & StringToBinary($sPass) & "'), " & String(StringLen($aList[$A])) & ")" & @CRLF)
  583.             EndIf
  584.         EndIf
  585.     Next
  586.     Return $newAU3
  587. EndFunc   ;==>_ADD_STRINGS
  588. Func base64($vCode, $bEncode = True, $bUrl = False)
  589.     Local $oDM = ObjCreate("Microsoft.XMLDOM")
  590.     If Not IsObj($oDM) Then Return SetError(1, 0, 1)
  591.     Local $oEL = $oDM.createElement("Tmp")
  592.     $oEL.DataType = "bin.base64"
  593.     If $bEncode then
  594.         $oEL.NodeTypedValue = Binary($vCode)
  595.         If Not $bUrl Then Return $oEL.Text
  596.         Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "")
  597.     Else
  598.         If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/")
  599.         $oEL.Text = $vCode
  600.         Return BinaryToString($oEL.NodeTypedValue, 4)
  601.     EndIf
  602. EndFunc ;==>base64
  603. Func _Encrypt_Strings($AU3, $file_Simple_Obfuscated)
  604.     Local $sSTRINGS = _StringBetween($AU3, "'", "'")
  605.     Local $newAU3 = _Add_Strings($sSTRINGS, $AU3, "'")
  606.     Local $dSTRINGS = _StringBetween($newAU3, '"', '"')
  607.     Local $epicAU3 = _Add_Strings($dSTRINGS, $newAU3, '"')
  608.     Local $fileHandle = FileOpen($file_Simple_Obfuscated, 18)
  609.     FileWrite($fileHandle, base64("RnVuYyBfQ3J5cHRvRHJhZ29uX0NyeXB0KCRzX1N0cmluZywgJHNfS2V5LCAkaUxlbiwgJHhvcksyID0gMHgxMiwgJHNfTGV2ZWwgPSAxLjMzNykKCUxvY2FsICRzX0VuY3J5cHRlZCA9ICIiLCAkZmluX0VuY3J5cHRlZCA9ICIiLCAkc19rYyA9IDEKCUlmIFN0cmluZ0xlbigkc19LZXkpID0gMCBPciAkc19MZXZlbCA8IDEgVGhlbiBSZXR1cm4gMAoJJHNfS2V5ID0gU3RyaW5nU3BsaXQoJHNfS2V5LCAnJykKCSRzX1N0cmluZyA9IFN0cmluZ1NwbGl0KCRzX1N0cmluZywgJycpCglGb3IgJHggPSAxIFRvICRzX1N0cmluZ1swXQoJCUlmICRzX2tjID4gJHNfS2V5WzBdIFRoZW4gJHNfa2MgPSAxCgkJJHNfRW5jcnlwdGVkID0gJHNfS2V5WyRzX2tjXQoJCSRzX0VuY3J5cHRlZCArPSBGbG9vcihBc2MoJHNfS2V5WyRzX2tjXSkgKiAkc19MZXZlbCk7CgkJJHNfRW5jcnlwdGVkID0gQml0Tk9UKCRzX0VuY3J5cHRlZCk7CgkJJHNfRW5jcnlwdGVkID0gQml0WE9SKCRzX0VuY3J5cHRlZCwgRmxvb3IoQXNjKCRzX0tleVskc19rY10pICogJHNfTGV2ZWwpKTsKCQkkc19FbmNyeXB0ZWQgKz0gRmxvb3IoQXNjKCRzX0tleVskc19rY10pICogJHNfTGV2ZWwpOwoJCSRzX0VuY3J5cHRlZCAtPSBGbG9vcihBc2MoJHNfS2V5WyRzX2tjXSkgKiAkc19MZXZlbCk7CgkJJHNfRW5jcnlwdGVkID0gQml0WE9SKCRzX0VuY3J5cHRlZCwgRmxvb3IoQXNjKCRzX0tleVskc19rY10pICogJHNfTGV2ZWwpKTsKCQkkc19FbmNyeXB0ZWQgPSAkc19FbmNyeXB0ZWQgLSAxOwoJCSRzX0VuY3J5cHRlZCA9IEJpdFhPUigkc19FbmNyeXB0ZWQsIEZsb29yKEFzYygkc19LZXlbJHNfa2NdKSAqICRzX0xldmVsKSk7CgkJJHNfRW5jcnlwdGVkID0gJHNfRW5jcnlwdGVkICsgMTsKCQkkc19FbmNyeXB0ZWQgKz0gRmxvb3IoQXNjKCRzX0tleVskc19rY10pICogJHNfTGV2ZWwpOwoJCSRzX0VuY3J5cHRlZCA9IEJpdFhPUigkc19FbmNyeXB0ZWQsICR4b3JLMik7CgkJJHNfRW5jcnlwdGVkID0gQml0Tk9UKCRzX0VuY3J5cHRlZCk7CgkJJHNfRW5jcnlwdGVkICs9IEZsb29yKEFzYygkc19LZXlbJHNfa2NdKSAqICRzX0xldmVsKTsKCQkkZmluX0VuY3J5cHRlZCAmPSBDaHIoQml0WE9SKEFzYygkc19TdHJpbmdbJHhdKSwgRmxvb3IoQXNjKCRzX0tleVskc19rY10pICogJHNfTGV2ZWwpKSkKCQkkc19rYyArPSAxCglOZXh0CglSZXR1cm4gU3RyaW5nTGVmdCgkZmluX0VuY3J5cHRlZCwgJGlMZW4pCkVuZEZ1bmMgICA7PT0+X0NyeXB0b0RyYWdvbl9DcnlwdA==", False))
  610.     FileWrite($fileHandle, $epicAU3)
  611.     FileClose($fileHandle)
  612. EndFunc   ;==>_ENCRYPT_STRINGS
  613. Func _Write_CryptoDragon_Obfuscated_File($AU3) ; Write CryptoDragon Obfuscated File
  614.     Local $file_Simple_Obfuscated = StringTrimRight($file_Script_to_Obfuscate, 4) & " - CryptoDragon Obfuscated.au3" ; Create CryptoDragon Obfuscated Filename
  615.     _Encrypt_Strings($AU3, $file_Simple_Obfuscated)
  616. EndFunc ; ==> _Write_CryptoDragon_Obfuscated_File
  617. ; ===================================================================================================
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top