Jump to content
Sign in to follow this  
typhoon

Using StringRegExp with binary cleartext

Recommended Posts

typhoon

I read in a file to $buffer, and then I try using StringRegExp on it. This works fine with a pure text file, but if the file is binary (with some clear text) the function seems to return prematurely (but without error). Specifically, for the file I'm reading in it only captures one match.

$array = StringRegExp($buffer, "path\d*:", 3)

I tried using binary mode with FileOpen, but in that case I get an invalid result code from StringRegExp.

I've tested the same code using a file that consists of only plain text; in that case it works.

Share this post


Link to post
Share on other sites
SmOke_N

I read in a file to $buffer, and then I try using StringRegExp on it. This works fine with a pure text file, but if the file is binary (with some clear text) the function seems to return prematurely (but without error). Specifically, for the file I'm reading in it only captures one match.

$array = StringRegExp($buffer, "path\d*:", 3)

I tried using binary mode with FileOpen, but in that case I get an invalid result code from StringRegExp.

I've tested the same code using a file that consists of only plain text; in that case it works.

You need to either have a string with no Nulls or you need to convert that string to binary ... Look at BinaryToString. Then you'll need to look for for your option in Hex ... path\d and your ":" will have to be the hex values.

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.

Share this post


Link to post
Share on other sites
Richard Robertson

The regular expressions functions are meant to work with standard strings. Have you tried calling String($buffer) using the binary mode?

Share this post


Link to post
Share on other sites
Community On Patrol

Hi typhoon,

Just a note on Regular Expressions and AutoIt in case you didn't know.

AutoIt uses the PCRE (Perl Compatible Regular Expressions) engine.

If you are using google for tutorials or just searching for specifics, keep this in mind when looking for expressions or help on expressions.

Some things that may help you along with future questions or concerns:

QuickStart

Tutorials

RegExCoach

Share this post


Link to post
Share on other sites
SmOke_N

Without the file to test, I'd say this may be close:

Local $s_file = "Txt.txt"
Local $h_open = FileOpen($s_file, 16)
Local $sv_text = FileRead($h_open)
FileClose($h_open)
Local $s_path = __StringToHex("path")
Local $s_numbers = __StringToHex("0123456789")
Local $s_colon = __StringToHex(":")
Local $a_sre = StringRegExp($sv_text, "(?i)(" & $s_path & "(?:" & _
                StringTrimRight(StringRegExpReplace($s_numbers, "(.{2})", "\[\1\]\|"), 1) & ")*" & $s_colon & ")", 3)

Func __StringToHex($s_string)
    Return Hex(StringToBinary($s_string))
EndFunc


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.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.