verschlüsselte INI auslesen, und entschlüsselt schreiben

  • Hi zusammen...

    Hab da ein Problem mit einem Teilscript.

    Ich habe eine verschlüsselte INI, die ich in meinem Programm einlesen, entschlüsseln und in eine neue INI ablegen möchte.

    Wie ich es jetzt habe, schreibt er mir nix in die GP.ini... Helft Ihr mir mal bitte aufs Pferd???

    [autoit]


    if Fileexists(@ScriptDir & "\GP.ini") Then
    FileCopy(@ScriptDir & "\GP.ini", $pfad & 'GP_1.ini')
    Sleep(100)
    $file = FileOpen($pfad & "GP_1.ini", 0)
    If $file = -1 Then
    MsgBox(0, "ACHTUNG", "GP.ini ist leer " & @CRLF & "oder beschädigt. " & @CRLF & " Bitte die INI erneut downloaden " & @CRLF & "und in den Install-Ordner legen!", 10)
    Exit
    EndIf
    EndIf

    [/autoit][autoit][/autoit][autoit]

    $chars = FileRead($pfad & "GP_1.ini")

    [/autoit][autoit][/autoit][autoit]

    $s_EncryptPassword = 'irendeinPasswort'
    $i_EncryptLevel = '2'

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    $text = _StringEncrypt(0, $chars, $s_EncryptPassword, $i_EncryptLevel)
    Sleep(100)
    $file_new = _FileCreate($pfad & 'gp.ini')

    [/autoit][autoit][/autoit][autoit]

    $inifile = FileOpen ($pfad & 'gp.ini',2)

    [/autoit][autoit][/autoit][autoit]

    _FileWriteFromArray($pfad & 'gp.ini', $text)
    ;~ $FileWrite($pfad & 'gp.ini', $text)
    ;~ FileClose($pfad & 'gp.ini')
    FileClose($pfad & "GP_1.ini")

    [/autoit]

    Gruß
    Pitter

    Einmal editiert, zuletzt von Pitter (18. April 2010 um 21:33)

  • Wie sieht denn die

    [autoit]

    $pfad

    [/autoit]

    Variable aus?
    Wenn diese kein "\" am Ende hat solltest du

    [autoit]

    $pfad & "GP_1.ini"

    [/autoit]

    in

    [autoit]

    $pfad & "\GP_1.ini"

    [/autoit]

    ändern. [MSIE_newline_end ]

  • Versuch mal so:

    Spoiler anzeigen
    [autoit]

    If FileExists(@ScriptDir & "\GP.ini") Then
    FileCopy(@ScriptDir & "\GP.ini", $pfad & '\GP_1.ini')
    $file = FileOpen($pfad & "\GP_1.ini", 0)
    If $file = -1 Then
    MsgBox(0, "ACHTUNG", "GP.ini ist leer " & @CRLF & "oder beschädigt. " & @CRLF & " Bitte die INI erneut downloaden " & @CRLF & "und in den Install-Ordner legen!", 10)
    Exit
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $chars = FileRead($file)
    FileClose($file)

    [/autoit] [autoit][/autoit] [autoit]

    $s_EncryptPassword = 'irgendeinPasswort'
    $i_EncryptLevel = '2'

    [/autoit] [autoit][/autoit] [autoit]

    $text = _StringEncrypt(0, $chars, $s_EncryptPassword, $i_EncryptLevel)

    [/autoit] [autoit][/autoit] [autoit]

    $inifile = FileOpen ($pfad & '\gp.ini',2)
    _FileWriteFromArray($inifile, $text)
    FileClose($inifile)

    [/autoit]
  • Vielen Dank!

    Leider bleibt die neue entschlüsselte INI leer. Ich hab keine Ahnung warum.
    Der Schlüssel ist richtig, mit der ich die INI vorher verschlüsselt habe... ?(

    Gruß
    Pitter

  • Kannst du auch mal die GP.ini geben zum testen?

    Edit: probier mal so:

    Spoiler anzeigen
    [autoit]

    If FileExists(@ScriptDir & "\GP.ini") Then
    FileCopy(@ScriptDir & "\GP.ini", $pfad & '\GP_1.ini')
    $file = FileOpen($pfad & "\GP_1.ini", 0)
    If $file = -1 Then
    MsgBox(0, "ACHTUNG", "GP.ini ist leer " & @CRLF & "oder beschädigt. " & @CRLF & " Bitte die INI erneut downloaden " & @CRLF & "und in den Install-Ordner legen!", 10)
    Exit
    EndIf
    $chars = FileRead($file)
    FileClose($file)

    [/autoit] [autoit][/autoit] [autoit]

    $sEncryptPassword = 'irgendeinPasswort'
    $iEncryptLevel = 2

    [/autoit] [autoit][/autoit] [autoit]

    $text = _StringEncrypt(0, $chars, $sEncryptPassword, $iEncryptLevel)

    $inifile = FileOpen ($pfad & '\gp.ini', 2)
    FileWrite($inifile, $text)
    FileClose($inifile)
    EndIf

    [/autoit]
  • na logisch...
    Hier das Verschlüsselungstool mit dem festen PW, was ich zum Erstellen der verschlüsselten INI verwende.
    Der Text wird dann mit C&P in die INI kopiert und gespeichert. Wenn das dann mal läuft, werde ich das dynamisch machen... aer erst muss das mal klappen...

    Spoiler anzeigen
    [autoit]


    ;====================================================
    ;============= Encryption Tool With GUI =============
    ;====================================================
    ; AutoIt version: 3.0.103
    ; Language: English
    ; Author: "Wolvereness"
    ;
    ; ----------------------------------------------------------------------------
    ; Script Start
    ; ----------------------------------------------------------------------------
    #include <GUIConstantsEx.au3>
    #include <String.au3>
    ;#include files for encryption and GUI constants

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    _Main()

    [/autoit] [autoit][/autoit] [autoit]

    Func _Main()
    Local $WinMain, $EditText, $InputLevel, $InputPass, $UpDownLevel
    Local $EncryptButton, $DecryptButton, $string
    #forceref $UpDownLevel
    ;~~
    $WinMain = GUICreate('Encryption tool', 400, 400)
    ; Creates window
    ;~~
    $EditText = GUICtrlCreateEdit('', 5, 5, 380, 350)
    ; Creates main edit
    ;~~
    $InputPass = "test"
    ; Creates the password box with blured/centered input
    ;~~
    $InputLevel = "2"
    ; These two make the level input with the Up|Down ability
    ;~~
    $EncryptButton = GUICtrlCreateButton('Encrypt', 170, 360, 105, 35)
    $DecryptButton = GUICtrlCreateButton('Decrypt', 285, 360, 105, 35)
    ; Encryption/Decryption buttons
    ;~~

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    ; Shows window
    ;~~

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    ExitLoop
    Case $EncryptButton
    ; When you press Encrypt
    ;~~
    GUISetState(@SW_DISABLE, $WinMain)
    ; Stops you from changing anything
    ;~~
    $string = GUICtrlRead($EditText)
    ; Saves the editbox for later
    ;~~
    GUICtrlSetData($EditText, 'Please wait while the text is Encrypted/Decrypted.')
    ; Friendly message
    ;~~
    GUICtrlSetData($EditText, _StringEncrypt(1, $string, $InputPass, $InputLevel))
    ; Calls the encryption. Sets the data of editbox with the encrypted string
    ;~~
    GUISetState(@SW_ENABLE, $WinMain)
    ; This turns the window back on
    ;~~
    Case $DecryptButton
    ; When you press Decrypt
    ;~~
    GUISetState(@SW_DISABLE, $WinMain)
    ; Stops you from changing anything
    ;~~
    $string = GUICtrlRead($EditText)
    ; Saves the editbox for later
    ;~~
    GUICtrlSetData($EditText, 'Please wait while the text is Encrypted/Decrypted.')
    ; Friendly message
    ;~~
    GUICtrlSetData($EditText, _StringEncrypt(0, $string, $InputPass, $InputLevel))
    ; Calls the encryption. Sets the data of editbox with the encrypted string
    ;~~
    GUISetState(@SW_ENABLE, $WinMain)
    ; This turns the window back on
    ;~~
    EndSwitch
    WEnd
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Dann hier der unverschlüsselte Inhalt der GP.ini:

    Spoiler anzeigen

    last but not least der aktuelle Teil:

    Spoiler anzeigen
    [autoit]


    If FileExists(@ScriptDir & "\GP.ini") Then
    FileCopy(@ScriptDir & "\GP.ini", $pfad & '\GP_1.ini')
    $file = FileOpen($pfad & 'GP_1.ini', 0)
    If $file = -1 Then
    MsgBox(0, "ACHTUNG", "GP.ini ist leer " & @CRLF & "oder beschädigt. " & @CRLF & " Bitte die INI erneut downloaden " & @CRLF & "und in den Install-Ordner legen!", 10)
    Exit
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $chars = FileRead($file)
    FileClose($file)

    [/autoit] [autoit][/autoit] [autoit]

    $s_EncryptPassword = "test"
    $i_EncryptLevel = "2"

    [/autoit] [autoit][/autoit] [autoit]

    $text = _StringEncrypt(0, $chars, $s_EncryptPassword, $i_EncryptLevel)
    Sleep(500)
    $inifile = FileOpen ($pfad & 'gp.ini',2)
    _FileWriteFromArray($inifile, $text)
    Sleep(500)
    FileClose($inifile)

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Edit:

    die Links sind korrekt so und benötigen keinen Backjslash

    Edit2:

    auch mit FileWrite($inifile, $text) ist die INI leer...

    Gruß
    Pitter

    Einmal editiert, zuletzt von Pitter (18. April 2010 um 21:18)

  • Meins geht auch, habs so getestet.

    Spoiler anzeigen
    [autoit]

    #Include <String.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $pfad = @ScriptDir & "\GP\"

    [/autoit] [autoit][/autoit] [autoit]

    $sEncryptPassword = 'irgendeinPasswort'
    $iEncryptLevel = 2

    [/autoit] [autoit][/autoit] [autoit]

    $file = FileOpen(@ScriptDir & "\GPold.ini", 0)
    $string = FileRead($file)
    FileClose($file)
    $string = _StringEncrypt(1, $string, $sEncryptPassword, $iEncryptLevel)
    $file = FileOpen(@ScriptDir & "\GP.ini", 2)
    FileWrite($file, $string)
    FileClose($file)

    [/autoit] [autoit][/autoit] [autoit]

    If FileExists(@ScriptDir & "\GP.ini") Then
    FileCopy(@ScriptDir & "\GP.ini", $pfad & 'GP_1.ini')
    $file = FileOpen($pfad & "GP_1.ini", 0)
    If $file = -1 Then
    MsgBox(0, "ACHTUNG", "GP.ini ist leer " & @CRLF & "oder beschädigt. " & @CRLF & " Bitte die INI erneut downloaden " & @CRLF & "und in den Install-Ordner legen!", 10)
    Exit
    EndIf
    $chars = FileRead($file)
    FileClose($file)

    [/autoit] [autoit][/autoit] [autoit]

    $text = _StringEncrypt(0, $chars, $sEncryptPassword, $iEncryptLevel)

    [/autoit] [autoit][/autoit] [autoit]

    $inifile = FileOpen($pfad & 'gp.ini', 2)
    FileWrite($inifile, $text)
    FileClose($inifile)
    EndIf

    [/autoit]

    Wozu packs du da eigentlich die Sleeps rein?

  • Die Sleeps hatte ich reingemacht, um erst mal sicherzustellen, dass das nicht daran liegt, dass der versucht vor dem Ende des Kopieren schon zu lesen...
    ...ne reine Vorsichtsmassnahme. Die hba ich jetzt auch wieder draussen. ;)

    Gruß
    Pitter

  • Da brauchst du keine Angst haben, der führt die Befehle erst aus bis zum Ende, da manche auch einen Rückgabeparameter wollen. Und den bekommst du erst wenn der Befehl vollständig ausgeführt wurde.