Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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


Expand Down Expand Up @@ -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'])