Skip to content

Commit

Permalink
Merge branch 'string_slicer_integration-rebased-2024-08' into go-rust…
Browse files Browse the repository at this point in the history
…-new
  • Loading branch information
blattm committed Aug 28, 2024
2 parents f1d579b + 804b8e0 commit 62e35f6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions decompiler/frontend/binaryninja/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import binaryninja
from binaryninja import BinaryView
from binaryninja.types import SymbolType
from decompiler.frontend.binaryninja.rust_string_detection import RustStringDetection
from decompiler.task import DecompilerTask
from decompiler.util.options import Options

Expand Down Expand Up @@ -67,6 +68,9 @@ def lift(self, task: DecompilerTask):
function = self._get_binninja_function(task.function_identifier)
lifter, parser = self._create_lifter_parser(task.options)

rust_string_detection = RustStringDetection(self._bv, task.options)
rust_string_detection.run()

task.function_return_type = lifter.lift(function.return_type)
task.function_parameters = [lifter.lift(param_type) for param_type in function.type.parameters]

Expand Down
50 changes: 50 additions & 0 deletions decompiler/frontend/binaryninja/rust_string_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging

from binaryninja import BinaryView
from decompiler.util.options import Options
import sys

string_slicer_path = "/home/manuel/repos/"

class RustStringDetection:
"""TODO:"""

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._debug_submodules = options.getboolean("logging.debug-submodules")

def is_rust_binary(self):
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")):
return True
return False

def run(self):
"""
TODO:
"""
if not self._enabled:
return

if self._rust_binaries_only and not self.is_rust_binary():
logging.info("Rust String Slicer not executed: Not a Rust Binary")
return

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

if not RustStringSlice.check_binary_ninja_type_exists(self._bv):
RustStringSlice.create_binary_ninja_type(self._bv)
RecoverStringFromReadOnlyDataTask(bv=self._bv).run()

except Exception as e:
if self._debug_submodules:
raise RuntimeError(e)
logging.warning("Rust String Slicer failed. Please check if the tool is installed and the path is set correctly!")
return

0 comments on commit 62e35f6

Please sign in to comment.