Jump to content
Sign in to follow this  
hmobron

FileOpen and @error

Recommended Posts

hmobron

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.

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
hmobron

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.

Func 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

Share this post


Link to post
Share on other sites
guinness

@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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
hmobron

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 by hmobron

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
FireFox

@jchd

That's not right as he crypts the whole line.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
FireFox

Yes indeed, that just makes it worse!

Yup.

@hmobron

My 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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
hmobron

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

Share this post


Link to post
Share on other sites
jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

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
Sign in to follow this  

×