feat: add ELF file parse for py version #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: LibSurgeon CI | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| # ============================================================ | |
| # Code Quality Checks | |
| # ============================================================ | |
| lint: | |
| name: Lint & Format Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install black flake8 | |
| - name: Check formatting with black | |
| run: | | |
| python -m black --check --diff libsurgeon.py evaluate_quality.py tests/*.py | |
| - name: Lint with flake8 | |
| run: | | |
| python -m flake8 libsurgeon.py evaluate_quality.py tests/*.py --max-line-length=88 --extend-ignore=E203,E501,W503 | |
| # ============================================================ | |
| # Unit Tests | |
| # ============================================================ | |
| test: | |
| name: Tests (Python ${{ matrix.python-version }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pytest pytest-cov | |
| pip install -r requirements.txt || true | |
| - name: Build test fixtures | |
| run: | | |
| cd tests | |
| bash build_fixtures.sh | |
| - name: Run tests | |
| run: | | |
| pytest tests/ -v --tb=short | |
| - name: Run tests with coverage | |
| if: matrix.python-version == '3.11' | |
| run: | | |
| pytest tests/ --cov=. --cov-report=xml --cov-report=term-missing | |
| - name: Upload coverage to Codecov | |
| if: matrix.python-version == '3.11' | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: ./coverage.xml | |
| fail_ci_if_error: false | |
| # ============================================================ | |
| # Integration Test (with Ghidra) | |
| # ============================================================ | |
| integration: | |
| name: Integration Test | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pytest | |
| - name: Set up Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Download Ghidra | |
| run: | | |
| wget -q https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.2.1_build/ghidra_11.2.1_PUBLIC_20241105.zip | |
| unzip -q ghidra_11.2.1_PUBLIC_20241105.zip | |
| mv ghidra_11.2.1_PUBLIC $HOME/ghidra | |
| - name: Build test fixtures | |
| run: | | |
| cd tests | |
| bash build_fixtures.sh | |
| - name: Test archive extraction | |
| run: | | |
| python -c "from libsurgeon import extract_archive; print('Import OK')" | |
| - name: Test ELF detection | |
| run: | | |
| python -c "from libsurgeon import is_elf_file, get_file_type, FileType; assert get_file_type('test.elf') == FileType.ELF; print('ELF detection OK')" | |
| - name: Test module strategies | |
| run: | | |
| python -c "from libsurgeon import MODULE_STRATEGIES; assert len(MODULE_STRATEGIES) == 4; print('Module strategies OK')" | |
| - name: Test progress bar | |
| run: | | |
| python -c "from libsurgeon import draw_progress_bar; bar = draw_progress_bar(50, 100); assert len(bar) == 40; print('Progress bar OK')" | |
| - name: Test quality evaluation | |
| run: | | |
| # Create a sample decompiled file | |
| mkdir -p test_output | |
| echo 'void test() { return; }' > test_output/sample.cpp | |
| python evaluate_quality.py test_output/ | |
| - name: Test libsurgeon help | |
| run: | | |
| python libsurgeon.py --help | |
| # Verify ELF module option exists | |
| python libsurgeon.py --help | grep -q "\-m.*prefix\|alpha\|camelcase\|single" | |
| # ============================================================ | |
| # Documentation | |
| # ============================================================ | |
| docs: | |
| name: Documentation Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check README exists | |
| run: | | |
| test -f README.md | |
| - name: Check LICENSE exists | |
| run: | | |
| test -f LICENSE |