hmobron Posted January 22, 2013 Share Posted January 22, 2013 Hello, i have a strange problem. When i open a bin file, created by my self and i re read it whit FileReadLine the @error is trowing a 1 in stead off -1. _FileCountLines Shows 2 line's and that is correct. FileGetPos Starts at 0, then to 36 and then to 104 and it stays there looping at the line If @error = -1 Then ExitLoop I open the file whit 0+16 and contains two lines whit EncryptData write whit mode 2+16 I can change @error = -1 to @error = 1 but i don't think that's the correct way. Any help welcome. Link to comment Share on other sites More sharing options...
FireFox Posted January 22, 2013 Share Posted January 22, 2013 Hi,Can you provide a sample of your code ?I can change @error = -1 to @error = 1 but i don't think that's the correct way.Erm. This macro is only a "flag" that can be returned by functions to tell if this one succeeded or not. Editing this one will maybe make you feel better but it's not going to change something at the end.Br, FireFox. Link to comment Share on other sites More sharing options...
hmobron Posted January 22, 2013 Author Share Posted January 22, 2013 Hello, this is the part thats write the data. Func Safe() _Crypt_Startup() ; If GUICtrlRead ( $WWisTrue) = $GUI_CHECKED Then $SetpassWord = "True" Else $SetpassWord = "False" EndIf Local $file = FileOpen(@ScriptDir & "\manager.cfg",2+16) ;FileWriteLine($file, $Data) FileWriteLine($file, _Crypt_EncryptData("Password=" &GUICtrlRead ( $WW) , $Password, $CALG_AES_256 )& @CRLF) FileWriteLine($file, _Crypt_EncryptData("PasswordTrue=" &$SetpassWord, $Password, $CALG_AES_256 )& @CRLF) FileClose($file) _Crypt_Shutdown() Exit EndFunc This part is reading the data. Its a bit messy by testing and seeking the error. expandcollapse popupFunc LoadConfig() _Crypt_Startup() MsgBox(0,"",_FileCountLines(@ScriptDir & "\manager.cfg")) Local $file = FileOpen(@ScriptDir & "\manager.cfg", 16+0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 MsgBox(0, "", "Position: " & FileGetPos($file) ) Local $line = FileReadLine($file) MsgBox(0, "",$line) $tmp = StringSplit(BinaryToString(_Crypt_DecryptData( $line, $Password, $CALG_AES_256)), "=") local $a $a = $a +1 if $a = 10 then Exit ; _ArrayDisplay($tmp, "$avArray set manually 1D") ;$Data[1] = $tmp[2] If @error Then MsgBox(0,"error",@error) If @error = -1 Then ExitLoop MsgBox(0, "",BinaryToString(_Crypt_DecryptData( $line, $Password, $CALG_AES_256))) WEnd _ArrayDisplay($Data, "$avArray set manually 1D") FileClose($file) _Crypt_Shutdown() EndFunc Link to comment Share on other sites More sharing options...
guinness Posted January 22, 2013 Share Posted January 22, 2013 @error can be changed by using SetError, but it's set if the previous function fails. Also why not just read the whole contents of the file? Instead of line by line. UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
hmobron Posted January 22, 2013 Author Share Posted January 22, 2013 (edited) Hoi guinness,I tried that, but the problem stay's. I want to now why the error is 1 instead off -1. When i save and direct open there is no problem at all.BTW The data is correct at reading. Edited January 22, 2013 by hmobron Link to comment Share on other sites More sharing options...
FireFox Posted January 22, 2013 Share Posted January 22, 2013 I don't know what's the default line if the parameter is not set for the function FileReadLine, but seems like it's the last line. So you must set it to 1 for your example : $line = FileReadLine($file, 1) Code cleaned : ... Local $line = FileReadLine($file, 1) Local $atmp = StringSplit(BinaryToString(_Crypt_DecryptData($line, $Password, $CALG_AES_256)), "=") _ArrayDisplay($atmp) FileClose($file) ... Br, FireFox. Link to comment Share on other sites More sharing options...
jchd Posted January 22, 2013 Share Posted January 22, 2013 The basic problem is that your logic is faulty. Your .cfg file content is: Password=<binary data block> PasswordTrue=<second binary data block> The problem is that you can't predict which bytes are in the two binary blocks (or you could break AES). There are good chances that what FIleReadLine considers a line break might be in one or both blocks. Same for your splitting by '=' as this character may well be in one or both blocks. Mixing text and random binary is almost always a bad idea. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
FireFox Posted January 22, 2013 Share Posted January 22, 2013 @jchd That's not right as he crypts the whole line. Link to comment Share on other sites More sharing options...
jchd Posted January 22, 2013 Share Posted January 22, 2013 Yes indeed, that just makes it worse! This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
FireFox Posted January 22, 2013 Share Posted January 22, 2013 Yes indeed, that just makes it worse!Yup.@hmobronMy suggestion would to use the IniCrypt UDF or something similar in order to easily work on the data instead of reading each line, decode it, and know if it's the key you want to read. Link to comment Share on other sites More sharing options...
hmobron Posted January 22, 2013 Author Share Posted January 22, 2013 Hello Guys, thank for the input about the crypting, but the main problem still exist. Change the line to Local $line = FileReadLine($file,1) makes the pointer hang to position 36 off the file because the error = 1 Greeting Link to comment Share on other sites More sharing options...
jchd Posted January 22, 2013 Share Posted January 22, 2013 Once again, there is no meaning of a "line" in a binary file. THAT is the main problem. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now