Skip to content

Commit

Permalink
polish string slicer integration
Browse files Browse the repository at this point in the history
  • Loading branch information
blattm committed Aug 29, 2024
1 parent 9c577a4 commit ce163e9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
23 changes: 17 additions & 6 deletions decompiler/frontend/binaryninja/rust_string_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@
from binaryninja import BinaryView
from decompiler.util.options import Options

string_slicer_path = "/home/manuel/repos/"


class RustStringDetection:
"""TODO:"""
"""
This 'stage' detects certain Rust strings (string slices), which are struct based strings.
It requires the RustStringSlicer. A path to the tool needs to be configured via the options.
The stage is executed before lifting, as it uses the Binary Ninja API to identify string slices
and 'mark' them, by assigning the appropriate type.
It can be configured to run always, never, or for Rust binaries only.
"""

def __init__(self, binary_view: BinaryView, options: Options):
self._bv = binary_view
# TODO: add to default settings, change fallback
self._enabled = options.getboolean("rust-string-detection.enabled", fallback=True)
self._rust_binaries_only = options.getboolean("rust-string-detection.rust_binaries_only", fallback=True)
self._string_slicer_path = options.getstring("rust-string-detection.string_slicer_path")
self._debug_submodules = options.getboolean("logging.debug-submodules")

def is_rust_binary(self):
"""
Simple heurstic to determine, whether the binary is a Rust binary.
"""
for _ in self._bv.find_all_data(self._bv.start, self._bv.end, "rustc".encode("utf-8")):
return True
for _ in self._bv.find_all_data(self._bv.start, self._bv.end, "cargo".encode("utf-8")):
Expand All @@ -26,7 +35,9 @@ def is_rust_binary(self):

def run(self):
"""
TODO:
Runs the Rust String Slicer, if the required conditions are met.
String Slicer's path will be added to Python's path before importing the module.
"""
if not self._enabled:
return
Expand All @@ -37,7 +48,7 @@ def run(self):

logging.info("Starting Rust String Slicer")
try:
sys.path.append(string_slicer_path)
sys.path.append(self._string_slicer_path)
from rust_string_slicer.binja_plugin.actions import RecoverStringFromReadOnlyDataTask, RustStringSlice

if not RustStringSlice.check_binary_ninja_type_exists(self._bv):
Expand Down
30 changes: 30 additions & 0 deletions decompiler/util/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,36 @@
"is_hidden_from_cli": false,
"argument_name": "--remove-no-return-boilerplate"
},
{
"dest": "rust-string-detection.enabled",
"default": true,
"title": "Detect Rust string slices",
"type": "boolean",
"description": "enable the detection of Rust string slices. Requires setting up Rust String Slicer",
"is_hidden_from_gui": false,
"is_hidden_from_cli": false,
"argument_name": "--detect-rust-string-slices"
},
{
"dest": "rust-string-detection.rust_binaries_only",
"default": true,
"title": "Restrict string slice detection to Rust binaries",
"type": "boolean",
"description": "string slices will only be detected for Rust binaries",
"is_hidden_from_gui": false,
"is_hidden_from_cli": false,
"argument_name": "--string-slices-rust-only"
},
{
"dest": "rust-string-detection.string_slicer_path",
"default": "",
"title": "Rust String Slicer Path",
"type": "string",
"description": "Path to the Rust String Slicer folder",
"is_hidden_from_gui": false,
"is_hidden_from_cli": false,
"argument_name": "--rust-string-slicer-path"
},
{
"dest": "array-access-detection.enabled",
"default": true,
Expand Down

0 comments on commit ce163e9

Please sign in to comment.