diff --git a/export.py b/export.py index 0da06ab..dd54836 100644 --- a/export.py +++ b/export.py @@ -4,10 +4,9 @@ from binaryninja import BinaryView from binaryninja import CoreSymbol, Logger from binaryninja import SymbolType, SymbolBinding -from binaryninja import TypeLibrary, Function +from binaryninja import TypeLibrary, Function, Metadata - -def create_type_library(log: Logger, bv: BinaryView, func_list: list[Function], config: dict) -> TypeLibrary: +def create_type_library(log: Logger, bv: BinaryView, export_func_syms: list[CoreSymbol], config: dict) -> TypeLibrary: typelib = TypeLibrary.new(bv.arch, config["lib_name"]) typelib.add_platform(bv.platform) @@ -18,9 +17,19 @@ def create_type_library(log: Logger, bv: BinaryView, func_list: list[Function], if "dependency_name" in config: typelib.dependency_name = config["dependency_name"] - log.log_debug(f"Exporting {len(func_list)} functions to a type library") + + log.log_info(f'Exporting {len(export_func_syms)} ordinals to type library') + ordinals = {sym.ordinal: sym.name for sym in export_func_syms} + typelib.store_metadata('ordinals', Metadata(ordinals)) + + func_list = get_funcs_from_syms(log, bv, export_func_syms) + log.log_debug(f"Exporting {len(func_list)} functions to type library") + for func in func_list: - bv.export_object_to_library(typelib, func.name, func.function_type) + bv.export_object_to_library(typelib, func.name, func.type) + + log.log_info(f"Exported {len(func_list)} functions to {config['export_path']}") + return typelib @@ -63,10 +72,6 @@ def export_functions(bv: BinaryView): export_func_syms = [sym for sym in func_list if sym.binding == SymbolBinding.GlobalBinding or sym.binding == SymbolBinding.WeakBinding] - export_funcs = get_funcs_from_syms(log, bv, export_func_syms) - log.log_debug(f"Discovered {len(export_funcs)} exported functions") - - typelib = create_type_library(log, bv, export_funcs, config) + typelib = create_type_library(log, bv, export_func_syms, config) typelib.finalize() - log.log_info(f"Exported {len(export_funcs)} functions to {config['export_path']}") typelib.write_to_file(config['export_path'])