Jump to content

Find String in Binary File


Andre
 Share

Recommended Posts

Hi,

Is there an way to find an String in an binary File ?

When so, it would then be nice to stop searching when found.

Andre

What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!
Link to comment
Share on other sites

Hi,

Too bad, is not what i want.

I want to search the header of an binary file and pass the result to AutoIt.

Andre

What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!
Link to comment
Share on other sites

Hi,

Too bad, is not what i want.

I want to search the header of an binary file and pass the result to AutoIt.

Andre

<{POST_SNAPBACK}>

As long as you are not looking for the null character you can loop through the binary file just like a text file. It would look something like this (untested):

Func SearchBinFile( $binFile, $strSearch )
   $file = FileOpen( $binFile )

   While 1

      $currText = FileRead( $file, StringLen($strSearch) )

      If( @error = -1 ) Then
         Return 0
      EndIf

      If( $currText = $strSearch ) Then
       ; Place code here to do when string is found 
        Return 1
      EndIf

   Wend

EndFunc

It only tells you if it is found, but you can change it to do whatever you need. It should work. Hope it helps!

*** Matt @ MPCS

Link to comment
Share on other sites

Hi,

I Changed you're code a bit and now it's working like the way i want it.

If SearchBinFile('c:\tmp\renamemaster.exe','This',9) Then
   MsgBox(4096,'Found','Found it!')
EndIf


; ----------------------------------------------------------------------------
; Functions
; ----------------------------------------------------------------------------

Func SearchBinFile( $binFile, $strSearch,$Inputcounter )

 Dim $CurrText, $StrSearch
 Dim $File, $BinFile
 Dim $Counter, $InputCounter

  $file = FileOpen( $binFile,0 )

  While 1

     $currText = FileRead( $file, StringLen($strSearch) )
     $Counter = StringLen($strSearch) + $Counter
     
     If $Counter >= $InputCounter Then
        Return 0
     EndIf

     If( @error = -1 ) Then
        Return 0
     EndIf

     If( $currText = $strSearch ) Then
      Return 1
     EndIf

  Wend

EndFunc

Andre

What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!
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...