From 1ca4e89851e2d448daedf9c95921f355dd59dc17 Mon Sep 17 00:00:00 2001 From: VyacheslavIurevich Date: Wed, 12 Mar 2025 13:13:18 +0300 Subject: [PATCH 1/4] chore: change pyhidra version in requirements.txt Signed-off-by: VyacheslavIurevich --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From aa05a2a3aab26c5cbb08a26bff7c8d4de8cc657b Mon Sep 17 00:00:00 2001 From: VyacheslavIurevich Date: Wed, 12 Mar 2025 13:13:45 +0300 Subject: [PATCH 2/4] refactor: remove unused variables from dump.py Signed-off-by: VyacheslavIurevich --- src/scripts/dump.py | 3 --- 1 file changed, 3 deletions(-) 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""" From 2a6e1b65db59018baa17e8997766580967dc23a2 Mon Sep 17 00:00:00 2001 From: VyacheslavIurevich Date: Wed, 12 Mar 2025 13:14:21 +0300 Subject: [PATCH 3/4] chores: automatize mkdir in tests, change gcc to gcc-13 Signed-off-by: VyacheslavIurevich --- .github/workflows/test.yml | 1 + README.md | 14 +++++--------- ci/test.sh | 1 - src/tests/user_tests.py | 22 ++++++++++++---------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01449c6..376f653 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,7 @@ jobs: run: | 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/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) From 5b4020ea9f7ffd638980c9dd368dd8c1c5f8e125 Mon Sep 17 00:00:00 2001 From: VyacheslavIurevich Date: Wed, 12 Mar 2025 13:30:56 +0300 Subject: [PATCH 4/4] fix: installation of gcc-13 in ci Signed-off-by: VyacheslavIurevich --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 376f653..91dd62a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,9 @@ 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