#NoTrayIcon
Global $iAppDefender
Global $sApp_RegKey = 'HKEY_CURRENT_USER\Software\FolderBlocker'
Global $sRun_RegKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run'
Global $sApp_ExePath = '"' & @AutoItExe & '"'
If Not @Compiled Then $sApp_ExePath = '"' & @AutoItExe & '" "' & @ScriptFullPath & '"'
;DEBUG PURPOSE ONLY
;~ $CmdLineRaw &= ' /OnStartup'
If StringInStr($CmdLineRaw, '/OnStartup') Then
$sFolder = RegRead($sApp_RegKey, 'Folder')
$sPass = RegRead($sApp_RegKey, 'Pass')
$hFile = _CreateFile($sFolder)
If $hFile = -1 Then Exit MsgBox(16, "Error", "Unable to open file")
Else
$sFolder = FileSelectFolder("Select the folder", "")
If @error Then Exit
$sPass = InputBox("File security", "Please set a password", "", "*")
If @error Then Exit
$hFile = _CreateFile($sFolder)
If $hFile = -1 Then Exit MsgBox(16, "Error", "Unable to open file")
RegWrite($sApp_RegKey, 'Folder', 'REG_SZ', $sFolder)
RegWrite($sApp_RegKey, 'Pass', 'REG_SZ', $sPass)
RegWrite($sRun_RegKey, 'FolderBlocker', 'REG_SZ', $sApp_ExePath & ' /OnStartup')
EndIf
HotKeySet("^d", "_Decrypt") ;Ctrl + d
OnAutoItExitRegister('_OnExit')
_AppDefender_Init()
While 1
Sleep(100)
WEnd
Func _AppDefender_Init()
Local $sAppDefender_Src, $sAppDefender_File, $sAppDefender_Exe, $hFile
$sAppDefender_Src &= '#NoTrayIcon' & @CRLF
$sAppDefender_Src &= '' & @CRLF
$sAppDefender_Src &= 'If WinExists("_AppDefender_") Then' & @CRLF
$sAppDefender_Src &= ' Exit' & @CRLF
$sAppDefender_Src &= 'EndIf' & @CRLF
$sAppDefender_Src &= '' & @CRLF
$sAppDefender_Src &= 'AutoItWinSetTitle("_AppDefender_")' & @CRLF
$sAppDefender_Src &= '' & @CRLF
$sAppDefender_Src &= 'While 1' & @CRLF
$sAppDefender_Src &= ' If Not ProcessExists(' & @AutoItPID & ') Then' & @CRLF
$sAppDefender_Src &= " Run('" & $sApp_ExePath & " /OnStartup')" & @CRLF
$sAppDefender_Src &= ' Exit' & @CRLF
$sAppDefender_Src &= ' EndIf' & @CRLF
$sAppDefender_Src &= ' ' & @CRLF
$sAppDefender_Src &= ' Sleep(100)' & @CRLF
$sAppDefender_Src &= 'WEnd' & @CRLF
$sAppDefender_File = @TempDir & '\Defender.tmp'
$sAppDefender_Exe = @TempDir & '\System.sys'
FileCopy(@AutoItExe, $sAppDefender_Exe, 1)
$hFile = FileOpen($sAppDefender_File, 2)
FileWrite($hFile, $sAppDefender_Src)
FileClose($hFile)
$iAppDefender = Run($sAppDefender_Exe & ' /AutoIt3ExecuteScript "' & $sAppDefender_File & '"')
AdlibRegister('_AppDefender_KeepAlive', 10)
EndFunc
Func _AppDefender_UnInit()
AdlibUnRegister('_AppDefender_KeepAlive')
ProcessClose($iAppDefender)
$iAppDefender = 0
EndFunc
Func _AppDefender_KeepAlive()
If Not ProcessExists($iAppDefender) Then
_AppDefender_UnInit()
_AppDefender_Init()
EndIf
EndFunc
Func _CreateFile($sFile)
Local Const $GENERIC_READ = 0x80000000
Local Const $GENERIC_WRITE = 0x40000000
Local Const $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
Local Const $OPEN_EXISTING = 3
$sFile = "\\.\" & $sFile
Local $aRet = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", $sFile, "int", BitOR($GENERIC_READ, $GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_FLAG_BACKUP_SEMANTICS, "int", 0)
Return $aRet[0]
EndFunc
Func _Decrypt()
Local $sCurPass = InputBox("File security", "Please enter a password", "", "*")
If @error Then Return 0
If $sCurPass == $sPass Then
DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
MsgBox(64, "Success", "File decrypted")
RegDelete($sApp_RegKey)
RegDelete($sRun_RegKey, 'FolderBlocker')
Exit
Else
MsgBox(16, "Error", "Access denied")
EndIf
EndFunc
Func _OnExit()
_AppDefender_UnInit()
EndFunc