/usr/bin/hachoir-subfile is in python-hachoir-subfile 0.5.3-2.
This file is owned by root:root, with mode 0o755.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #!/usr/bin/python
from hachoir_core.cmd_line import unicodeFilename
from hachoir_core.stream import FileInputStream
from hachoir_core.i18n import _
from hachoir_core import config
from hachoir_subfile.search import SearchSubfile
import hachoir_core
from sys import exit
from optparse import OptionGroup, OptionParser
def displayVersion(*args):
from hachoir_subfile.version import VERSION, WEBSITE
print _("Hachoir subfile version %s") % VERSION
print _("hachoir-core version %s") % hachoir_core.__version__
print
print _("Website: %s") % WEBSITE
exit(0)
def parseOptions():
parser = OptionParser(usage="%prog [options] filename [output_directory]")
common = OptionGroup(parser, "hachoir-subfile", _("Option of hachoir-subfile"))
common.add_option("--offset", help=_("Skip first bytes of input file"),
action="store", type='int', default=0)
common.add_option("--size", help=_("Maximum size of input file"),
action="store", type='int', default=None)
common.add_option("--category", help=_("Parser category list (separated with a comma)"),
action="store", type='str', default=None)
common.add_option("--parser", help=_("Parser identifier list (separated with a comma)"),
action="store", type='str', default=None)
common.add_option("--version", help=_("Display version and exit"),
action="callback", callback=displayVersion)
common.add_option("--quiet", help=_("Be quiet"),
action="store_true", default=False)
common.add_option("--profiler", help=_("Run profiler"),
action="store_true", default=False)
common.add_option("--debug", help=_("Enable debug mode"),
action="store_true", default=False)
parser.add_option_group(common)
values, arguments = parser.parse_args()
if len(arguments) == 1:
filename, output = arguments[0], None
elif len(arguments) == 2:
filename, output = arguments
else:
parser.print_help()
exit(1)
return values, filename, output
def displaySearchStat(subfile):
stats = [ (parser.tags["id"], stats[0], stats[1])
for parser, stats in subfile.stats.iteritems() ]
print
print "[ Match statistics ]"
total_hit = 0
total_valid = 0
if stats:
stats.sort(key=lambda values: values[1])
for parser_id, hit, valid in stats:
print " - %s: %u hit/%u valid" % (parser_id, hit, valid)
total_hit += hit
total_valid += valid
print
else:
print "(no match)"
print "Total: %u hit/%u valid" % (total_hit, total_valid)
def runSearch(subfile, values):
# Load categories and parsers
categories = values.category
if categories:
categories = categories.split(",")
parsers = values.parser
if parsers:
parsers = parsers.split(",")
subfile.loadParsers(categories=categories, parser_ids=parsers)
# Search subfiles
ok = subfile.main()
# Dump statistics on debug mode
if values.debug:
displaySearchStat(subfile)
return ok
def main():
# Initialize
values, filename, output = parseOptions()
config.quiet = True
stream = FileInputStream(unicodeFilename(filename), real_filename=filename)
subfile = SearchSubfile(stream, values.offset, values.size)
subfile.verbose = not(values.quiet)
subfile.debug = values.debug
if output:
subfile.setOutput(output)
if values.profiler:
from hachoir_core.profiler import runProfiler
ok = runProfiler(runSearch, (subfile, values))
else:
ok = runSearch(subfile, values)
exit(int(not ok))
if __name__ == "__main__":
main()
|