/usr/share/pyshared/hachoir_subfile/pattern.py is in python-hachoir-subfile 0.5.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from hachoir_parser import QueryParser
from hachoir_regex import PatternMatching
class HachoirPatternMatching(PatternMatching):
def __init__(self, categories=None, parser_ids=None):
PatternMatching.__init__(self)
# Load parser list
tags = []
if categories: tags += [ ("category", cat) for cat in categories ]
if parser_ids: tags += [ ("id", parser_id) for parser_id in parser_ids ]
if tags : tags += [ None ]
parser_list = QueryParser(tags)
# Create string patterns
for parser in parser_list:
for (magic, offset) in parser.getParserTags().get("magic",()):
self.addString(magic, (offset, parser))
# Create regex patterns
for parser in parser_list:
for (regex, offset) in parser.getParserTags().get("magic_regex",()):
self.addRegex(regex, (offset, parser))
self.commit()
def search(self, data):
for start, stop, item in PatternMatching.search(self, data):
yield (item.user[1], start*8 - item.user[0])
|