Skip to content

Commit effd0ad

Browse files
committed
Added Eigen proxy + Taskfile variable tracking 🎉
1 parent 6d9d02a commit effd0ad

File tree

14 files changed

+450
-59
lines changed

14 files changed

+450
-59
lines changed

.vscode/launch.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"name": "Run without proxy (Eigen)",
99
"presentation": {
1010
"group": "Eigen",
11-
"order": 2
11+
"order": 1
1212
},
13-
"preLaunchTask": "Build (Eigen)",
13+
"preLaunchTask": "Build program (Eigen)",
1414
"type": "cppdbg",
1515
"request": "launch",
1616
"program": "${workspaceFolder}/prototypes/eigen/bin/main",
1717
"args": [],
1818
"stopAtEntry": false,
19-
"cwd": "${fileDirname}",
19+
"cwd": "${workspaceFolder}/prototypes/eigen",
2020
"environment": [],
2121
"externalConsole": false,
2222
"MIMode": "gdb",

.vscode/tasks.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"label": "Build (Eigen)",
5+
"label": "Build program (Eigen)",
66
"type": "shell",
7-
"command": "task build:program && task build:proxy",
7+
"command": "task build:program",
88
"options": {
99
"cwd": "${workspaceFolder}/prototypes/eigen",
1010
"env": {
11-
"VERBOSE": "true"
11+
"DEBUG": "true"
1212
}
1313
},
1414
"problemMatcher": []

prototypes/dynamorio/Taskfile.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ tasks:
1010
# Make the destination directory
1111
- mkdir -p bin
1212

13-
# Compile the program ("-O1 -mpush-args" ensure the arguments are passed via the stack instead of registers)
14-
- g++ {{if eq .VERBOSE "true"}} -g{{end}} -O1 -mpush-args src/main.cpp src/simple_math.cpp src/simple_math.hpp -o bin/main
13+
# Compile the program
14+
- g++ {{if eq .DEBUG "true"}} -g{{end}} src/main.cpp src/simple_math.cpp src/simple_math.hpp -o bin/main
1515
desc: Build the program
16+
label: 'build:program (Debug: {{eq .DEBUG "true"}})'
1617
silent: true
1718
sources:
1819
- src/main.cpp
@@ -23,15 +24,13 @@ tasks:
2324

2425
build:proxy:
2526
cmds:
26-
# Make the destination directory
27-
- mkdir -p lib
28-
2927
# Generate Makefiles
3028
- cmake -D DynamoRIO_DIR={{.DYNAMORIO}}/cmake -B lib .
3129

3230
# Build
3331
- cmake --build lib
3432
desc: Build the proxy
33+
label: 'build:proxy (DynamoRIO: {{.DYNAMORIO}})'
3534
silent: true
3635
sources:
3736
- CMakeLists.txt
@@ -78,4 +77,5 @@ tasks:
7877
- build:program
7978
- build:proxy
8079
desc: Run the program with the proxy
80+
label: 'run:proxy (DynamoRIO: {{.DYNAMORIO}})'
8181
silent: true

prototypes/eigen/CMakeLists.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Configure CMake
2+
cmake_minimum_required(VERSION 3.10)
3+
4+
# Project name
5+
project(proxy)
6+
7+
# Options
8+
option(VERBOSE "Whether or not verbose logging is enabled" OFF)
9+
10+
# Find QBDI (See https://qbdi.readthedocs.io/en/stable/installation_and_integration.html?highlight=cmake#single-architecture)
11+
find_package(QBDI REQUIRED)
12+
find_package(QBDIPreload REQUIRED)
13+
14+
# Find Eigen (See https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html)
15+
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
16+
17+
# Add the library
18+
include_directories(../../src)
19+
file(GLOB LIB "../../src/*")
20+
21+
if(DEBUG)
22+
add_definitions(-D VERBOSE)
23+
endif(DEBUG)
24+
25+
# Add the executable
26+
add_library(proxy SHARED src/proxy.cpp ${LIB})
27+
28+
# Add elfutils
29+
target_link_libraries(proxy elf)
30+
31+
# Add QBDI
32+
target_link_libraries(proxy QBDIPreload::QBDIPreload QBDI::QBDI_static)
33+
34+
# Add Eigen
35+
target_link_libraries (proxy Eigen3::Eigen)

