Triblade Posted May 25, 2007 Posted May 25, 2007 Hiya, When I use this piece of code: $open = fileopen(@DesktopDir & "\testpic1.JPG", 0) $read = fileread($open) msgbox(0,"",$read) I get only the first 4 characters (ÿØÿà) of the .JPG on my desktop. This is not what I expected. JPG file are often at least filled with a few thousand characters. Well, not so strange when I noticed the first characters in the JPG where: "ÿØÿà JFIF ` ` ÿÛ C" After these 4 chars the comes (5th char) an NULL character ( ascii: 0 ). I guess the FileRead can't handle NULL characters. Can someone confirm this or possibly have an anwser? Thanks in advance, Tri My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
gcriaco Posted May 25, 2007 Posted May 25, 2007 (edited) Hiya, When I use this piece of code: $open = fileopen(@DesktopDir & "\testpic1.JPG", 0) $read = fileread($open) msgbox(0,"",$read) oÝ÷ ضåÊØ^~*ì·!j¶µêì¡ûaxÆ¢y²uë$¶S+"²z-Â!ìiyË^tÆ~)^j·¨~×§jÙ^jË_Y^w§ÞÂØhºÆ§uÈZ§-z»zYg¢Û(²ÚÚ°éÈbqçmçâ®ËªÚr׫²)íâO^ꮢÒE _z÷ ªº@~׫¶¬{!j»-ç(ë9¶!j¶§5BËr«iË^«-笲Ø^)^Eæq©÷öØZÙ^5BËr«iË^®ÀÊ&zÞrß¹+(®,²&åʯy©Ú8ZK"§ojwN¸¿ªê-y:ò¢ëm+¡×ºÚ"µÍÌÍÛÜ[H[[Ü[ÚÝÜ [È ][ÝÉÌLÝÝXÌKÉ][ÝËMB Edited May 25, 2007 by gcriaco
Triblade Posted May 25, 2007 Author Posted May 25, 2007 (edited) Try out this code: $open = fileopen(@DesktopDir & "\testpic1.JPG", 16) (Edit: thanks for the reply ) Then I get the code, but in hexadecimal. Which I can't turn into an picture again. (Due to the conversion to the NULL character) What I like to accomplice is to make an complete copy of the picture, but in an variable or an string or such. So I have to grab the ascii characters from the data of the file and copy them. This seems impossible for me atm... Edited May 25, 2007 by Triblade My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
Triblade Posted May 25, 2007 Author Posted May 25, 2007 Hmm, the tile of the msgbox says 4 and the msg says: "ÿØÿà". So maybe the FileOpen is %6^*(%&*( ? My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
Triblade Posted May 25, 2007 Author Posted May 25, 2007 (edited) Well that IS odd... Hmm, what happens if you write that to a file? Anyway, my case: Oh, and I do have to say I just installed the latest beta from the website. v3.2.4.7. Edit: Downoaded the 'Full' v3.2.4.8 and still didn't work. Edited May 25, 2007 by Triblade My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
randallc Posted May 25, 2007 Posted May 25, 2007 (edited) Hi, That's weird! How about posting to Bugs! I don't understand it... r [EDIT] but this message boxes OK?.... ;_FileReadAPI2.au3 #include "APITailRW.au3" $s_File = @WindowsDir & "\Rhododendron.bmp" $i_FileSize = FileGetSize($s_File) $h_File = _FileOpenAPI ($s_File) _FileSetPosAPI ($h_File, $i_FileSize - 128);5 ;read first $read = _FileReadAPI ($h_File, 128) $len =StringLen($read) _FileCloseAPI ($h_File) MsgBox(4096, "", "StringLen($read)="&StringLen($read)) msgbox(0,StringLen($read),$read)What is happenng? ; ConsoleWrite shows same problem so must be in return of fileread (whatever method; so not just the inbuilt fileread!) $i_FileSize=17362 $len=4 $read=BMÒC Edited May 25, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
Triblade Posted May 25, 2007 Author Posted May 25, 2007 (edited) Before reading my post further: I am now at home behind my Vista machine. Any test now displayed are tested in Vista and can show different results then in XP. Tomorrow I will double check my findings in XP. Hi, That's weird! How about posting to Bugs! I don't understand it... <..................................> What is happenng? ; ConsoleWrite shows same problem so must be in return of fileread (whatever method; so not just the inbuilt fileread!)Maybe the FileRead can't handle ascii 0. Can anyone confirm this before going to the bug section? x'00' terminates a message in MSGBOX. Try: $Hex00 = BinaryString(0) MsgBox(0, "", "This text is displayed." & $Hex00 & "This text is missing!!!") oÝ÷ Ûú®¢×+"³Z´¶)ÕËZßvµ§!éíTo do my basic check I've tried the 1st two lines of your code. This is what I got: So simply put, like my last results Edit: Stupid typo... Edited May 25, 2007 by Triblade My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
Triblade Posted May 29, 2007 Author Posted May 29, 2007 I reacted to Jon's post in the bug tread. When I use the binary I get hex back. I'd like to get the characters back as you see them when opend in Notepad. The length is indeed fixed. If I get hex it's not unwelcome, but when I convert that back to ascii chars the null still terminates. My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
Administrators Jon Posted May 29, 2007 Administrators Posted May 29, 2007 I reacted to Jon's post in the bug tread. When I use the binary I get hex back. I'd like to get the characters back as you see them when opend in Notepad. The length is indeed fixed. If I get hex it's not unwelcome, but when I convert that back to ascii chars the null still terminates.Nulls will _always_ terminate a msgbox. The Windows API message box functions (and most string functions) use the presence of null to denote the end of string. How you work around this depends on what you are trying to do. If you simply want a display version then stringreplace the nulls for some other char like "?". $string = chr(0) & "something" & chr(0) $display = StringReplace($string, chr(0), "?") MsgBox(0, "", $display) Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Triblade Posted May 30, 2007 Author Posted May 30, 2007 Thanks for all the fantastic replies.Jon fixed (= pointed me to the right way) my problem in this anwser: http://www.autoitscript.com/forum/index.ph...st&p=349578'Simple' explanation: With the read when opened as binary ( FileOpen($file, 16) ) you can use the binarytostring ( BinarytoString($string) ) funtion to get the content of the file into an string just as the content is read in Notepad.So in code:$data = FileOpen(@WindowsDir & "\Rhododendron.bmp", 16) $data = FileRead($data) MsgBox(0, "Length", BinarytoString($data))I may not have explaned to as perfect as I would like, but English is not my primary language.Anyway, my problem is now gone thanks to you all! My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
Antiec Posted June 21, 2007 Posted June 21, 2007 I've been trying to make my little BinaryToString work for the whole day. And still after searching the forums couple of times I haven't been able to do it so i'm wondering if someone knows the answer. But why does the following code work with a text-file which has just some gibberish in it, but not with a proper exe-file, which returns MZ and a box: CODE$s_File = "test.exe" $i_FileSize = FileGetSize($s_File) $h_File = FileOpen($s_File, 16) $s_data = FileRead($h_File, 1500) FileClose($h_File) MsgBox(0, "test", $s_data) $ConvertedToString = BinaryToString($s_data) MsgBox(0, "test", $ConvertedToString) Func _BinToString($binary) $filename = Hex(Random(0,65535^2,1))&".temp.txt" $fp = FileOpen($filename,18) FileWrite($fp,$binary) FileClose($fp) $string = FileRead($filename) FileDelete($filename) Return $string EndFunc Someone babbled about some buggie thing on 3.2.2.x but it looks like some have it working. I'm using 3.2.4.9. Thanks
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