Skip to content

Project support #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
```
Expand Down
1 change: 0 additions & 1 deletion ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash
echo "Run tests"
mkdir -p res/out
pytest src/tests/user_tests.py
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyhidra==1.2.0
pyhidra==1.3.0
pytest==8.3.2
pylint==3.2.6
3 changes: 0 additions & 3 deletions src/scripts/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
22 changes: 12 additions & 10 deletions src/tests/user_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading