diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01449c6..91dd62a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,8 +24,12 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + apt update + apt install software-properties-common -y + add-apt-repository ppa:ubuntu-toolchain-r/test apt update apt install build-essential -y + apt install gcc-13 -y python -m pip install --upgrade pip pip install -r requirements.txt - name: Run tests diff --git a/README.md b/README.md index 464f6a3..d06cb84 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This script provides ability to postprocess code, which is decompiled via Ghidra, to make it closer to recompilable. # Technologies used * [Python 3.12](https://www.python.org/) -* [pyhidra](https://github.com/dod-cyber-crime-center/pyhidra) +* [pyhidra 1.3.0](https://github.com/dod-cyber-crime-center/pyhidra) * [Ghidra 11.1.0](https://github.com/NationalSecurityAgency/ghidra) Development: @@ -13,10 +13,10 @@ Development: * [Shellcheck](https://www.shellcheck.net/) Running tests: -* [GCC](https://gcc.gnu.org/) +* [GCC 13](https://gcc.gnu.org/) # Setup -Ensure that you do have Python with installed pip, Ghidra app and GCC compiler. If you want to run CI scripts, ensure you do have shellcheck installed. +Ensure that you do have Python with installed pip, Ghidra app and GCC-13 compiler. If you want to run CI scripts, ensure you do have shellcheck installed. Then just clone the repo using HTTPS: ```shell @@ -55,15 +55,11 @@ python3 run.py res/in/hello_world res/out/hello_world.c ``` After this, you can try to compile output code. Example with GCC: ```shell -gcc res/out/hello_world.c +gcc-13 res/out/hello_world.c ``` Enjoy! # Running tests -Ensure you do have res/out directory set. -```shell -mkdir -p res/out -``` -After that, you can run our tests using pytest. +You can run our tests using pytest. ```shell pytest src/tests/user_tests.py ``` diff --git a/ci/test.sh b/ci/test.sh index 384130a..a0ecebc 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -1,4 +1,3 @@ #!/bin/bash echo "Run tests" -mkdir -p res/out pytest src/tests/user_tests.py diff --git a/requirements.txt b/requirements.txt index 094f2a5..95f22cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -pyhidra==1.2.0 +pyhidra==1.3.0 pytest==8.3.2 pylint==3.2.6 diff --git a/src/scripts/dump.py b/src/scripts/dump.py index fd03bf5..8f6df9f 100644 --- a/src/scripts/dump.py +++ b/src/scripts/dump.py @@ -14,9 +14,6 @@ from ghidra.program.model.data import Structure from ghidra.program.model.data import Union -CONCAT_LEN = 6 # = len("CONCAT") -BYTE_SIZE = 8 - def put_program_data_types(program, file_writer, monitor, library_list): """Dumps program data types""" diff --git a/src/tests/user_tests.py b/src/tests/user_tests.py index 17c8499..1c4a473 100644 --- a/src/tests/user_tests.py +++ b/src/tests/user_tests.py @@ -6,12 +6,14 @@ INPUT_DIRECTORY = "res/in/" OUTPUT_PATH = "res/out/code.c" -COMPILER = "gcc" +COMPILER = "gcc-13" @pytest.fixture(scope='module') -def clean(): - """Deleting a.out and code.c files""" +def chores(): + """Create output directory before running tests + deleting a.out and code.c files after running tests""" + os.makedirs("res/out", exist_ok = True) yield os.remove("a.out") os.remove(OUTPUT_PATH) @@ -24,27 +26,27 @@ def compile_binary(binary): return os.system(f"{COMPILER} {OUTPUT_PATH}") -def test_hello_world(clean): +def test_hello_world(chores): """Recompiles hello world binary""" assert compile_binary("hello_world") == 0 -def test_bmp(clean): +def test_bmp(chores): """Recompiles BMP header reader binary""" assert compile_binary("bmp1") == 0 -def test_bst(clean): +def test_bst(chores): """Recompiles binary search tree binary""" assert compile_binary("bst") == 0 -def test_avl(clean): +def test_avl(chores): """Recompiles AVL tree binary""" assert compile_binary("avl") == 0 -def test_linpack(clean): - """Recompiles AVL tree binary""" +def test_linpack(chores): + """Recompiles linpack binary""" assert compile_binary("linpack") == 0 -def test_export_c_code(): +def test_export_c_code(chores): """Postprocessor test""" for binary in os.listdir(INPUT_DIRECTORY): export_c_code(f"{INPUT_DIRECTORY}{binary}", OUTPUT_PATH)