Commit f6ea905
committed
Binary Rewriting *WITH* Control-Flow Recovery
This change makes it possible to rewrite binaries
using Control-Flow Recovery (CFR).
To enable, simply pass "-X" to E9Tool:
$ ./e9tool -X ...
This will enable a heuristic-based CFR analysis
in E9Patch, and the binary will be rewritten
using this information. Without the "-X", the
binary will be rewritten without CFR, which is
the classic E9Patch mode.
PROS (with -X):
- The rewritten binary will be much faster
- The patching coverage will be much higher
- The rewriting speed will be improved
CONS (with -X):
- If the heuristic-based CFR is inaccurate, the
rewritten binary may be broken/buggy.
Thus, the -X mode provides much weaker
guarantees.
That said, the CFR analysis is designed to be
an overapproximation that should work for all
binaries compiled with standard compilers such
as gcc or clang. The CFR does *NOT* assume
disassembly/symbols and can handle classic
problems like data-in-code. It appears to work
for most binaries.
(The only incompatible binary found thus far is
E9Patch itself, which contains code that
delibrately attempts to confuse CFR analysis).
Whether the performance vs. accuracy trade-off
is acceptable depends on the application. The
-X mode is generally much faster, and closes the
performance gap with inline-based binary
rewriting tools like RetroWrite.
Internally, CFR enables a new rewriting tactic
"T0" that batches together instructions that
are not jump targets into a single trampoline.
This significantly improves locality and
reduces jumps, improving performance. This
also improves patching coverage, since
instruction batches are easier to patch, and
generally do not need to rely on instruction
punning.1 parent 35d1059 commit f6ea905
16 files changed
Lines changed: 1122 additions & 232 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| |||
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | | - | |
| 78 | + | |
75 | 79 | | |
76 | 80 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
208 | 213 | | |
209 | 214 | | |
210 | 215 | | |
| |||
0 commit comments