Jump to content

Find Hex String


Recommended Posts

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

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

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 by FireFox
Link to comment
Share on other sites

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 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

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 by czardas
Link to comment
Share on other sites

Yep, let's wait what the op is looking for.

Good night,

UEZ

Edited 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...