czmaster Posted November 14, 2009 Share Posted November 14, 2009 Hi, If I remove some data (from a binary file) with the String functions (Stringregexp, StringMid, ...) some data are changed by 0x. If I open the file and show the data without using the String functions the data doesn't change. For example if I open a GIF file instead of the line GIF89 I have GI0x123456. Do you know why ? Thx ! Link to comment Share on other sites More sharing options...
Developers Jos Posted November 14, 2009 Developers Share Posted November 14, 2009 Hi,If I remove some data (from a binary file) with the String functions (Stringregexp, StringMid, ...) some data are changed by 0x. If I open the file and show the data without using the String functions the data doesn't change.For example if I open a GIF file instead of the line GIF89 I have GI0x123456.Do you know why ?Thx !You are probably doing something wrong but you will have to show the script to be able to see what is happening.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 14, 2009 Moderators Share Posted November 14, 2009 czmaster,Because Autoit variables are not "typed" (that is forced to be something specific like an integer, string, float, etc) you sometimes get the "best guess" of the interpreter as to what a type particular variable is supposed to be. If you open a file in binary mode, Autoit presumes you want the contents as a hex string - and that is what you get: the hex bytes preceded by "0x" to indicate it is hex. Look at this example:$sFilename = "Your_File_Path" Global $hFileHandle = FileOpen($sFilename, 16) $bFileContents = FileRead($hFileHandle) $bFirstBytes = StringLeft($bFileContents, 16) $bFirstHex = StringMid($bFileContents, 3, 14) MsgBox(0, "", $bFirstBytes & @CRLF & " " & $bFirstHex)You can see that the "normal" return has the "0x" at the beginning - it is up to you to remove it if you want to manipulate the bytes themselves.I know it sounds a pain, but it is the price to pay for having un-typed variables - one that I am very happy to pay given the flexibility that it offers. There are a number of commands which force variables into a specifiic type: Dec, Hex, Number, Binary, String, etc - these can be used if you want to change the type. For example, InputBox returns a string - so if you want to compare the result to a number, you need to reset the type first:$sResult = InputBox(..... If Number($sResult) > 5 Then ; .....I hope that answers your question. If not, post your code so we can see what is going on and offer more advice. M23 pixelsearch 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Authenticity Posted November 14, 2009 Share Posted November 14, 2009 If you change binary data you need to write binary data or otherwise use BinaryToString(): $hFile = FileOpen(@ScriptDir & "\test.bin", 18) $xBin = StringToBinary("GIF") $xBin = BinaryMid($xBin, 1, BinaryLen($xBin)-1) & "51" FileWrite($hFile, $xBin) FileClose($hFile) Link to comment Share on other sites More sharing options...
czmaster Posted November 14, 2009 Author Share Posted November 14, 2009 (edited) While 1 $recv = TCPRecv($socket, 8) If @error <> 0 Then ExitLoop EndIf If ($x = 1) Then $txt &= $recv EndIf ConsoleWrite($recv) WEnd $f = FileOpen("123.txt", 1) $b = 1 While $b <> 0 $a = $b + 1 $b = StringInStr($txt, @CRLF, 0, 1, $a) $t = StringMid($txt, $a, $b - $a) FileWrite($f, $t & @CRLF) Wend This is a part of code, the entire program donwload a file from an HTTP server and remove chunk information. When I show value of $recv it looks good, but in my file it isn't the same value. Thx, Edited November 14, 2009 by czmaster Link to comment Share on other sites More sharing options...
Authenticity Posted November 14, 2009 Share Posted November 14, 2009 The file on the server is a binary or text file? Can you post the first few bytes? Link to comment Share on other sites More sharing options...
czmaster Posted November 14, 2009 Author Share Posted November 14, 2009 (edited) The file on the server is a binary or text file? Can you post the first few bytes? The file is a GIF but it can also be other format. The server return ASCII character but it isn't really text. Authentic file bytes (copy/paste does not work with all character) : GIF89a çÿ×é³ûÛüÿöÍå’þþý Result file bytes : G0x49463839612000200x00E7FF00EE9D93EDøØ Edited November 14, 2009 by czmaster 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