def get_bininfo(bv): if bv is None: filename = "" if len(sys.argv) > 1: filename = sys.argv[1] else: filename = interaction.get_open_filename_input("Filename:") if filename is None: log.log_warn("No file specified") sys.exit(1) bv = BinaryViewType.get_view_of_file(filename) log.log_to_stdout(True) contents = "## %s ##\n" % os.path.basename(bv.file.filename) contents += "- START: 0x%x\n\n" % bv.start contents += "- ENTRY: 0x%x\n\n" % bv.entry_point contents += "- ARCH: %s\n\n" % bv.arch.name contents += "### First 10 Functions ###\n" contents += "| Start | Name |\n" contents += "|------:|:-------|\n" for i in range(min(10, len(bv.functions))): contents += "| 0x%x | %s |\n" % (bv.functions[i].start, bv.functions[i].symbol.full_name) contents += "### First 10 Strings ###\n" contents += "| Start | Length | String |\n" contents += "|------:|-------:|:-------|\n" for i in range(min(10, len(bv.strings))): start = bv.strings[i].start length = bv.strings[i].length string = bv.read(start, length) contents += "| 0x%x |%d | %s |\n" % (start, length, string) return contents
def get_bininfo(bv): if bv is None: filename = "" if len(sys.argv) > 1: filename = sys.argv[1] else: filename = interaction.get_open_filename_input("Filename:") if filename is None: log.log_warn("No file specified") sys.exit(1) bv = BinaryViewType.get_view_of_file(filename) log.redirect_output_to_log() log.log_to_stdout(True) contents = "## %s ##\n" % bv.file.filename contents += "- START: 0x%x\n\n" % bv.start contents += "- ENTRY: 0x%x\n\n" % bv.entry_point contents += "- ARCH: %s\n\n" % bv.arch.name contents += "### First 10 Functions ###\n" contents += "| Start | Name |\n" contents += "|------:|:-------|\n" for i in xrange(min(10, len(bv.functions))): contents += "| 0x%x | %s |\n" % (bv.functions[i].start, bv.functions[i].symbol.full_name) contents += "### First 10 Strings ###\n" contents += "| Start | Length | String |\n" contents += "|------:|-------:|:-------|\n" for i in xrange(min(10, len(bv.strings))): start = bv.strings[i].start length = bv.strings[i].length string = bv.read(start, length) contents += "| 0x%x |%d | %s |\n" % (start, length, string) return contents
def main(args): log_to_stdout(LogLevel.InfoLog) if not os.path.exists(args.input_file): log_warn(f"input file: {args.input_file} does not exist") return 1 dir_path = os.path.dirname(os.path.realpath(args.output)) if not os.path.exists(dir_path): log_warn(f"Output path directory {dir_path} does not exist") return 1 try: platform: Platform = Platform[args.platform] except KeyError: log_warn(f"'{args.platform}' is not supported binja platform") return 1 with open(args.input_file) as fd: type_data = fd.read() if args.definitions: prepend_str = "" for defintion in args.definitions.split(","): prepend_str += f"#define {defintion} 1\n" type_data = "%s%s" % (prepend_str, type_data) types_path = [os.path.dirname(os.path.realpath(args.input_file))] type_res = platform.parse_types_from_source(type_data, filename=args.input_file, include_dirs=types_path) cur_typelib: TypeLibrary = TypeLibrary.new(Architecture[platform.arch.name], args.name) for name, type_obj in type_res.functions.items(): # log_info(f"Adding function {name}") cur_typelib.add_named_object(name, type_obj) for name, type_obj in type_res.types.items(): # log_info(f"Adding type {name}") cur_typelib.add_named_type(name, type_obj) cur_typelib.add_platform(platform) if args.alt_names: for name in args.alt_names.split(","): cur_typelib.add_alternate_name(name) if args.guid: cur_typelib.guid = args.guid cur_typelib.finalize() log_info(f"Wrote type library to {args.output}") cur_typelib.write_to_file(args.output) return 0
def get_bin_view(bv): if bv is None: filename = "" if len(sys.argv) > 1: filename = sys.argv[1] else: filename = interaction.get_open_filename_input("Filename:") if filename is None: log.log_warn("No file specified") sys.exit(1) bv = BinaryViewType.get_view_of_file(filename) log.log_to_stdout(True) return bv
def init_console(min_level=LogLevel.InfoLog): log.log_to_stdout(LogLevel.InfoLog)