Jump to content
Sign in to follow this  
deerhunt713

Find Hex String

Recommended Posts

deerhunt713

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

Share this post


Link to post
Share on other sites
stormbreaker

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

Share this post


Link to post
Share on other sites
czardas

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 by czardas
  • Like 1

Share this post


Link to post
Share on other sites
FireFox

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
  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
UEZ

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
  • Like 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
czardas

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! :thumbsup:

  • Like 1

Share this post


Link to post
Share on other sites
czardas

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

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
deerhunt713

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

Share this post


Link to post
Share on other sites
czardas

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

Share this post


Link to post
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
Sign in to follow this  

×