Run the program
()
| 60 | |
| 61 | |
| 62 | def main() -> None: |
| 63 | """Run the program""" |
| 64 | args = _parse_args() |
| 65 | _setup_logger(args.debug) |
| 66 | |
| 67 | files = _get_directory_listing(args.path) |
| 68 | for _file in files: |
| 69 | log_info(f"Running base address detection analysis on '{_file}'...") |
| 70 | bad = BaseAddressDetection(_file) |
| 71 | arch = Architecture[args.arch] if args.arch else None |
| 72 | if not bad.detect_base_address(analysis=args.analysis, arch=arch): |
| 73 | log_error("Base address detection analysis failed") |
| 74 | continue |
| 75 | |
| 76 | json_dict = dict() |
| 77 | json_dict["filename"] = path.basename(_file) |
| 78 | json_dict["preferred_candidate"] = dict() |
| 79 | json_dict["preferred_candidate"]["address"] = f"0x{bad.preferred_base_address:x}" |
| 80 | json_dict["preferred_candidate"]["confidence"] = bad.confidence |
| 81 | json_dict["aborted"] = bad.aborted |
| 82 | json_dict["last_tested"] = f"0x{bad.last_tested_base_address:x}" |
| 83 | json_dict["candidates"] = dict() |
| 84 | for baseaddr, score in bad.scores: |
| 85 | json_dict["candidates"][f"0x{baseaddr:x}"] = dict() |
| 86 | json_dict["candidates"][f"0x{baseaddr:x}"]["score"] = score |
| 87 | json_dict["candidates"][f"0x{baseaddr:x}"]["function hits"] = bad.get_function_hits(baseaddr) |
| 88 | json_dict["candidates"][f"0x{baseaddr:x}"]["string hits"] = bad.get_string_hits(baseaddr) |
| 89 | json_dict["candidates"][f"0x{baseaddr:x}"]["data hits"] = bad.get_data_hits(baseaddr) |
| 90 | if args.reasons: |
| 91 | json_dict["candidates"][f"0x{baseaddr:x}"]["reasons"] = dict() |
| 92 | for reason in bad.get_reasons(baseaddr): |
| 93 | json_dict["candidates"][f"0x{baseaddr:x}"]["reasons"][f"0x{reason.pointer:x}"] = { |
| 94 | "poi_offset": f"0x{reason.offset:x}", |
| 95 | "poi_type": reason.type, |
| 96 | } |
| 97 | |
| 98 | print(json.dumps(json_dict, indent=4)) |
| 99 | |
| 100 | |
| 101 | if __name__ == "__main__": |
no test coverage detected