Skip to content

Commit c3329cb

Browse files
committed
feat: add ui dialog for config options
1 parent 2010ebf commit c3329cb

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

__init__.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import os
22

3+
import binaryninja as bn
34
from binaryninja import BinaryView, Function
45
from binaryninja import CoreSymbol, Logger
56
from binaryninja import PluginCommand
67
from binaryninja import SymbolType, SymbolBinding
78
from binaryninja import TypeLibrary
89

910

10-
def create_type_library(log: Logger, bv: BinaryView, func_list: list[Function]) -> TypeLibrary:
11+
def create_type_library(log: Logger, bv: BinaryView, func_list: list[Function], config: dict) -> TypeLibrary:
1112
typelib = TypeLibrary.new(bv.arch, os.path.basename(bv.file.filename))
1213
typelib.add_platform(bv.platform)
14+
15+
if "alternate_names" not in config:
16+
name_list = [name.strip() for name in config["alternate_names"].split(";")]
17+
for name in name_list:
18+
typelib.add_alternate_name(name)
19+
20+
if "dependency_name" not in config:
21+
typelib.dependency_name = config["dependency_name"]
1322
log.log_debug(f"Exporting {len(func_list)} functions to a type library")
1423
for func in func_list:
1524
bv.export_object_to_library(typelib, func.name, func.function_type)
@@ -28,8 +37,23 @@ def get_funcs_from_syms(log: Logger, bv: BinaryView, func_syms: list[CoreSymbol]
2837
return func_list
2938

3039

40+
def get_config_options(bv: BinaryView):
41+
alternate_names = bn.TextLineField("Alternative Names (optional):", "lib_musl.so;lib_musl.so.5")
42+
export_path = bn.TextLineField("Path to store type library:", f"{bv.file.filename}.bntl")
43+
dependency_name = bn.TextLineField("Dependency Name (optional):")
44+
bn.get_form_input([alternate_names, export_path, dependency_name], "Export as Type Library Options")
45+
46+
config = {"alternate_names": alternate_names.result, "export_path": export_path.result,
47+
"dependency_name": dependency_name.result}
48+
return config
49+
50+
3151
def export_functions(bv: BinaryView):
3252
log = bv.create_logger("TypeLib_Exporter")
53+
config = get_config_options(bv)
54+
if not os.path.exists(config['export_path']):
55+
log.log_error("Please specify a path to export the type library")
56+
return
3357

3458
func_list = bv.get_symbols_of_type(SymbolType.FunctionSymbol)
3559
export_func_syms = [sym for sym in func_list
@@ -38,10 +62,10 @@ def export_functions(bv: BinaryView):
3862
export_funcs = get_funcs_from_syms(log, bv, export_func_syms)
3963
log.log_debug(f"Discovered {len(export_funcs)} exported functions")
4064

41-
typelib = create_type_library(log, bv, export_funcs)
65+
typelib = create_type_library(log, bv, export_funcs, config)
4266
typelib.finalize()
43-
log.log_info(f"Exported {len(export_funcs)} functions to {os.path.basename(bv.file.filename)}.bntl")
44-
typelib.write_to_file(f"~/{os.path.basename(bv.file.filename)}.bntl")
67+
log.log_info(f"Exported {len(export_funcs)} functions to {config['export_path']}")
68+
typelib.write_to_file(config['export_path'])
4569
return
4670

4771

0 commit comments

Comments
 (0)