Extracting strings from binary file using regex an

2019-07-31 19:36发布

Trying to figure out how to extract a string off characters from a binary file and convert them to ascii. The characters are a barcode, which is preceded by a constant string of text. My thought is to figure out what the HEX pattern is for the string constant string and extract the string based on that, then convert the HEX to ASCII.

Problem is I don't know how get perl to "read" the file, or "see" what it's seeing. Meaning that if the file was a text file, might do something like this - Perl: extracting data from text using regex - but I don't know how to figure out what the binary pattern I'm targeting is; that said, I've posted one view of this data here: Extracting “plaintext” header from HEX file using Perl

How do I do this in Perl?

1条回答
乱世女痞
2楼-- · 2019-07-31 20:27

Here's one easy way to do it:

perl -nlwe "print for m/\w{2,}/g" < bla.exe

That'll print all strings composed of \w{2,}, i.e. legacy word characters exclusively, and at least two of them.

查看更多
登录 后发表回答