knight666 Posted June 24, 2007 Share Posted June 24, 2007 (edited) Okay, here's what I'm trying to do:I'm loading in an image file to see if it has any secret rarred files.I can do this in PSPad's hex editor, by hand, but I'm a lazy bum who happens to know how to program.Here's what's driving me inane:I load the file into my program, using binary mode, and it gives a completely different hex code than what PSPad gives!PSPad:FFD8FFE000104A46494600010201012C012C0000FFE21C6D4943435F50524F46494C4500010100001C5D4C696E6F02100000D6E74725247422058595A2007CE00020009000600310000616373704D534654000000004945432073524742000000000000000000000000000F6D6000100000000D32D485020200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001163707274000001500000003364657363000001830000006C77747074000001E00000014626B707400000203000000147258595A00000217000000146758595A0000022B000000146258595A0000023F0000014646D6E640000025300000070646D6464000002C300000088767565640000034B0000008676696577000003D1000000246756D69000003F5000000146D6561730000040900000024746563680000042D0000000C72545243000004390000080C6754AutoIt:FFD8FFE00x01130119011F0125012B01320138013E0145014C0152015901600167016E0175017C0183018B0192019A01A101901B101B901C101C901D101D901E101E901F201FA0203020C0214021D0226022F02380241024B0254025D02670271027A028028E029802A202AC02B602C102CB02D502E002EB02F5030x051C052B053A05490558056705770586059605A605B505C505D55E505F6060606160627063706480659066A067B068C069D06AF06C006D106E306F507070719072B073D074F07610774078609907AC07BF07D207E507F8080B081F08320846085A086E0882089608AA08BE08D208E708FB09100925093A094F0964097909F09A409BA09CF09E509FB0x110x270x3D0x540x6A0x810x980xAE0xC50xDC0xF30B0B0B220B390B510B690B800B980BB00BC0BE10BF90C120C2A0C430C5C0C750C8E0CA70CC00CD90CF30x260x400x5A0x740x8E0xA90xC30xDE0xF80E1But the really, REALLY funky bit is that the first few characters are the same!I am using the latest version of AutoIt, I downloaded it a few hours ago. Edited June 24, 2007 by knight666 Link to comment Share on other sites More sharing options...
Siao Posted June 24, 2007 Share Posted June 24, 2007 Why are you using FileReadLine on binary files? "be smart, drink your wine" Link to comment Share on other sites More sharing options...
knight666 Posted June 24, 2007 Author Share Posted June 24, 2007 Because FileRead only returns a handful of characters while FileReadLine returns the entire image? Link to comment Share on other sites More sharing options...
Siao Posted June 24, 2007 Share Posted June 24, 2007 Because FileRead only returns a handful of characters while FileReadLine returns the entire image?That's nonsense. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
knight666 Posted June 24, 2007 Author Share Posted June 24, 2007 FileRead:ÿØÿàFileReadLine:ÿØÿà%+28>ELRY`gnu|¡©±¹ÁÉÑÙáéòú&/8AKT]gqz¢¬¶ÁËÕàëõ+:IXgw¦µÅÕåö'7HYj{¯ÀÑãõ+=Oat¬¿Òåø2FZnª¾ÒçûIt goes on for a bit (it's a 306 kB textfile), but you get my point.Replacing Chr(13) with questionmarks does absolutely squad. Link to comment Share on other sites More sharing options...
Siao Posted June 24, 2007 Share Posted June 24, 2007 (edited) $name = FileOpenDialog("Open file", @ScriptDir, "All (*I][ÝËJBÌÍÙ[HH[SÜ[ ÌÍÛ[YKMBÚ[HB ÌÍÝ[fÆU&VBb33c¶fÆRÂ#B¢bW'&÷"ÒÓFVâWDÆö÷¢b×6t&÷°ÅÕ½Ðí=,Ѽ½¹Ñ¥¹Õ° ¹°Ñ¼ÅեиÅÕ½Ðì°!à ÀÌØíѵÀ¤¤ôÈQ¡¸átLoop WEnd FileClose($file) And if you omit count parameter in FileRead, it would read the whole file. Edited June 24, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
knight666 Posted June 24, 2007 Author Share Posted June 24, 2007 Well, okay, that's a PARTIAL solution. If you keep the FileRead limit at 1024, it beautifully returns 1024 hex characters. BUT if you leave it empty it returns nothing. $name = "J:\Downloads\1182474737965.jpg" $fiHH[SÜ[ ÌÍÛ[YKMBÌÍÜÚ^HH[QÙ]Ú^J ÌÍÛ[YJBÌÍÝ×ÒfÆU&VBb33c¶fÆRÂb33c·6¦R¤uT7G&Å6WDFFb33c·GDFV'VrÂuT7G&Å ÀÌØíÑáÑÕ¤µÀì!à ÀÌØíѵÀ¤¤()¥± ±½Í ÀÌØí¹µ¤ This doesn't work either, because the size is completely different than the binary size, or something. :\ Link to comment Share on other sites More sharing options...
Siao Posted June 24, 2007 Share Posted June 24, 2007 The other part of your solution lies elsewhere, so I suggest you shift your focus away from FileRead. Because it works as documented and works fine. That mysterious GUI control you're trying to update is a label? Then it probably has a limit of 32767 or whatever number of chars. So if a return from FR exceeds that, you have a problem. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
knight666 Posted June 24, 2007 Author Share Posted June 24, 2007 That mysterious GUI control you're trying to update is a label? Then it probably has a limit of 32767 or whatever number of chars. So if a return from FR exceeds that, you have a problem.Look, okay, the "mysterious GUI control" is an EDIT.Last time I checked, edits don't have limits.However, if you simply post whatever is returned from the FileRead into a MsgBox, Windows (ME) has a complete brainfreeze and you have to reboot.Here's some info:The file I'm trying to load is a .jpg, it's 670 kB.PSPad (gave) a different hexadecimal output than AutoIt.Inside the .png is a .txt (rarred), so I'll have to convert the hexadecimal output to a string, or better yet, the binary output to a string in order to search for it.BinaryToString doesn't work or I'm not using it correctly even though I tried everything. Link to comment Share on other sites More sharing options...
FreeFry Posted June 24, 2007 Share Posted June 24, 2007 Post your image, and your entire script so we can look at whats wrong. Link to comment Share on other sites More sharing options...
knight666 Posted June 24, 2007 Author Share Posted June 24, 2007 As you can tell from the total mess that is my code, I'm kind of frustated about all this. Link to comment Share on other sites More sharing options...
Siao Posted June 24, 2007 Share Posted June 24, 2007 (edited) Look, okay, the "mysterious GUI control" is an EDIT.Last time I checked, edits don't have limits.Well, obviously you checked wrong, because in Windows95/98/Me edit control has a limit of 32kb (or 64kb, don't remember which one it is, but it certainly has to do with short int). That's why, quite notoriously, Notepad in those OSes has that limit too and pops that messagebox asking if you want to open the file in Wordpad.To search for Rar signature inside that binary file use something like$file = FileOpen($name, 16)$temp = FileRead($file)Fileclose($file)$found = StringInStr(BinaryToString($temp), "Rar!") Edited June 24, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
FreeFry Posted June 24, 2007 Share Posted June 24, 2007 (edited) I wrapped up this little test with binary reading and writing, which shows how it's supposed to be done, and how it works: Edit: Problem is that whilst this test takes 26 chars from the read data, autoit sees it as a hex string(0x...), which means that one character(byte) is actually two chars in lenght(hex), meaning: using StringLeft() and trying to grab 26 chars, will actually just grab 13 chars. I myself is a little puzzled over how BinaryToString() works... If it removes all binary data from the data itself I'm not sure:S Edited June 24, 2007 by FreeFry Link to comment Share on other sites More sharing options...
knight666 Posted June 24, 2007 Author Share Posted June 24, 2007 $file = FileOpen($name, 16)$temp = FileRead($file)Fileclose($file)$found = StringInStr(BinaryToString($temp), "Rar!")Short, simple and working.Thanks for your help man, it was getting rather annoying. Link to comment Share on other sites More sharing options...
herewasplato Posted June 24, 2007 Share Posted June 24, 2007 knight666, Kudos on the "Topic Title Edit". ***SOLVED*** is a nice use of the feature. One each: "at-a-boy". -MSP- [size="1"][font="Arial"].[u].[/u][/font][/size] 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