(bv, filename=None)
| 27 | |
| 28 | |
| 29 | def get_bininfo(bv, filename=None): |
| 30 | if bv is None: |
| 31 | if not (os.path.isfile(filename) and os.access(filename, os.R_OK)): |
| 32 | return("Cannot read {}\n".format(filename)) |
| 33 | bv = load(filename, options={'analysis.mode': 'basic', 'analysis.linearSweep.autorun' : False}) |
| 34 | else: |
| 35 | filename = "" |
| 36 | if len(sys.argv) > 1: |
| 37 | filename = sys.argv[1] |
| 38 | else: |
| 39 | filename = interaction.get_open_filename_input("Filename:") |
| 40 | if filename is None: |
| 41 | log_warn("No file specified") |
| 42 | sys.exit(1) |
| 43 | |
| 44 | bv = load(filename) |
| 45 | log_to_stdout(LogLevel.InfoLog) |
| 46 | |
| 47 | contents = "## %s ##\n" % os.path.basename(bv.file.filename) |
| 48 | contents += "- START: 0x%x\n\n" % bv.start |
| 49 | contents += "- ENTRY: 0x%x\n\n" % bv.entry_point |
| 50 | contents += "- ARCH: %s\n\n" % bv.arch.name |
| 51 | contents += "### First 10 Functions ###\n" |
| 52 | |
| 53 | contents += "| Start | Name |\n" |
| 54 | contents += "|------:|:-------|\n" |
| 55 | functions = list(bv.functions) |
| 56 | for i in range(min(10, len(functions))): |
| 57 | contents += "| 0x%x | %s |\n" % (functions[i].start, functions[i].symbol.full_name) |
| 58 | |
| 59 | contents += "### First 10 Strings ###\n" |
| 60 | contents += "| Start | Length | String |\n" |
| 61 | contents += "|------:|-------:|:-------|\n" |
| 62 | for i in range(min(10, len(bv.strings))): |
| 63 | start = bv.strings[i].start |
| 64 | length = bv.strings[i].length |
| 65 | string = bv.strings[i].value |
| 66 | contents += "| 0x%x |%d | %s |\n" % (start, length, string) |
| 67 | |
| 68 | # Note that we need to close BV file handles that we opened to prevent a |
| 69 | # memory leak due to a circular reference between BinaryViews and the |
| 70 | # FileMetadata that backs them |
| 71 | |
| 72 | if filename != "": |
| 73 | bv.file.close() |
| 74 | return contents |
| 75 | |
| 76 | |
| 77 | def display_bininfo(bv): |
no test coverage detected