deerhunt713 Posted October 7, 2012 Share Posted October 7, 2012 So I'm new to autoit. I need to find a hex string in a file (also in hex). I looked into the function StringInStr, but it gives the wrong location, and there doesnt seem to be a function to do the same for binary or hex. any suggestions? what i have $location = StringInStr($file,"fedcba987654321") Link to comment Share on other sites More sharing options...
stormbreaker Posted October 7, 2012 Share Posted October 7, 2012 StringInStr($File, 0xfedcba987654321). I don't think ya need inverted commas for hex... ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
czardas Posted October 7, 2012 Share Posted October 7, 2012 How about: $sBinaryFile = "test.txt" ; Text contains Hello World ; read binary file $hFile = FileOpen($sBinaryFile, 16) $dBinary = FileRead($hFile) FileClose($hFile) If StringInStr($dBinary, "48656C6C6F20576F726C64") Then MsgBox(0, "", "Hello World") operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted October 7, 2012 Share Posted October 7, 2012 (edited) There is a potential problem with the code above. Anyone who wants a small challenge; identify the problem and provide, or describe, a solution. Edited October 7, 2012 by czardas FireFox 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
FireFox Posted October 7, 2012 Share Posted October 7, 2012 (edited) There is a potential problem with the code above. Anyone who wants a small challenge; identify the problem and provide, or describe, a solution. An issue : Does not work with specials encodings (e.g : UTF-16XX) My fix : $sBinaryFile = "test.txt" ; Text contains Hello World $sStringToFind = "Hello World" $bStringToFind = StringTrimLeft(Binary($sStringToFind), 2) ; read binary file $hFile = FileOpen($sBinaryFile, 16) $dBinary = FileRead($hFile) FileClose($hFile) $bStringToFind2 = "" For $iOffset = 3 To StringLen($bStringToFind) step 2 $bStringToFind2 &= "00" & StringMid($bStringToFind, $iOffset, 2) Next If StringInStr($dBinary, $bStringToFind) _ Or StringInStr($dBinary, $bStringToFind2) Then MsgBox(64, "", $sStringToFind & " found !") Br, FireFox. Edited October 7, 2012 by FireFox czardas 1 Link to comment Share on other sites More sharing options...
UEZ Posted October 7, 2012 Share Posted October 7, 2012 (edited) There is a potential problem with the code above. Anyone who wants a small challenge; identify the problem and provide, or describe, a solution. I think that the op is not searching for this kind of solution rather than look for hex values within a text file. Your solution is working only for case sensitive strings -> Hello World not equal with hello world. Edit: indeed, UTF stuff makes also problems... $sBinaryFile = "test.txt" ; Text contains Hello World ; read binary file $hFile = FileOpen($sBinaryFile, 16) $dBinary = FileRead($hFile) FileClose($hFile) $sSearch = "hello world" $sBinary = BinaryToString($dBinary) If $sSearch = $sBinary Then MsgBox(0, "", $sBinary) @deerhunt713: something like that here? #include <Array.au3> $sText = "This is a text with a hex string in it: fedcba987654321. Needs to be filtered by AutoIt." $aResult = StringRegExp($sText, "b[[:xdigit:]]+b", 3) _ArrayDisplay($aResult, "Possible Hex Values") Br, UEZ Edited October 7, 2012 by UEZ czardas 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
czardas Posted October 7, 2012 Share Posted October 7, 2012 That's excellent Firefox, I'm most impressed. I figured it might be a useful question from which other's can learn, including myself! Five Stars! FireFox 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted October 7, 2012 Share Posted October 7, 2012 (edited) Your solution is working only for case sensitive strings -> Hello World not equal with hello world.Firefox found the issue I was referring to, but you do have a point. I'm not exactly sure what the OP wants, and I consider the question to be somewhat vague. Without knowing the type of encoding or significance of the binary, it's an almost impossible question to answer. Edited October 7, 2012 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
UEZ Posted October 7, 2012 Share Posted October 7, 2012 (edited) Yep, let's wait what the op is looking for. Good night, UEZ Edited October 7, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
deerhunt713 Posted October 8, 2012 Author Share Posted October 8, 2012 Thanks guys. I solved it by doing a while loop. Sorry for the vagueness of the post. my solution probably isnt the best but it seems to work. $try = Binary("0xFEDCBA9876543210") $p =1 $Startloop = StringCompare($try,BinaryMid($fileHex,$p,8)) While $Startloop <> 0 $p = $p+1 $Startloop = StringCompare($try,BinaryMid($fileDataBin,$p,8)) If $p > 1000 Then ExitLoop WEnd Link to comment Share on other sites More sharing options...
czardas Posted October 8, 2012 Share Posted October 8, 2012 (edited) If it's doing what you intend it to do, then that's great. This question got me thinking about some related stuff. Thanks for updating us. Edited October 8, 2012 by czardas operator64 ArrayWorkshop 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