简体   繁体   English

是否存在类似于正则表达式的语言,用于从二进制文件中匹配/提取数据?

[英]Is there a regex-like language for matching / extracting data from binary files?

I was looking at some custom code to read a binary file today and realized that surely this should be a job for a regular language, similar to regexs for matching, extracting data from text. 今天,我正在看一些自定义代码以读取二进制文件,并且意识到这肯定是常规语言的工作,类似于用于从文本中提取数据的匹配正则表达式。

Is there anything like this? 有没有这样的东西? A fairly standard convention for notating a regular language to parse binary files? 一个相当标准的约定,用于指定一种常规语言来解析二进制文件? Particularly one which has implementations / wrappers in several programming languages? 尤其是其中一种具有几种编程语言的实现/包装器?

Is there anything like this? 有没有这样的东西?

Yes. 是。 It is called - regexp. 它称为-regexp。 Binary files are simply strings with 8-bit "encoding". 二进制文件只是带有8位“编码”的字符串。

However, binary files can be encrypted, or can have non-linear structure, in which case you need to read them using the tools applicable to the structure (just like you don't use regexps for, eg XML, JSON, or similar structured text strings). 但是,二进制文件可以被加密,也可以具有非线性结构,在这种情况下,您需要使用适用于该结构的工具来读取它们(就像您不对XML,JSON或类似结构化的文件使用正则表达式一样)文字字符串)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM