blindwig Posted June 14, 2005 Share Posted June 14, 2005 I needed to read some binary data out of a file, so I wrote this function. It takes a file handle (you must have already opened the file in read mode) and reads the specified number of bytes. In returns the value of each byte in an array. CODE Func _FileReadBin($hndFile, $Amount = 1) If $Amount <= 0 or not StringIsDigit($hndFile) Then SetError(1) Return 0 EndIf Dim $aReturn[$Amount + 1], $num = 0, $tmp = '' For $Num = 1 to $Amount $tmp = FileRead($hndFile, 1) If @error Then ExitLoop $aReturn[$num] = Asc($tmp) Next ReDim $aReturn[$num] $aReturn[0] = $num - 1 If $aReturn[0] < $Amount Then SetError(1) Return $aReturn EndFunc My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
FuryCell Posted June 15, 2005 Share Posted June 15, 2005 I needed to read some binary data out of a file, so I wrote this function. It takes a file handle (you must have already opened the file in read mode) and reads the specified number of bytes. In returns the value of each byte in an array.CODEFunc _FileReadBin($hndFile, $Amount = 1) If $Amount <= 0 or not StringIsDigit($hndFile) Then SetError(1) Return 0 EndIf Dim $aReturn[$Amount + 1], $num = 0, $tmp = '' For $Num = 1 to $Amount $tmp = FileRead($hndFile, 1) If @error Then ExitLoop $aReturn[$num] = Asc($tmp) Next ReDim $aReturn[$num] $aReturn[0] = $num - 1 If $aReturn[0] < $Amount Then SetError(1) Return $aReturnEndFunc<{POST_SNAPBACK}>Will this work on files that contain nulls??If so you just solved a problem people have been try to solve since the arrival of Autoit3 HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
blindwig Posted June 15, 2005 Author Share Posted June 15, 2005 Will this work on files that contain nulls??If so you just solved a problem people have been try to solve since the arrival of Autoit3<{POST_SNAPBACK}>Yes, it reads nulls. Since it does not store the actual character, only the value, then a null is just a zero, and AutoIt is perfectly capable of storing zeros It might not be the fastest routine out there, but it does the job... My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
FuryCell Posted June 15, 2005 Share Posted June 15, 2005 (edited) Yes, it reads nulls. Since it does not store the actual character, only the value, then a null is just a zero, and AutoIt is perfectly capable of storing zeros It might not be the fastest routine out there, but it does the job...<{POST_SNAPBACK}>Awesome! Great job.i can use this for a lot of programs and now we can compare binary files natively in Autoit. Edited June 15, 2005 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. 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