File tree 14 files changed +450
-59
lines changed
14 files changed +450
-59
lines changed Original file line number Diff line number Diff line change 8
8
"name" : " Run without proxy (Eigen)" ,
9
9
"presentation" : {
10
10
"group" : " Eigen" ,
11
- "order" : 2
11
+ "order" : 1
12
12
},
13
- "preLaunchTask" : " Build (Eigen)" ,
13
+ "preLaunchTask" : " Build program (Eigen)" ,
14
14
"type" : " cppdbg" ,
15
15
"request" : " launch" ,
16
16
"program" : " ${workspaceFolder}/prototypes/eigen/bin/main" ,
17
17
"args" : [],
18
18
"stopAtEntry" : false ,
19
- "cwd" : " ${fileDirname} " ,
19
+ "cwd" : " ${workspaceFolder}/prototypes/eigen " ,
20
20
"environment" : [],
21
21
"externalConsole" : false ,
22
22
"MIMode" : " gdb" ,
Original file line number Diff line number Diff line change 2
2
"version" : " 2.0.0" ,
3
3
"tasks" : [
4
4
{
5
- "label" : " Build (Eigen)" ,
5
+ "label" : " Build program (Eigen)" ,
6
6
"type" : " shell" ,
7
- "command" : " task build:program && task build:proxy " ,
7
+ "command" : " task build:program" ,
8
8
"options" : {
9
9
"cwd" : " ${workspaceFolder}/prototypes/eigen" ,
10
10
"env" : {
11
- "VERBOSE " : " true"
11
+ "DEBUG " : " true"
12
12
}
13
13
},
14
14
"problemMatcher" : []
Original file line number Diff line number Diff line change @@ -10,9 +10,10 @@ tasks:
10
10
# Make the destination directory
11
11
- mkdir -p bin
12
12
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
15
15
desc : Build the program
16
+ label : ' build:program (Debug: {{eq .DEBUG "true"}})'
16
17
silent : true
17
18
sources :
18
19
- src/main.cpp
@@ -23,15 +24,13 @@ tasks:
23
24
24
25
build:proxy :
25
26
cmds :
26
- # Make the destination directory
27
- - mkdir -p lib
28
-
29
27
# Generate Makefiles
30
28
- cmake -D DynamoRIO_DIR={{.DYNAMORIO}}/cmake -B lib .
31
29
32
30
# Build
33
31
- cmake --build lib
34
32
desc : Build the proxy
33
+ label : ' build:proxy (DynamoRIO: {{.DYNAMORIO}})'
35
34
silent : true
36
35
sources :
37
36
- CMakeLists.txt
78
77
- build:program
79
78
- build:proxy
80
79
desc : Run the program with the proxy
80
+ label : ' run:proxy (DynamoRIO: {{.DYNAMORIO}})'
81
81
silent : true
Original file line number Diff line number Diff line change
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)
Original file line number Diff line number Diff line change 1
1
# Eigen
2
2
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)
4
4
5
5
## Documentation
6
6
@@ -12,14 +12,4 @@ task run:no-proxy
12
12
2 . Run with the proxy:
13
13
``` bash
14
14
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
+ ```
Original file line number Diff line number Diff line change 8
8
- mkdir -p bin
9
9
10
10
# 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
12
12
vars :
13
13
# Headers
14
14
INCLUDE : /usr/include/eigen3
15
15
desc : Build the program
16
+ label : ' build:program (Debug: {{eq .DEBUG "true"}}, include: {{.INCLUDE}})'
16
17
silent : true
17
18
sources :
18
19
- src/main.cpp
@@ -21,38 +22,40 @@ tasks:
21
22
22
23
build:proxy :
23
24
cmds :
24
- # Make the destination directory
25
- - mkdir -p bin
25
+ # Generate Makefiles
26
+ - cmake -B lib {{if eq .DEBUG "true"}} -DDEBUG=ON{{end}} .
26
27
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
29
30
desc : Build the proxy
31
+ label : ' build:proxy (Debug: {{eq .DEBUG "true"}})'
30
32
silent : true
31
33
sources :
34
+ - CMakeLists.txt
32
35
- src/proxy.cpp
33
36
generates :
34
- - bin/proxy
37
+ - lib/*
35
38
36
39
symbols:program :
37
40
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\(.*\)$"
39
42
deps :
40
43
- build:program
41
44
desc : Lists the relevant (filtered) symbols from the program
42
45
silent : true
43
46
44
47
symbols:proxy :
45
48
cmds :
46
- - nm -C bin/proxy | grep run
49
+ - nm -C lib/libproxy.so | grep qbdipreload_on_run
47
50
deps :
48
51
- build:proxy
49
52
desc : Lists the relevant (filtered) symbols from the proxy
50
53
silent : true
51
54
52
55
clean :
53
56
cmds :
54
- # Delete the directory
55
- - cmd : rm bin -r
57
+ # Delete the directories
58
+ - cmd : rm bin lib -r
56
59
ignore_error : true
57
60
desc : Clean everything
58
61
silent : true
@@ -67,9 +70,12 @@ tasks:
67
70
68
71
run:proxy :
69
72
cmds :
70
- - bin/proxy bin/ main
73
+ - bin/main
71
74
deps :
72
75
- build:program
73
76
- build:proxy
74
77
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
You can’t perform that action at this time.
0 commit comments