prototypes/eigen/README.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Eigen
22
A proxy for intercepting [Eigen](https://eigen.tuxfamily.org/) static library calls based on
3-
`ptrace`
3+
[QuarkslaB Dynamic binary Instrumentation (QBDI)](https://qbdi.quarkslab.com/) (X86-only)
44

55
## Documentation
66

@@ -12,14 +12,4 @@ task run:no-proxy
1212
2. Run with the proxy:
1313
```bash
1414
task run:proxy
15-
```
16-
17-
### Static Library Interception
18-
Using [`/proc/[PID]/maps`](https://man7.org/linux/man-pages/man5/proc.5.html) and
19-
[`libelf`](https://sourceware.org/elfutils/), it's possible to calculate a symbol's address in
20-
memory (Note: this should even work with ASLR). Once a symbol's address is known,
21-
[`ptrace`](https://man7.org/linux/man-pages/man2/ptrace.2.html) can be used to insert debugging
22-
trap/breakpoint instruction inside of the target function. Then, whenever the target function is
23-
called, the process emits a `SIGTRAP` which is easily detected by the parent. See
24-
[Eli Bendersky's website](https://eli.thegreenplace.net/2011/01/27/how-debuggers-work-part-2-breakpoints)
25-
for more information.
15+
```

prototypes/eigen/Taskfile.yml

+18-12
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ tasks:
88
- mkdir -p bin
99

1010
# Compile the program
11-
- g++ {{if eq .VERBOSE "true"}} -g{{end}} -I {{.INCLUDE}} src/main.cpp -o bin/main
11+
- g++ {{if eq .DEBUG "true"}} -g{{end}} -I {{.INCLUDE}} src/main.cpp -o bin/main
1212
vars:
1313
# Headers
1414
INCLUDE: /usr/include/eigen3
1515
desc: Build the program
16+
label: 'build:program (Debug: {{eq .DEBUG "true"}}, include: {{.INCLUDE}})'
1617
silent: true
1718
sources:
1819
- src/main.cpp
@@ -21,38 +22,40 @@ tasks:
2122

2223
build:proxy:
2324
cmds:
24-
# Make the destination directory
25-
- mkdir -p bin
25+
# Generate Makefiles
26+
- cmake -B lib {{if eq .DEBUG "true"}} -DDEBUG=ON{{end}} .
2627

27-
# Compile the proxy
28-
- g++ {{if eq .VERBOSE "true"}}-D VERBOSE -g{{end}} src/proxy.cpp -o bin/proxy
28+
# Build
29+
- cmake --build lib
2930
desc: Build the proxy
31+
label: 'build:proxy (Debug: {{eq .DEBUG "true"}})'
3032
silent: true
3133
sources:
34+
- CMakeLists.txt
3235
- src/proxy.cpp
3336
generates:
34-
- bin/proxy
37+
- lib/*
3538

3639
symbols:program:
3740
cmds:
38-
- nm -C bin/main | grep Eigen::internal::general_matrix_matrix_product
41+
- nm -C bin/main | grep "Eigen::internal::general_matrix_matrix_product<.*>::run\(.*\)$"
3942
deps:
4043
- build:program
4144
desc: Lists the relevant (filtered) symbols from the program
4245
silent: true
4346

4447
symbols:proxy:
4548
cmds:
46-
- nm -C bin/proxy | grep run
49+
- nm -C lib/libproxy.so | grep qbdipreload_on_run
4750
deps:
4851
- build:proxy
4952
desc: Lists the relevant (filtered) symbols from the proxy
5053
silent: true
5154

5255
clean:
5356
cmds:
54-
# Delete the directory
55-
- cmd: rm bin -r
57+
# Delete the directories
58+
- cmd: rm bin lib -r
5659
ignore_error: true
5760
desc: Clean everything
5861
silent: true
@@ -67,9 +70,12 @@ tasks:
6770

6871
run:proxy:
6972
cmds:
70-
- bin/proxy bin/main
73+
- bin/main
7174
deps:
7275
- build:program
7376
- build:proxy
7477
desc: Run the program with the proxy
75-
silent: true
78+
env:
79+
LD_BIND_NOW: 1
80+
LD_PRELOAD: ./lib/libproxy.so
81+
silent: true

0 commit comments

Comments
 (0)