Skip to content

Commit b600d52

Browse files
committed
fix: add ruff rules
1 parent 392f338 commit b600d52

File tree

6 files changed

+60
-28
lines changed

6 files changed

+60
-28
lines changed

.ruff.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[lint]
2+
select = ["F", "SIM", "C4", "B", "LOG", "RET", "TC", "E", "W", "PL"]
3+
ignore = ["E501"]

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@ current binary view and any successive binary view in the current session.
1414
A potential workflow for this plugin would be to compile an open source library with debug information, load it into
1515
Binary Ninja,
1616
run the debug info parser, and export it to a type library.
17-
18-
## Future Plans
19-
- [ ] Headless support

__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ def is_valid(bv: BinaryView):
88
return bv.has_initial_analysis()
99

1010

11-
PluginCommand.register("Export As Type Library", "Compiles the exported function types into a type library",
12-
export.export_functions, is_valid)
13-
PluginCommand.register("Apply Type Library", "Loads and applies a type library to the current binary view",
14-
apply.load_library, is_valid)
11+
PluginCommand.register(
12+
"Export As Type Library",
13+
"Compiles the exported function types into a type library",
14+
export.export_functions,
15+
is_valid,
16+
)
17+
PluginCommand.register(
18+
"Apply Type Library",
19+
"Loads and applies a type library to the current binary view",
20+
apply.load_library,
21+
is_valid,
22+
)

apply.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77

88
def get_library_path() -> Optional[str]:
9-
library_path = bn.TextLineField("Path to load type library:", "~/Desktop/libcapstone.bntl")
9+
library_path = bn.TextLineField(
10+
"Path to load type library:", "~/Desktop/libcapstone.bntl"
11+
)
1012
bn.get_form_input([library_path], "Apply Type Library Options")
1113
res_path = os.path.expanduser(library_path.result)
1214
if os.path.exists(res_path):
1315
return res_path
14-
else:
15-
return None
16+
return None
1617

1718

1819
def apply_library(bv: BinaryView, typelib_handle: TypeLibrary):
@@ -27,7 +28,7 @@ def apply_library(bv: BinaryView, typelib_handle: TypeLibrary):
2728
def load_library(bv: BinaryView):
2829
lib_path = get_library_path()
2930
if lib_path is None:
30-
bn.log_error(f"Supplied path was invalid")
31+
bn.log_error("Supplied path was invalid")
3132
return
3233
bn.log_debug(f"lib_path: {lib_path}")
3334
typelib_handle = TypeLibrary.load_from_file(lib_path)

export.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from binaryninja import TypeLibrary, Function
88

99

10-
def create_type_library(log: Logger, bv: BinaryView, func_list: list[Function], config: dict) -> TypeLibrary:
10+
def create_type_library(
11+
log: Logger, bv: BinaryView, func_list: list[Function], config: dict
12+
) -> TypeLibrary:
1113
typelib = TypeLibrary.new(bv.arch, config["lib_name"])
1214
typelib.add_platform(bv.platform)
1315

@@ -24,49 +26,70 @@ def create_type_library(log: Logger, bv: BinaryView, func_list: list[Function],
2426
return typelib
2527

2628

27-
def get_funcs_from_syms(log: Logger, bv: BinaryView, func_syms: list[CoreSymbol]) -> list[Function]:
29+
def get_funcs_from_syms(
30+
log: Logger, bv: BinaryView, func_syms: list[CoreSymbol]
31+
) -> list[Function]:
2832
func_list = []
2933
for sym in func_syms:
3034
res = bv.get_function_at(sym.address)
3135
if res is None:
32-
log.log_warn(f"Function: {sym.name} at address: {sym.address} does not exist in the current binary view")
36+
log.log_warn(
37+
f"Function: {sym.name} at address: {sym.address} does not exist in the current binary view"
38+
)
3339
else:
3440
func_list.append(res)
3541

3642
return func_list
3743

3844

3945
def get_config_options(bv: BinaryView):
40-
lib_name = bn.TextLineField("Type Library Name:", f"{os.path.basename(bv.file.filename)}")
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"~/{os.path.basename(bv.file.filename)}.bntl")
46+
lib_name = bn.TextLineField(
47+
"Type Library Name:", f"{os.path.basename(bv.file.filename)}"
48+
)
49+
alternate_names = bn.TextLineField(
50+
"Alternative Names (optional):", "lib_musl.so;lib_musl.so.5"
51+
)
52+
export_path = bn.TextLineField(
53+
"Path to store type library:", f"~/{os.path.basename(bv.file.filename)}.bntl"
54+
)
4355
dependency_name = bn.TextLineField("Dependency Name (optional):")
44-
bn.get_form_input([lib_name, alternate_names, export_path, dependency_name], "Export as Type Library Options")
56+
bn.get_form_input(
57+
[lib_name, alternate_names, export_path, dependency_name],
58+
"Export as Type Library Options",
59+
)
4560

46-
config = {"lib_name": lib_name.result, "alternate_names": alternate_names.result, "export_path": os.path.expanduser(export_path.result),
47-
"dependency_name": dependency_name.result}
48-
return config
61+
return {
62+
"lib_name": lib_name.result,
63+
"alternate_names": alternate_names.result,
64+
"export_path": os.path.expanduser(export_path.result),
65+
"dependency_name": dependency_name.result,
66+
}
4967

5068

5169
def export_functions(bv: BinaryView):
5270
log = bv.create_logger("TypeLib_Exporter")
5371
config = get_config_options(bv)
54-
if not os.path.exists(os.path.dirname(config['export_path'])):
55-
log.log_error(f"Please specify a path to export the type library: {config['export_path']}")
72+
if not os.path.exists(os.path.dirname(config["export_path"])):
73+
log.log_error(
74+
f"Please specify a path to export the type library: {config['export_path']}"
75+
)
5676
return
5777
if len(config["lib_name"]) == 0:
5878
log.log_error(f"lib name: [{config['lib_name']}]")
5979
log.log_error("Please specify a name for the type library")
6080
return
6181

6282
func_list = bv.get_symbols_of_type(SymbolType.FunctionSymbol)
63-
export_func_syms = [sym for sym in func_list
64-
if sym.binding == SymbolBinding.GlobalBinding or sym.binding == SymbolBinding.WeakBinding]
83+
export_func_syms = [
84+
sym
85+
for sym in func_list
86+
if sym.binding in (SymbolBinding.GlobalBinding, SymbolBinding.WeakBinding)
87+
]
6588

6689
export_funcs = get_funcs_from_syms(log, bv, export_func_syms)
6790
log.log_debug(f"Discovered {len(export_funcs)} exported functions")
6891

6992
typelib = create_type_library(log, bv, export_funcs, config)
7093
typelib.finalize()
7194
log.log_info(f"Exported {len(export_funcs)} functions to {config['export_path']}")
72-
typelib.write_to_file(config['export_path'])
95+
typelib.write_to_file(config["export_path"])

plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"description": "This plugin compiles exported functions and its corresponding types into a type library. Type libraries can also be applied to existing bndbs through this plugin.",
1313
"license": {
1414
"name": "MIT",
15-
"text": "Copyright (c) 2022 Scott Lagler\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
15+
"text": "Copyright (c) 2025 Scott Lagler\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
1616
},
1717
"platforms": [
1818
"Darwin",
@@ -30,7 +30,7 @@
3030
"installers": [],
3131
"other": []
3232
},
33-
"version": "2.2",
33+
"version": "2.3",
3434
"author": "SmoothHacker",
3535
"minimumbinaryninjaversion": 3469
3636
}

0 commit comments

Comments
 (0)