def getOffset(fn): ''' Find the first valid zlib header. ''' for result in binwalk.Modules().execute(fn, '-q', signature=True)[0].results: if result.description.lower().startswith('zlib') and result.valid: return result.offset return -1
def main(): with binwalk.Modules() as modules: try: if len(sys.argv) == 1: sys.stderr.write(modules.help()) sys.exit(1) # If no explicit module was enabled in the command line arguments, # run again with the default signature scan explicitly enabled. elif not modules.execute(): # Make sure the Signature module is loaded before attempting # an implicit signature scan; else, the error message received # by the end user is not very helpful. if hasattr(binwalk.modules, "Signature"): modules.execute(*sys.argv[1:], signature=True) else: sys.stderr.write("Error: Signature scans not supported; ") sys.stderr.write("make sure you have python-lzma installed and try again.\n") sys.exit(2) except binwalk.ModuleException as e: sys.exit(3)
#!/usr/bin/env python import sys import binwalk try: # Perform a signature scan against the files specified on the command line and suppress the usual binwalk output. for module in binwalk.Modules().execute(*sys.argv[1:], signature=True, quiet=True): print ("%s Results:" % module.name) for result in module.results: print ("\t%s 0x%.8X %s" % (result.file.name, result.offset, result.description)) except binwalk.ModuleException as e: pass
#!/usr/bin/env python import binwalk binwalk.Modules().execute()
def init(self): self.binwalk = binwalk.Modules(idc.GetIdbPath(), signature=True) self.menu_context = idaapi.add_menu_item("Search/", "binwalk scan", "Alt-9", 0, self.run, (None,)) return idaapi.PLUGIN_KEEP