Sign in to follow this  
Followers 0
Rozek

searching for text in a binary

4 posts in this topic

Hello!

I'm new to AutoIt and this forum, thus, please forgive me, should the following question look too much like that of a newbie...

In my AutoIt script, I have to look for some text within otherwise binary content (to be more precise: a binary file somewhere contains an XML document which I'm going to extract).

Loading the file into a binary is not a problem - but (since the file purposefully contains null bytes) searching for "<?xml" is one. I tried

- to BinaryToString(...) the binary - this sometimes even lead to a crash(!)

- to String(...) the binary - that gave me two characters per byte (measured with StringLen())

- to treat the binary as if it already were a string

None of the approaches was successfull, I was never able to find my pattern (neither with StringInStr(...,"<?xml") nor with StringRegExp(..., "<[?]xml", 1))

How can I search within a binary, convert the binary into an (ASCII) string which "ignores" the null bytes or just convert the null bytes into something else (as they are not relevant)

Thanks in advance for any help!

Kind regards,

Andreas Rozek

Share this post


Link to post
Share on other sites



I have no idea why BinaryToString would cause a crash... but did you open the file in Binary Mode first?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I used

local $InStream = FileOpen(...,16)

local $Content = FileRead($InStream)

FileClose($InStream)

local $hugo = BinaryToString($Content)

(not mentioning any error handling etc.)

Whether the script crashes or not depends on the actual file contents - some files let the script survive, others let it crash..

Kind regards,

Andreas Rozek

Share this post


Link to post
Share on other sites

I used

local $InStream = FileOpen(...,16)

local $Content = FileRead($InStream)

FileClose($InStream)

local $hugo = BinaryToString($Content)

(not mentioning any error handling etc.)

Whether the script crashes or not depends on the actual file contents - some files let the script survive, others let it crash..

Kind regards,

Andreas Rozek

So you don't really have a replication script to provide for us to help you?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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