Skip to content

Commit 5dbab19

Browse files
committed
CIL: Copy the CIL extractor and tools into the binary directory.
1 parent 2676719 commit 5dbab19

10 files changed

Lines changed: 91 additions & 1 deletion

File tree

cil/extractor/Semmle.Extraction.CSharp.IL/ILExtractor.cs renamed to binary/extractor/cil/Semmle.Extraction.CSharp.IL/ILExtractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private void ExtractMethodBody(MethodDefinition method, int methodId) {
102102
trap.WriteTuple("il_instruction_method", instrId,
103103
methodId);
104104

105-
trap.WriteTuple("il_instruction_string", instrId,
105+
trap.WriteTuple("instruction_string", instrId,
106106
instruction.OpCode.Name);
107107

108108
// Parent relationship

cil/extractor/Semmle.Extraction.CSharp.IL/Program.cs renamed to binary/extractor/cil/Semmle.Extraction.CSharp.IL/Program.cs

File renamed without changes.

cil/extractor/Semmle.Extraction.CSharp.IL/Semmle.Extraction.CSharp.IL.csproj renamed to binary/extractor/cil/Semmle.Extraction.CSharp.IL/Semmle.Extraction.CSharp.IL.csproj

File renamed without changes.

cil/extractor/Semmle.Extraction.CSharp.IL/Trap/TrapWriter.cs renamed to binary/extractor/cil/Semmle.Extraction.CSharp.IL/Trap/TrapWriter.cs

File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "cil"
2+
aliases:
3+
- "cil"
4+
- "csharp-il"
5+
display_name: "C# IL"
6+
version: 0.0.1
7+
column_kind: "utf16"
8+
build_modes:
9+
- none
10+
file_types:
11+
- name: cil
12+
display_name: C# IL
13+
extensions:
14+
- .exe
15+
- .dll

binary/tools/cil/autobuild.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
3+
"%CODEQL_DIST%\codeql.exe" database index-files --working-dir=. --language=cil "%CODEQL_EXTRACTOR_CIL_WIP_DATABASE%"
4+
exit /b %ERRORLEVEL%

binary/tools/cil/autobuild.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
if [[ -z "${CODEQL_EXTRACTOR_CSHARPIL_ROOT}" ]]; then
6+
export CODEQL_EXTRACTOR_CSHARPIL_ROOT="$(dirname "$(dirname "${BASH_SOURCE[0]}")")"
7+
fi
8+
9+
# For C# IL, autobuild and buildless extraction are the same - just extract the DLLs
10+
exec "${CODEQL_EXTRACTOR_CSHARPIL_ROOT}/tools/index.sh"

binary/tools/cil/index-files.cmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@echo off
2+
3+
if not defined CODEQL_CIL_EXTRACTOR (
4+
set CODEQL_CIL_EXTRACTOR=Semmle.Extraction.CSharp.IL.exe
5+
)
6+
7+
type NUL && "%CODEQL_EXTRACTOR_CIL_ROOT%/tools/%CODEQL_PLATFORM%/%CODEQL_CIL_EXTRACTOR%" "%1"
8+
exit /b %ERRORLEVEL%

binary/tools/cil/index-files.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)