Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ofrak_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Remove test dependencies that are already in the global `requirements-dev.txt` ([#695](https://github.com/redballoonsecurity/ofrak/pull/695))

### Fixed
- Fix ELF modifier tests writing generated artifacts into source tree instead of tmp_path ([#705](https://github.com/redballoonsecurity/ofrak/pull/705))
- Fix `Resource.get_attributes` docstring to match implementation ([#692](https://github.com/redballoonsecurity/ofrak/pull/692))
- Fix GUI serialization of enum values and script creator generating invalid Python syntax for enum values
- `build_image.py` uses `OFRAK_DIR` from `extra_build_args` to identify `pytest_ofrak` location for develop builds ([#657](https://github.com/redballoonsecurity/ofrak/pull/657/))
Expand Down
23 changes: 12 additions & 11 deletions ofrak_core/tests/components/test_elf_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- REQ3.4
"""
import os
import shutil
import subprocess
from typing import Optional

Expand Down Expand Up @@ -49,9 +50,7 @@
from ofrak import OFRAKContext, Resource


async def test_elf_add_symbols(
ofrak_context: OFRAKContext, elf_executable_file, elf_test_directory
):
async def test_elf_add_symbols(ofrak_context: OFRAKContext, elf_executable_file, tmp_path):
"""
Tests insertion of new strings into an ELF executable.

Expand All @@ -76,20 +75,20 @@ async def test_elf_add_symbols(

await original_elf.run(ElfAddStringModifier, ElfAddStringModifierConfig(strings_to_add))

output_path = os.path.join(elf_test_directory, "program_with_newstrings")
output_path = str(tmp_path / "program_with_newstrings")
await original_elf.flush_data_to_disk(output_path)
strings_result = subprocess.run(["strings", output_path], capture_output=True)
new_strings = set(strings_result.stdout.decode().split("\n"))

assert new_strings.difference(original_strings) == set(strings_to_add)

result = subprocess.run([os.path.join(elf_test_directory, "program")])
result = subprocess.run([elf_executable_file])
assert result.returncode == 12


@pytest.mark.skipif_windows
async def test_elf_force_relocation(
ofrak_context: OFRAKContext, elf_object_file, elf_test_directory
ofrak_context: OFRAKContext, elf_object_file, elf_test_directory, tmp_path
):
"""
Tests symbol relocation modification to redirect function calls.
Expand Down Expand Up @@ -122,9 +121,11 @@ async def test_elf_force_relocation(
ElfRelocateSymbolsModifierConfig({foo_vaddr: bar_vaddr, bar_vaddr: foo_vaddr}),
)

await elf.resource.flush_data_to_disk(os.path.join(elf_test_directory, "program_relocated.o"))
subprocess.run(["make", "-C", elf_test_directory, "program_relocated"])
result = subprocess.run([os.path.join(elf_test_directory, "program_relocated")])
relocated_obj = str(tmp_path / "program_relocated.o")
await elf.resource.flush_data_to_disk(relocated_obj)
shutil.copy(os.path.join(elf_test_directory, "Makefile"), tmp_path)
subprocess.run(["make", "-C", str(tmp_path), "program_relocated"])
result = subprocess.run([str(tmp_path / "program_relocated")])
assert result.returncode == 24


Expand Down Expand Up @@ -156,7 +157,7 @@ async def test_elf_force_relocation(
async def test_modifier(
ofrak_context: OFRAKContext,
elf_executable_file,
elf_test_directory,
tmp_path,
modifier,
modifier_config,
test_view,
Expand All @@ -183,7 +184,7 @@ async def test_modifier(
for view in views:
for entry in await view.get_entries():
await entry.resource.run(modifier, modifier_config)
mod_path = elf_executable_file + "_mod"
mod_path = str(tmp_path / "program_mod")
await elf.resource.flush_data_to_disk(mod_path)
mod_elf = await ofrak_context.create_root_resource_from_file(mod_path)
await mod_elf.unpack()
Expand Down
5 changes: 3 additions & 2 deletions ofrak_core/tests/components/test_patch_from_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def test_patch_from_source_modifier(
ofrak_context: OFRAKContext,
large_elf_file,
patch_file,
tmp_path,
) -> None:
"""
Tests the patch from source modifier functionality (REQ6.2).
Expand Down Expand Up @@ -152,9 +153,9 @@ async def apply_patch(resource: Resource, source_dir: str, new_segment: ElfProgr
resource = await ofrak_context.create_root_resource_from_file(large_elf_file)
new_segment = await add_and_return_segment(resource, 0x440000, 0x2000)

output_file_name = os.path.join(os.path.dirname(patch_file), "test_patch")
output_file_name = str(tmp_path / "test_patch")

source_dir = os.path.join(os.path.dirname(patch_file))
source_dir = os.path.dirname(patch_file)

await apply_patch(resource, source_dir, new_segment)
await call_new_segment_instead(resource, new_segment)
Expand Down
2 changes: 1 addition & 1 deletion ofrak_core/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "3.4.0rc5"
VERSION = "3.4.0rc6"
Loading