AutoIt - VNCKeyProtector.au3

;------------------------------------------
; VNC Connection Protector
; von Wolfgang Führer
;------------------------------------------
 
Global $g_title = "VNC Key Protector"
Global $g_version = "Version 0.9 beta"
Global $g_masterpass = "" ;password to encrypt and decrypt all files
Global $g_defext = ".vkd" ;profile definition file encrypted
Global $g_keyext = ".vkk" ;profile key file encrypted
Global $g_noteext = ".vkn" ;profile note file encrypted
Global $g_safepath = @ScriptDir & "\ConnectionSafe"
Global $g_openpath = @ScriptDir & "\OpenConnections"
Global $g_pass = ""
Global $g_waitcount = 1
Global $g_waitstring = "... waiting for input ..."
Global $g_waitdelay = 2
 
Global $g_infotext = " " & @CRLF & _
"                 " & $g_title & " - " & $g_version & @CRLF & _
"                             by Wolfgang Führer" & @CRLF & _ 
"                     http://www.wolfgang-fuehrer.de" & @CRLF & @CRLF & _
"---------------------------------------------------------------------------      " & @CRLF & @CRLF & _
"                 For VNC see http://www.ultravnc.org" & @CRLF & _
"Dlock2 by Michael Paul Johnson - see http://cryptography.org" & @CRLF & _
"    For DSM-Plugin see http://msrc4plugin.home.comcast.net" & @CRLF & @CRLF & _
"---------------------------------------------------------------------------" & @CRLF & @CRLF & _		
"                      See helpfile for more infos."
 
