Skip to content

Commit

Permalink
fix: improved efficiency of docker mount in software plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke authored and maringuu committed Nov 27, 2024
1 parent ea694e5 commit 00dc1f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_version_for_component(self, result, file_object: FileObject):
'function_name': result['meta']['_version_function'],
}
versions.update(
extract_data_from_ghidra(file_object.binary, input_data, config.backend.docker_mount_base_dir)
extract_data_from_ghidra(file_object.file_path, input_data, config.backend.docker_mount_base_dir)
)
if '' in versions and len(versions) > 1: # if there are actual version results, remove the "empty" result
versions.remove('')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@

from helperFunctions.docker import run_docker_container

CONTAINER_TARGET_PATH = '/work'
CONTAINER_TARGET_PATH = Path('/work')
INPUT_PATH = CONTAINER_TARGET_PATH / 'ghidra_input'
DOCKER_IMAGE = 'fact/format_string_resolver'
DOCKER_OUTPUT_FILE = 'ghidra_output.json'
TIMEOUT = 300
KEY_FILE = 'key_file'


def extract_data_from_ghidra(input_file_data: bytes, input_data: dict, path: str) -> list[str]:
def extract_data_from_ghidra(file_path: str, input_data: dict, path: str) -> list[str]:
with TemporaryDirectory(prefix='FSR_', dir=path) as tmp_dir:
tmp_dir_path = Path(tmp_dir)
ghidra_input_file = tmp_dir_path / 'ghidra_input'
(tmp_dir_path / KEY_FILE).write_text(json.dumps(input_data))
ghidra_input_file.write_bytes(input_file_data)
with suppress(DockerException, TimeoutError):
proc = run_docker_container(
DOCKER_IMAGE,
logging_label='FSR',
timeout=TIMEOUT,
command=f'/work/ghidra_input {CONTAINER_TARGET_PATH}',
command=f'{INPUT_PATH} {CONTAINER_TARGET_PATH}',
mounts=[
Mount(CONTAINER_TARGET_PATH, tmp_dir, type='bind'),
Mount(str(CONTAINER_TARGET_PATH), tmp_dir, type='bind'),
Mount(str(INPUT_PATH), file_path, type='bind', read_only=True),
],
)
if 'Traceback' in proc.stderr:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
def test_extract_data_from_ghidra(backend_config, test_file, input_data, expected_output):
test_file = Path(__file__).parent / 'data' / test_file
result = extract_data_from_ghidra(test_file.read_bytes(), input_data, str(backend_config.docker_mount_base_dir))
result = extract_data_from_ghidra(str(test_file), input_data, str(backend_config.docker_mount_base_dir))
assert len(result) == 1
assert result == expected_output

Expand Down

0 comments on commit 00dc1f3

Please sign in to comment.