Extracting strings from binary file using regex and converting to ASCII — Using Perl

你。 提交于 2019-12-13 19:37:13

问题


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:


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.



来源:https://stackoverflow.com/questions/5954784/extracting-strings-from-binary-file-using-regex-and-converting-to-ascii-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!