If Not FileExists(@ScriptDir & "\Bin") Then DirCreate(@ScriptDir & "\Bin\")
FileInstall("E:\AutoIt_Projects\VNCkeyProtector\Bin\help_de.htm", @ScriptDir & "\Bin\",1)
FileInstall("E:\AutoIt_Projects\VNCkeyProtector\Bin\help_en.htm", @ScriptDir & "\Bin\",1)
FileInstall("E:\AutoIt_Projects\VNCkeyProtector\Bin\VNCkp.jpg", @ScriptDir & "\Bin\",1)
If Not FileExists(@ScriptDir & "\Bin\dlock2.exe") Then
    FileInstall("E:\AutoIt_Projects\VNCkeyProtector\Bin\dlock2.exe", @ScriptDir & "\Bin\")
EndIf
If Not FileExists(@ScriptDir & "\Bin\msrc4plugin_noreg.dsm") Then
    FileInstall("E:\AutoIt_Projects\VNCkeyProtector\Bin\msrc4plugin_noreg.dsm", @ScriptDir & "\Bin\")
EndIf
If Not FileExists(@ScriptDir & "\Bin\vncviewer.exe") Then
    FileInstall("E:\AutoIt_Projects\VNCkeyProtector\Bin\vncviewer.exe", @ScriptDir & "\Bin\")
EndIf
 
If Not FileExists($g_safepath) Then DirCreate($g_safepath)
 
#region GUI
#include <GUIConstants.au3>
; == GUI generated with Koda ==
$VNCkp = GUICreate("VNC Key Protector", 336, 346, 206, 124)
GUICtrlCreateLabel("Profile:", 16, 58, 35, 17)
$in_profilename = GUICtrlCreateInput("", 64, 56, 185, 21, -1, $WS_EX_CLIENTEDGE)
$bt_buttonload = GUICtrlCreateButton("Load ...", 256, 56, 63, 22)
$Tab1 = GUICtrlCreateTab(16, 96, 305, 177)
$tab_horst = GUICtrlCreateTabItem("Host")
GUICtrlCreateLabel("Server:", 36, 146, 38, 17)
$in_hostinput = GUICtrlCreateInput("IP or URL", 92, 144, 201, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Display:", 36, 178, 41, 17)
$in_displayinput = GUICtrlCreateInput("0", 92, 176, 73, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Password:", 36, 218, 53, 17)
$in_password = GUICtrlCreateInput("", 92, 216, 129, 21, $ES_PASSWORD, $WS_EX_CLIENTEDGE)
$tab_dsm = GUICtrlCreateTabItem("DSM")
$bt_buttonopen = GUICtrlCreateButton("Load Keyfile ...", 92, 144, 89, 23)
GUICtrlCreateLabel("Keyfile:", 36, 186, 38, 17)
$in_keyfilepath = GUICtrlCreateInput("", 92, 184, 201, 21, -1, $WS_EX_CLIENTEDGE)
$ck_usedsm = GUICtrlCreateCheckbox("use DSM Plugin", 92, 222, 97, 17)
 
$tab_color = GUICtrlCreateTabItem("Color/Size")
$gr_color = GUICtrlCreateGroup("Color", 32, 128, 113, 137)
$rd_gray8 = GUICtrlCreateRadio("8 grey", 56, 152, 73, 17)
$rd_color8 = GUICtrlCreateRadio("8 color", 56, 176, 73, 17)
$rd_color256 = GUICtrlCreateRadio("256 color", 56, 200, 73, 17)
$rd_color8bit = GUICtrlCreateRadio("8 bit", 56, 232, 73, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$gr_size = GUICtrlCreateGroup("Size", 168, 128, 137, 137)
$rd_autoscale = GUICtrlCreateRadio("Autoscale", 184, 152, 113, 17)
$rd_fullscreen = GUICtrlCreateRadio("Fullscreen", 184, 176, 113, 17)
$rd_serverscale = GUICtrlCreateRadio("Serverscale ", 184, 200, 75, 17)
$in_sscale = GUICtrlCreateInput("2", 264, 200, 17, 21, -1, $WS_EX_CLIENTEDGE)
$in_scaleb = GUICtrlCreateInput("4", 264, 232, 17, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("/", 254, 234, 9, 17)
$in_scalea = GUICtrlCreateInput("3", 232, 232, 17, 21, -1, $WS_EX_CLIENTEDGE)
$rd_scale = GUICtrlCreateRadio("Scale", 184, 232, 45, 17)
 
$tab_options = GUICtrlCreateTabItem("Options")
$ck_viewonly = GUICtrlCreateCheckbox("view only", 52, 144, 73, 17)
$ck_notoolbar = GUICtrlCreateCheckbox("no toolbar", 172, 144, 65, 17)
$ck_nostatus = GUICtrlCreateCheckbox("no status", 172, 176, 65, 17)
$ck_nohotkeys = GUICtrlCreateCheckbox("no hotkeys", 172, 208, 73, 17)
$ck_emulate3 = GUICtrlCreateCheckbox("emulate 3", 52, 176, 73, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$tab_proxy = GUICtrlCreateTabItem("Proxy")
GUICtrlCreateLabel("Proxy:", 40, 176, 33, 17)
$in_proxy = GUICtrlCreateInput("", 96, 176, 201, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel("Port:", 40, 208, 26, 17)
$in_port = GUICtrlCreateInput("", 96, 208, 121, 21, -1, $WS_EX_CLIENTEDGE)
$ck_ieset = GUICtrlCreateCheckbox("Use Internetexplorer Settings", 96, 136, 185, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
$ck_proxy = GUICtrlCreateCheckbox("Use Proxy Settings", 96, 240, 161, 17)
$tab_note = GUICtrlCreateTabItem("Note")
$ed_notetext = GUICtrlCreateEdit("", 36, 136, 265, 121, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetData($ed_notetext, "notetext")
GUICtrlCreateTabItem("")
$bt_exit = GUICtrlCreateButton("Exit", 16, 288, 59, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$bt_help = GUICtrlCreateButton("?", 88, 288, 40, 25)
$bt_connect = GUICtrlCreateButton("Connect", 232, 288, 88, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
$bt_save = GUICtrlCreateButton("Save Profile", 140, 288, 80, 25)
$lb_status = GUICtrlCreateLabel(" ", 2, 327, 332, 17, BitOR($SS_CENTER, $SS_SUNKEN))
$Pic1 = GUICtrlCreatePic(".\Bin\VNCkp.jpg", 16, 8, 303, 40)
GUISetState(@SW_SHOW)
GUICtrlSetState($in_profilename, $GUI_FOCUS)
#endregion
 
;make working dir
DirCreate($g_openpath)
 
While 1
    ;get gui event
    $msg = GUIGetMsg()
    ;some tests
    If $g_masterpass = "" Then
        GUICtrlSetData($lb_status, "Masterpassword is needed")
        $g_masterpass = InputBox("Masterpassword", "Please insert Masterpassword", "", "*", -1, 70)
        If @error = 1 Then
            Exit
        EndIf
        GUICtrlSetData($lb_status, " ")
    EndIf
    ;no space in profilename
    $g_profile = GUICtrlRead($in_profilename)
    If StringInStr($g_profile, " ") > 0 Then
        MsgBox(0, "Profile error", "A space in profilename is not supported!")
        $g_profile = StringLeft($g_profile, StringLen($g_profile) - 1)
        GUICtrlSetData($in_profilename, $g_profile)
    EndIf
    ;no space in password
    $g_pass = GUICtrlRead($in_password)
    If StringInStr($g_pass, " ") > 0 Then
        MsgBox(0, "Passworde error", "A space in password is not supported!")
        $g_pass = StringLeft($g_pass, "")
        GUICtrlSetData($in_password, $g_pass)
    EndIf
    ;no save possible without profile name
    if ($g_profile = "") Then
        GUICtrlSetState($bt_save, $GUI_DISABLE)
    Else
        GUICtrlSetState($bt_save, $GUI_ENABLE)
    EndIf
    ;no proxy use without parameter
    If StringLen(GUICtrlRead($in_proxy)) > 0 And Int(GUICtrlRead($in_port)) > 0 Then
        GUICtrlSetState($ck_proxy, $GUI_ENABLE)
    Else
        GUICtrlSetState($ck_proxy, $GUI_DISABLE)
    EndIf
    ;no dsm use without parameter
    If StringLen(GUICtrlRead($in_keyfilepath)) > 9 Then
        GUICtrlSetState($ck_usedsm, $GUI_ENABLE)
    Else
        GUICtrlSetState($ck_usedsm, $GUI_DISABLE)
    EndIf
 
    ;gui action
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $bt_exit
            GUICtrlSetData($lb_status, "Closing application")
			;remove all decrypted files
			DirRemove($g_openpath, 1)
            ExitLoop
		Case $msg = $bt_help
            _Help()
        Case $msg = $bt_buttonopen
            GUICtrlSetData($lb_status, "Loading keyfile")
            _OpenKey()
            GUICtrlSetData($lb_status, " ")
        Case $msg = $bt_buttonload
            GUICtrlSetData($lb_status, "Loading profile")
            _LoadProfile()
            GUICtrlSetData($lb_status, " ")
        Case $msg = $bt_save
            GUICtrlSetData($lb_status, "Saving profile")
            _SaveProfile()
            GUICtrlSetData($lb_status, " ")
        Case $msg = $bt_connect
            GUICtrlSetData($lb_status, "Connecting")
            _Connect()
            GUICtrlSetData($lb_status, " ")
        Case Else
            ;;;;;;;
    EndSelect
    Sleep(250)
	$g_waitcount = $g_waitcount + 1
	if $g_waitcount > StringLen($g_waitstring)*$g_waitdelay then $g_waitcount = 1
	GUICtrlSetData($lb_status, StringLeft($g_waitstring,$g_waitcount/$g_waitdelay))
	;GUICtrlSetData($lb_status, $g_wait)
WEnd
 
Exit
 
; ############### Functions ###############
 
Func _Connect()
    Local $l_url = GUICtrlRead($in_hostinput)
    Local $l_display = GUICtrlRead($in_displayinput)
    Local $l_pass = GUICtrlRead($in_password)
    Local $l_dsmplug = ""
    Local $l_color = ""
    Local $l_size = ""
    Local $l_opt = ""
    Local $l_proxy = ""
    Local $l_string = ""
    Local $l_workingdir = $g_openpath & "\" & $g_profile
 
    If GUICtrlRead($ck_usedsm) == $GUI_CHECKED Then $l_dsmplug = " /dsmplugin ..\..\msrc4plugin_noreg.dsm"
    $l_string = $l_string & $l_dsmplug & " /server " & $l_url & ":" & $l_display
 
    If GUICtrlRead($rd_gray8) == $GUI_CHECKED Then $l_color = " /8greycolors"
    If GUICtrlRead($rd_color8) == $GUI_CHECKED Then $l_color = " /8colors"
    If GUICtrlRead($rd_color256) == $GUI_CHECKED Then $l_color = " /256colors"
    If GUICtrlRead($rd_color8bit) == $GUI_CHECKED Then $l_color = " /8bit"
    $l_string = $l_string & $l_color
 
    If GUICtrlRead($rd_autoscale) == $GUI_CHECKED Then $l_size = " /autoscaling"
    If GUICtrlRead($rd_fullscreen) == $GUI_CHECKED Then $l_size = " /fullscreen"
    If GUICtrlRead($rd_serverscale) == $GUI_CHECKED Then $l_size = " /serverscale " & GUICtrlRead($in_sscale)
    If GUICtrlRead($rd_serverscale) == $GUI_CHECKED Then
        $l_size = " /scale " & GUICtrlRead($in_scalea) & "/" & GUICtrlRead($in_scaleb)
    EndIf
    $l_string = $l_string & $l_size
 
    If GUICtrlRead($ck_viewonly) == $GUI_CHECKED Then $l_opt = $l_opt & " /viewonly"
    If GUICtrlRead($ck_notoolbar) == $GUI_CHECKED Then $l_opt = $l_opt & " /notoolbar"
    If GUICtrlRead($ck_nostatus) == $GUI_CHECKED Then $l_opt = $l_opt & " /nostatus"
    If GUICtrlRead($ck_nohotkeys) == $GUI_CHECKED Then $l_opt = $l_opt & " /nohotkeys"
    If GUICtrlRead($ck_emulate3) == $GUI_CHECKED Then $l_opt = $l_opt & " /emulate3"
    $l_string = $l_string & $l_opt
 
    If GUICtrlRead($ck_proxy) == $GUI_CHECKED Then
        $l_proxy = " /proxy"
        $l_proxy = $l_proxy & " " & GUICtrlRead($in_proxy) & ":" & GUICtrlRead($in_port)
        $l_string = $l_string & $l_proxy
    EndIf
 
 
    $l_string = $l_string & " /password " & $l_pass
    ;set current working dir
 
    FileChangeDir($l_workingdir)
	;debug for openconnection path
    ;MsgBox(0, "", $g_openpath & "\" & $g_profile)
	;debug for connect string
    ;MsgBox(0, "", '..\..\vncviewer.exe ' & $l_string)
    GUICtrlSetData($lb_status, "Connecting ..." & $g_profile)
    _RunDOS('..\..\Bin\vncviewer.exe ' & $l_string, $l_workingdir)
    FileChangeDir(@ScriptDir)
EndFunc   ;==>_Connect
 
Func _OpenKey()
    Local $l_data_keypath = FileOpenDialog("Search Keyfile", "c:\", "Keyfiles (*.key)", 3)
    If $l_data_keypath = "1" Then $l_data_keypath = ""
    GUICtrlSetData($in_keyfilepath, $l_data_keypath)
EndFunc   ;==>_OpenKey
 
Func _LoadProfile()
    Local $l_inifile
    Local $l_note = ""
    Local $l_handle
    Local $l_savepass = ""
    Local $l_flag = ""
    Local $l_tempdir
    Local $l_data_profile = FileOpenDialog("Search Profile", $g_safepath, "Profiles (*" & $g_defext & ")", 3)
    If $l_data_profile = "1" Then $l_data_profile = ""
    $g_profile = _GetProfileName($l_data_profile)
    GUICtrlSetData($in_profilename, $g_profile)
    $l_tempdir = $g_openpath & "\" & $g_profile
    If Not FileExists($l_tempdir) Then DirCreate($l_tempdir)
    $l_inifile = $l_tempdir & '\' & $g_profile & '.ini'
 
    GUICtrlSetData($lb_status, "Decrypting definition file")
    $l_savepass = $g_masterpass ;save masterpassword
    Do
        _Decrypt_def($l_data_profile)
        ;test if password was ok
        If IniRead($l_inifile, 'main', 'title', 'defect') <> $g_title Then
            ;set new masterpass
            $g_masterpass = InputBox("Other password needed", _
		         "Decryption failed - please try other password!", "", "*", -1, 70)
            $l_flag = @error
        EndIf
    Until (IniRead($l_inifile, 'main', 'title', 'defect') == $g_title) or ($l_flag == 1)
    ;password ok - then decrypt keyfile if availiable
    If $l_flag <> 1 Then
        If FileExists($g_safepath & "\" & $g_profile & $g_keyext) Then
            _Decrypt_key()
            If FileExists($g_openpath & "\" & $g_profile & "\rc4.key") Then
                GUICtrlSetData($in_keyfilepath, $g_openpath & "\" & $g_profile & "\rc4.key")
            EndIf
        EndIf
        If FileExists($g_safepath & "\" & $g_profile & $g_noteext) Then
            _Decrypt_note()
            If FileExists($g_openpath & "\" & $g_profile & "\" & $g_profile & ".txt") Then
                $l_handle = FileOpen($g_openpath & "\" & $g_profile & "\" & $g_profile & ".txt", 0)
                $l_note = FileRead($l_handle, FileGetSize($g_openpath & "\" & $g_profile & "\" & $g_profile & ".txt"))
                GUICtrlSetData($ed_notetext, $l_note)
                FileClose($l_handle)
            EndIf
        EndIf
 
 
        If IniRead($l_inifile, 'main', 'dsm', '0') == 1 Then
            GUICtrlSetState($ck_usedsm, $GUI_CHECKED)
        Else
            GUICtrlSetState($ck_usedsm, $GUI_UNCHECKED)
        EndIf
 
        ;GUICtrlSetData($ed_notetext, IniRead($file, 'main', 'note', ''))
        GUICtrlSetData($in_hostinput, IniRead($l_inifile, 'host', 'server', 'missing'))
        GUICtrlSetData($in_displayinput, IniRead($l_inifile, 'host', 'display', '0'))
        GUICtrlSetData($in_password, IniRead($l_inifile, 'host', 'password', ''))
 
        If IniRead($l_inifile, 'colordepth', 'gray8', '0') == 1 Then
            GUICtrlSetState($rd_gray8, $GUI_CHECKED)
        EndIf
        If IniRead($l_inifile, 'colordepth', 'color8', '0') == 1 Then
            GUICtrlSetState($rd_color8, $GUI_CHECKED)
        EndIf
        If IniRead($l_inifile, 'colordepth', 'color256', '0') == 1 Then
            GUICtrlSetState($rd_color256, $GUI_CHECKED)
        EndIf
        If IniRead($l_inifile, 'colordepth', 'color8bit', '0') == 1 Then
            GUICtrlSetState($rd_color8bit, $GUI_CHECKED)
        EndIf
 
        If IniRead($l_inifile, 'size', 'autoscale', '0') == 1 Then
            GUICtrlSetState($rd_autoscale, $GUI_CHECKED)
        EndIf
        If IniRead($l_inifile, 'size', 'fullscreen', '0') == 1 Then
            GUICtrlSetState($rd_fullscreen, $GUI_CHECKED)
        EndIf
        If IniRead($l_inifile, 'size', 'serverscale', '0') == 1 Then
            GUICtrlSetState($rd_serverscale, $GUI_CHECKED)
        EndIf
        GUICtrlSetData($in_sscale, IniRead($l_inifile, 'size', 'sscale', '4'))
        If IniRead($l_inifile, 'size', 'scale', '0') == 1 Then
            GUICtrlSetState($rd_scale, $GUI_CHECKED)
        EndIf
        GUICtrlSetData($in_scalea, IniRead($l_inifile, 'size', 'scalea', '3'))
        GUICtrlSetData($in_scaleb, IniRead($l_inifile, 'size', 'scaleb', '4'))
 
        If IniRead($l_inifile, 'options', 'viewonly', '0') == 1 Then
            GUICtrlSetState($ck_viewonly, $GUI_CHECKED)
        Else
            GUICtrlSetState($ck_viewonly, $GUI_UNCHECKED)
        EndIf
        If IniRead($l_inifile, 'options', 'notoolbar', '0') == 1 Then
            GUICtrlSetState($ck_notoolbar, $GUI_CHECKED)
        Else
            GUICtrlSetState($ck_notoolbar, $GUI_UNCHECKED)
        EndIf
        If IniRead($l_inifile, 'options', 'nostatus', '0') == 1 Then
            GUICtrlSetState($ck_nostatus, $GUI_CHECKED)
        Else
            GUICtrlSetState($ck_nostatus, $GUI_UNCHECKED)
        EndIf
        If IniRead($l_inifile, 'options', 'nohotkeys', '0') == 1 Then
            GUICtrlSetState($ck_nohotkeys, $GUI_CHECKED)
        Else
            GUICtrlSetState($ck_nohotkeys, $GUI_UNCHECKED)
        EndIf
        If IniRead($l_inifile, 'options', 'emulate3', '0') == 1 Then
            GUICtrlSetState($ck_emulate3, $GUI_CHECKED)
        Else
            GUICtrlSetState($ck_emulate3, $GUI_UNCHECKED)
        EndIf
 
        If IniRead($l_inifile, 'proxy', 'ieset', '0') == 1 Then
            GUICtrlSetState($ck_ieset, $GUI_CHECKED)
        Else
            GUICtrlSetState($ck_ieset, $GUI_UNCHECKED)
        EndIf
        If IniRead($l_inifile, 'proxy', 'use', '0') == 1 Then
            GUICtrlSetState($ck_proxy, $GUI_CHECKED)
            GUICtrlSetData($in_proxy, IniRead($l_inifile, 'proxy', 'url', 'missing'))
            GUICtrlSetData($in_port, IniRead($l_inifile, 'proxy', 'port', 'missing'))
        Else
            GUICtrlSetState($ck_proxy, $GUI_UNCHECKED)
        EndIf
 
    EndIf
    ;change back masterpassword if other used
    $g_masterpass = $l_savepass
 
EndFunc   ;==>_LoadProfile
 
Func _SaveProfile()
    Local $l_inifile = $g_openpath & '\' & $g_profile & '.ini'
    Local $l_notefile = $g_openpath & '\' & $g_profile & '.txt'
    Local $l_handle
 
    If StringInStr($g_profile, " ") > 0 Then
        MsgBox(0, "Profile error", "A space in profilename is not supported!")
    Else
        If StringInStr($g_profile, " ") > 0 Then
            MsgBox(0, "Password error", "A space in passwort is not supported!")
        Else
            IniWrite($l_inifile, 'main', 'title', $g_title)
            IniWrite($l_inifile, 'main', 'version', $g_version)
            IniWrite($l_inifile, 'main', 'dsm', GUICtrlRead($ck_usedsm))
            ;IniWrite($file,'main','note',GUICtrlRead($ed_notetext))
 
            IniWrite($l_inifile, 'host', 'server', GUICtrlRead($in_hostinput))
            IniWrite($l_inifile, 'host', 'display', GUICtrlRead($in_displayinput))
            IniWrite($l_inifile, 'host', 'password', GUICtrlRead($in_password))
 
            IniWrite($l_inifile, 'colordepth', 'gray8', GUICtrlRead($rd_gray8))
            IniWrite($l_inifile, 'colordepth', 'color8', GUICtrlRead($rd_color8))
            IniWrite($l_inifile, 'colordepth', 'color256', GUICtrlRead($rd_color256))
            IniWrite($l_inifile, 'colordepth', 'color8bit', GUICtrlRead($rd_color8bit))
 
            IniWrite($l_inifile, 'size', 'autoscale', GUICtrlRead($rd_autoscale))
            IniWrite($l_inifile, 'size', 'fullscreen', GUICtrlRead($rd_fullscreen))
            IniWrite($l_inifile, 'size', 'serverscale', GUICtrlRead($rd_serverscale))
            IniWrite($l_inifile, 'size', 'sscale', GUICtrlRead($in_sscale))
            IniWrite($l_inifile, 'size', 'scale', GUICtrlRead($rd_scale))
            IniWrite($l_inifile, 'size', 'scalea', GUICtrlRead($in_scalea))
            IniWrite($l_inifile, 'size', 'scaleb', GUICtrlRead($in_scaleb))
 
            IniWrite($l_inifile, 'options', 'viewonly', GUICtrlRead($ck_viewonly))
            IniWrite($l_inifile, 'options', 'notoolbar', GUICtrlRead($ck_notoolbar))
            IniWrite($l_inifile, 'options', 'nostatus', GUICtrlRead($ck_nostatus))
            IniWrite($l_inifile, 'options', 'nohotkeys', GUICtrlRead($ck_nohotkeys))
            IniWrite($l_inifile, 'options', 'emulate3', GUICtrlRead($ck_emulate3))
 
            IniWrite($l_inifile, 'proxy', 'ieset', GUICtrlRead($ck_ieset))
            IniWrite($l_inifile, 'proxy', 'use', GUICtrlRead($ck_proxy))
            IniWrite($l_inifile, 'proxy', 'url', GUICtrlRead($in_proxy))
            IniWrite($l_inifile, 'proxy', 'port', GUICtrlRead($in_port))
 
            If GUICtrlRead($ed_notetext) <> "" Then
                $l_handle = FileOpen($l_notefile, 2)
                FileWrite($l_handle, GUICtrlRead($ed_notetext))
                FileClose($l_handle)
                _Encrypt_note($l_notefile)
                FileDelete($l_notefile)
            EndIf
 
            _Encrypt_def($l_inifile)
            FileDelete($l_inifile)
 
            If GUICtrlRead($in_keyfilepath) <> "" Then
                _Encrypt_key(GUICtrlRead($in_keyfilepath))
            EndIf
 
        EndIf
    EndIf
 
EndFunc   ;==>_SaveProfile
 
Func _Help()
    MsgBox(64, "Program Info",$g_infotext)
EndFunc   ;==>_Help
 
Func _Encrypt_note($l_filename)
    Local $l_answer = 1
    Local $l_outputfile = $g_safepath & '\' & $g_profile & $g_noteext
    If FileExists($l_outputfile) Then
        $l_answer = MsgBox(1 + 48 + 256, "", _
	            "Encrypted file " & @CRLF & $l_outputfile & @CRLF & " already exist!")
    EndIf
    If $l_answer = 1 Then
        GUICtrlSetData($lb_status, "Deleting old file")
        If FileExists($l_outputfile) Then
            FileDelete($l_outputfile)
        EndIf
        GUICtrlSetData($lb_status, "Encrypting file")
        _RunWaitDOS('.\Bin\dlock2.exe /E /S "' & $l_filename & '" "' & $l_outputfile & '" /P' & $g_masterpass)
    EndIf
EndFunc   ;==>_Encrypt_note
 
Func _Decrypt_note()
    Local $l_inputfile = $g_safepath & '\' & $g_profile & $g_noteext
    Local $l_outputfile = $g_openpath & '\' & $g_profile & '\' & $g_profile & '.txt'
    If FileExists($l_outputfile) Then
        FileDelete($l_outputfile)
    EndIf
    GUICtrlSetData($lb_status, "Decrypting note file")
    _RunWaitDOS('.\Bin\dlock2.exe /D /S "' & $l_inputfile & '" "' & $l_outputfile & '" /P' & $g_masterpass)
EndFunc   ;==>_Decrypt_note
 
Func _Encrypt_def($l_filename)
    Local $l_answer = 1
    Local $l_outputfile = $g_safepath & '\' & $g_profile & $g_defext
    If FileExists($l_outputfile) Then
        $l_answer = MsgBox(1 + 48 + 256, "", _
                            "Encrypted file " & @CRLF & $l_outputfile & @CRLF & " already exist!")
    EndIf
    If $l_answer = 1 Then
        GUICtrlSetData($lb_status, "Deleting old file")
        If FileExists($l_outputfile) Then
            FileDelete($l_outputfile)
        EndIf
        GUICtrlSetData($lb_status, "Encrypting file")
        _RunWaitDOS('.\Bin\dlock2.exe /E /S "' & $l_filename & '" "' & $l_outputfile & '" /P' & $g_masterpass)
    EndIf
EndFunc   ;==>_Encrypt_def
 
Func _Decrypt_def($l_filename)
    Local $l_outputfile = $g_openpath & '\' & $g_profile & '\' & $g_profile & '.ini'
    If FileExists($l_outputfile) Then
        FileDelete($l_outputfile)
    EndIf
    GUICtrlSetData($lb_status, "Decrypting file")
    _RunWaitDOS('.\Bin\dlock2.exe /D "' & $l_filename & '" "' & $l_outputfile & '" /P' & $g_masterpass)
EndFunc   ;==>_Decrypt_def
 
Func _Encrypt_key($l_filename)
    Local $l_answer = 1
    Local $l_outputfile = $g_safepath & '\' & $g_profile & $g_keyext
    If FileExists($l_outputfile) Then
        $l_answer = MsgBox(1 + 48 + 256, "", _
                            "Encrypted Keyfile " & @CRLF & $l_outputfile & @CRLF & " already exist!")
    EndIf
    If $l_answer = 1 Then
        FileDelete($l_outputfile)
        GUICtrlSetData($lb_status, "Encrypting definition file")
        _RunWaitDOS('.\Bin\dlock2.exe /E /S "' & $l_filename & '" "' & $l_outputfile & '" /P' & $g_masterpass)
    EndIf
EndFunc   ;==>_Encrypt_key
 
Func _Decrypt_key()
    Local $l_inputfile = $g_safepath & '\' & $g_profile & $g_keyext
    Local $l_outputfile = $g_openpath & '\' & $g_profile & '\rc4.key'
    If FileExists($l_outputfile) Then
        FileDelete($l_outputfile)
    EndIf
    GUICtrlSetData($lb_status, "Decrypting key file")
    _RunWaitDOS('.\Bin\dlock2.exe /D /S "' & $l_inputfile & '" "' & $l_outputfile & '" /P' & $g_masterpass)
EndFunc   ;==>_Decrypt_key
 
Func _GetProfileName($l_filename)
    Local $l_temp1
    Local $l_temp2
    Local $l_temp3
    $l_temp1 = StringInStr($l_filename, "\", 0, -1) + 1
    $l_temp2 = StringInStr($l_filename, ".", 0, -1) - 1
    $l_temp3 = StringMid($l_filename, $l_temp1, $l_temp2 - $l_temp1 + 1)
    Return ($l_temp3)
EndFunc   ;==>_GetProfileName
 
Func _RunWaitDOS($sCommand)
    Return RunWait(@ComSpec & " /C " & $sCommand, @ScriptDir, @SW_HIDE)
EndFunc   ;==>_RunWaitDOS
 
Func _RunDOS($sCommand, $l_workingdir)
    Return Run(@ComSpec & " /C " & $sCommand, $l_workingdir, @SW_HIDE)
EndFunc   ;==>_RunDOS