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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ build/
dist/
.coverage*
**/license.json
assets/*_ghidra
**/assets/*_ghidra/
8 changes: 5 additions & 3 deletions disassemblers/ofrak_angr/tests/test_decompilation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""
Test the decompilation functionality within the OFRAK Angr disassembler.
"""
from typing import List
import os
from typing import List

from ofrak.core.complex_block import ComplexBlock
from ofrak.core.decompilation import DecompilationAnalysis, DecompilationAnalyzer
from ofrak.ofrak_context import OFRAKContext
from ofrak.core.complex_block import ComplexBlock
from ofrak.service.resource_service_i import ResourceFilter
from pytest_ofrak import ASSETS_DIR


async def test_angr_decompilation(ofrak_context: OFRAKContext):
Expand All @@ -20,7 +22,7 @@ async def test_angr_decompilation(ofrak_context: OFRAKContext):
"""

root_resource = await ofrak_context.create_root_resource_from_file(
os.path.join(os.path.dirname(__file__), "assets/hello.x64.elf")
os.path.join(ASSETS_DIR, "hello.x64.elf")
)
await root_resource.unpack_recursively(
do_not_unpack=[
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
"""

import os
from typing import Dict, Tuple
from typing import Dict, List, Tuple

import pytest

import ofrak_cached_disassembly
from ofrak.core.code_region import CodeRegion
from ofrak.core.complex_block import ComplexBlock
from ofrak.core.decompilation import DecompilationAnalysis, DecompilationAnalyzer
from ofrak.core.filesystem import File
from ofrak.core.instruction import Instruction
from ofrak.ofrak_context import OFRAKContext
Expand All @@ -19,8 +24,12 @@
CachedAnalysisAnalyzerConfig,
CachedProgramUnpacker,
)

from ofrak_type import InstructionSetMode, List
from ofrak_type import InstructionSetMode
from pytest_ofrak import ASSETS_DIR
from pytest_ofrak.patterns.basic_block_unpacker import (
BasicBlockUnpackerUnpackAndVerifyPattern,
BasicBlockUnpackerTestCase,
)
from pytest_ofrak.patterns.code_region_unpacker import (
CodeRegionUnpackAndVerifyPattern,
CodeRegionUnpackerTestCase,
Expand All @@ -29,18 +38,8 @@
ComplexBlockUnpackerUnpackAndVerifyPattern,
ComplexBlockUnpackerTestCase,
)
from pytest_ofrak import ASSETS_DIR
from pytest_ofrak.patterns.basic_block_unpacker import (
BasicBlockUnpackerUnpackAndVerifyPattern,
BasicBlockUnpackerTestCase,
)
from ofrak.core.decompilation import DecompilationAnalysis, DecompilationAnalyzer
from ofrak.core.code_region import CodeRegion

import ofrak_cached_disassembly
from pytest_ofrak import ASSETS_DIR as PYTEST_OFRAK_ASSETS_DIR

ASSETS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "assets"))
LOCAL_ASSETS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "assets"))


@pytest.fixture(autouse=True)
Expand All @@ -64,12 +63,12 @@ async def root_resource(
ofrak_context: OFRAKContext,
test_id: str,
) -> Resource:
asset_path = os.path.join(PYTEST_OFRAK_ASSETS_DIR, unpack_verify_test_case.binary_filename)
asset_path = os.path.join(ASSETS_DIR, unpack_verify_test_case.binary_filename)
with open(asset_path, "rb") as f:
binary_data = f.read()
resource = await ofrak_context.create_root_resource(test_id, binary_data, tags=(File,))
CACHE_FILENAME = os.path.join(
os.path.join(PYTEST_OFRAK_ASSETS_DIR, "cache"), unpack_verify_test_case.binary_filename
os.path.join(ASSETS_DIR, "cache"), unpack_verify_test_case.binary_filename
)
await resource.run(
CachedAnalysisAnalyzer, config=CachedAnalysisAnalyzerConfig(filename=CACHE_FILENAME)
Expand All @@ -94,12 +93,12 @@ async def root_resource(
ofrak_context: OFRAKContext,
test_id: str,
) -> Resource:
asset_path = os.path.join(PYTEST_OFRAK_ASSETS_DIR, unpack_verify_test_case.binary_filename)
asset_path = os.path.join(ASSETS_DIR, unpack_verify_test_case.binary_filename)
with open(asset_path, "rb") as f:
binary_data = f.read()
resource = await ofrak_context.create_root_resource(test_id, binary_data, tags=(File,))
CACHE_FILENAME = os.path.join(
os.path.join(PYTEST_OFRAK_ASSETS_DIR, "cache"), unpack_verify_test_case.binary_filename
os.path.join(ASSETS_DIR, "cache"), unpack_verify_test_case.binary_filename
)
await resource.run(
CachedAnalysisAnalyzer, config=CachedAnalysisAnalyzerConfig(filename=CACHE_FILENAME)
Expand Down Expand Up @@ -145,12 +144,12 @@ async def root_resource(
ofrak_context: OFRAKContext,
test_id: str,
) -> Resource:
asset_path = os.path.join(PYTEST_OFRAK_ASSETS_DIR, unpack_verify_test_case.binary_filename)
asset_path = os.path.join(ASSETS_DIR, unpack_verify_test_case.binary_filename)
with open(asset_path, "rb") as f:
binary_data = f.read()
resource = await ofrak_context.create_root_resource(test_id, binary_data, tags=(File,))
CACHE_FILENAME = os.path.join(
os.path.join(PYTEST_OFRAK_ASSETS_DIR, "cache"), unpack_verify_test_case.binary_filename
os.path.join(ASSETS_DIR, "cache"), unpack_verify_test_case.binary_filename
)
await resource.run(
CachedAnalysisAnalyzer, config=CachedAnalysisAnalyzerConfig(filename=CACHE_FILENAME)
Expand All @@ -171,7 +170,7 @@ async def test_case(
binary_name, cache_name, mode = request.param
binary_path = os.path.join(ASSETS_DIR, binary_name)
resource = await ofrak_context.create_root_resource_from_file(binary_path)
cache_path = os.path.join(ASSETS_DIR, cache_name)
cache_path = os.path.join(LOCAL_ASSETS_DIR, cache_name)
await resource.run(
CachedAnalysisAnalyzer, config=CachedAnalysisAnalyzerConfig(filename=cache_path)
)
Expand Down Expand Up @@ -217,7 +216,7 @@ async def test_cached_decompilation(ofrak_context: OFRAKContext):
await root_resource.run(
CachedAnalysisAnalyzer,
config=CachedAnalysisAnalyzerConfig(
filename=os.path.join(ASSETS_DIR, "hello.x64.elf.json")
filename=os.path.join(LOCAL_ASSETS_DIR, "hello.x64.elf.json")
),
)
await root_resource.unpack_recursively(
Expand Down Expand Up @@ -273,7 +272,7 @@ async def test_cached_program_unpacker(pyghidra_components, ofrak_context: OFRAK
cached_analysis_view = await root_resource.run(
CachedAnalysisAnalyzer,
config=CachedAnalysisAnalyzerConfig(
filename=os.path.join(ASSETS_DIR, "hello.x64.elf.json")
filename=os.path.join(LOCAL_ASSETS_DIR, "hello.x64.elf.json")
),
)

Expand Down Expand Up @@ -301,7 +300,7 @@ async def test_load_cached_analysis(ofrak_context: OFRAKContext):
await root_resource.run(
CachedAnalysisAnalyzer,
config=CachedAnalysisAnalyzerConfig(
filename=os.path.join(ASSETS_DIR, "hello.x64.elf.json")
filename=os.path.join(LOCAL_ASSETS_DIR, "hello.x64.elf.json")
),
)

Expand Down
3 changes: 0 additions & 3 deletions disassemblers/ofrak_ghidra/tests/assets/fib

This file was deleted.

3 changes: 0 additions & 3 deletions disassemblers/ofrak_ghidra/tests/assets/fib_thumb

This file was deleted.

3 changes: 0 additions & 3 deletions disassemblers/ofrak_ghidra/tests/assets/hello.x64.elf

This file was deleted.

8 changes: 5 additions & 3 deletions disassemblers/ofrak_ghidra/tests/test_decompilation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""
Test the decompilation functionality of OFRAK with Ghidra.
"""
from typing import List
import os
from typing import List

from ofrak.core.complex_block import ComplexBlock
from ofrak.core.decompilation import DecompilationAnalysis, DecompilationAnalyzer
from ofrak.ofrak_context import OFRAKContext
from ofrak.core.complex_block import ComplexBlock
from ofrak.service.resource_service_i import ResourceFilter
from pytest_ofrak import ASSETS_DIR


async def test_ghidra_decompilation(ofrak_context: OFRAKContext):
Expand All @@ -19,7 +21,7 @@ async def test_ghidra_decompilation(ofrak_context: OFRAKContext):
- The decompilation results contain expected keywords like 'main' and 'print'
"""
root_resource = await ofrak_context.create_root_resource_from_file(
os.path.join(os.path.dirname(__file__), "assets/hello.x64.elf")
os.path.join(ASSETS_DIR, "hello.x64.elf")
)
await root_resource.unpack_recursively(
do_not_unpack=[
Expand Down
11 changes: 6 additions & 5 deletions disassemblers/ofrak_ghidra/tests/test_unpackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
- REQ2.3
"""
import os
from typing import Tuple, Dict
from typing import Dict, Tuple

import pytest

from ofrak import OFRAKContext
from ofrak_type.architecture import InstructionSetMode
from ofrak.core.code_region import CodeRegion
from ofrak.core.instruction import Instruction
from ofrak.resource import Resource
from ofrak.core.code_region import CodeRegion
from ofrak.service.resource_service_i import ResourceFilter, ResourceSort
from ofrak_type.architecture import InstructionSetMode
from pytest_ofrak import ASSETS_DIR
from pytest_ofrak.patterns.basic_block_unpacker import (
BasicBlockUnpackerUnpackAndVerifyPattern,
)
Expand All @@ -27,7 +28,7 @@
ComplexBlockUnpackerTestCase,
)

ASSETS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "assets"))
LOCAL_ASSETS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "assets"))


class TestGhidraCodeRegionUnpackAndVerify(CodeRegionUnpackAndVerifyPattern):
Expand Down Expand Up @@ -129,7 +130,7 @@ async def test_instruction_mode(test_case: Tuple[Resource, InstructionSetMode]):
async def program_resource(ofrak_context: OFRAKContext):
# program compiled from examples/src
return await ofrak_context.create_root_resource_from_file(
os.path.join(os.path.dirname(__file__), "assets/program")
os.path.join(LOCAL_ASSETS_DIR, "program")
)


Expand Down
13 changes: 2 additions & 11 deletions disassemblers/ofrak_pyghidra/tests/test_pyghidra_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
InstructionSet,
)
import pytest
from pytest_ofrak import ASSETS_DIR
from pytest_ofrak.patterns.code_region_unpacker import CodeRegionUnpackAndVerifyPattern
from pytest_ofrak.patterns.complex_block_unpacker import (
ComplexBlockUnpackerUnpackAndVerifyPattern,
Expand All @@ -44,13 +45,6 @@
from ofrak_pyghidra.standalone.pyghidra_analysis import unpack, decompile_all_functions
from ofrak import Resource, ResourceFilter, ResourceSort, ResourceAttributeValueFilter

ASSETS_DIR = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"../../ofrak_cached_disassembly/tests/assets",
)
)


@pytest.fixture(autouse=True)
def pyghidra_components(ofrak_injector):
Expand Down Expand Up @@ -349,10 +343,7 @@ async def test_strings_in_decomp(freertos_resource, ofrak_injector):
@pytest.fixture
async def ihex_resource(ofrak_context: OFRAKContext):
return await ofrak_context.create_root_resource_from_file(
os.path.join(
os.path.dirname(__file__),
"../../ofrak_core/tests/components/assets/hello_world.ihex",
)
os.path.join(ASSETS_DIR, "hello_world.ihex")
)


Expand Down
8 changes: 3 additions & 5 deletions ofrak_core/tests/components/test_ihex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ofrak import OFRAKContext, Resource, ResourceFilter, ResourceAttributeRangeFilter
from ofrak.core import MemoryRegion, Ihex
from ofrak_type import Range
from pytest_ofrak import ASSETS_DIR as PYTEST_OFRAK_ASSETS_DIR
from pytest_ofrak.patterns.unpack_modify_pack import UnpackModifyPackPattern
from pytest_ofrak.patterns.unpack_verify import UnpackAndVerifyTestCase
from . import ASSETS_DIR
Expand All @@ -25,11 +26,8 @@ class IhexTestCase(UnpackAndVerifyTestCase):


IHEX_TEST_FILES = [
os.path.join(ASSETS_DIR, fname)
for fname in [
"patch_demo.ihex",
"hello_world.ihex",
]
os.path.join(ASSETS_DIR, "patch_demo.ihex"),
os.path.join(PYTEST_OFRAK_ASSETS_DIR, "hello_world.ihex"),
]


Expand Down
Loading