|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +if [[ -z "${CODEQL_EXTRACTOR_CSHARPIL_ROOT:-}" ]]; then |
| 6 | + export CODEQL_EXTRACTOR_CSHARPIL_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 7 | +fi |
| 8 | + |
| 9 | +# Get the trap directory from CodeQL environment |
| 10 | +TRAP_DIR="${CODEQL_EXTRACTOR_CSHARPIL_TRAP_DIR}" |
| 11 | +SRC_ARCHIVE="${CODEQL_EXTRACTOR_CSHARPIL_SOURCE_ARCHIVE_DIR}" |
| 12 | + |
| 13 | +echo "C# IL Extractor: Starting extraction" |
| 14 | +echo "Source root: $(pwd)" |
| 15 | +echo "TRAP directory: ${TRAP_DIR}" |
| 16 | + |
| 17 | +# Ensure TRAP directory exists |
| 18 | +mkdir -p "${TRAP_DIR}" |
| 19 | + |
| 20 | +# Find all DLL and EXE files in the source root |
| 21 | +EXTRACTOR_PATH="${CODEQL_EXTRACTOR_CSHARPIL_ROOT}/extractor/Semmle.Extraction.CSharp.IL/bin/Debug/net8.0/Semmle.Extraction.CSharp.IL" |
| 22 | + |
| 23 | +if [[ ! -f "${EXTRACTOR_PATH}" ]]; then |
| 24 | + echo "ERROR: Extractor not found at ${EXTRACTOR_PATH}" |
| 25 | + echo "Please build the extractor first with: dotnet build extractor/Semmle.Extraction.CSharp.IL" |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +# Extract all DLL and EXE files |
| 30 | +FILE_COUNT=0 |
| 31 | +find . -type f \( -name "*.dll" -o -name "*.exe" \) | while read -r assembly; do |
| 32 | + echo "Extracting: ${assembly}" |
| 33 | + |
| 34 | + # Normalize the assembly path (remove leading ./) |
| 35 | + normalized_path="${assembly#./}" |
| 36 | + |
| 37 | + # Create a unique trap file name based on the assembly path |
| 38 | + TRAP_FILE="${TRAP_DIR}/$(echo "${assembly}" | sed 's/[^a-zA-Z0-9]/_/g').trap" |
| 39 | + |
| 40 | + # Run the extractor |
| 41 | + "${EXTRACTOR_PATH}" "${assembly}" "${TRAP_FILE}" || echo "Warning: Failed to extract ${assembly}" |
| 42 | + |
| 43 | + # Copy the assembly to the source archive |
| 44 | + ARCHIVE_PATH="${SRC_ARCHIVE}/${normalized_path}" |
| 45 | + ARCHIVE_DIR="$(dirname "${ARCHIVE_PATH}")" |
| 46 | + mkdir -p "${ARCHIVE_DIR}" |
| 47 | + cp "${assembly}" "${ARCHIVE_PATH}" |
| 48 | + echo "Archived: ${assembly} -> ${ARCHIVE_PATH}" |
| 49 | + |
| 50 | + FILE_COUNT=$((FILE_COUNT + 1)) |
| 51 | +done |
| 52 | + |
| 53 | +echo "C# IL Extractor: Completed extraction of ${FILE_COUNT} assemblies" |
0 commit comments