Skip to content

Commit 418d819

Browse files
committed
Add "static" arguments (replaces staticAddr)
The "static" keyword translates the address into the (static) ELF version. Also replaces: staticAddr ---> static addr The "static" keyword can also be applied to: static next static target static &symbol Also fixed a naked+state SEGV bug & added new tests.
1 parent e6ff65b commit 418d819

95 files changed

Lines changed: 820 additions & 127 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/e9tool-user-guide.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ The following arguments are supported:
492492
<tr><td><i>Integer</i></td><td><tt>intptr_t</tt></td>
493493
<td>An integer constant</td></tr>
494494
<tr><td><tt>&amp;</tt><i>Name</i></td><td><tt>const void &#42;</tt></td>
495-
<td>A section/symbol/PLT/GOT name from the input ELF binary (passed-by-pointer)</td></tr>
495+
<td>The runtime address of the named section/symbol/PLT/GOT entry</td></tr>
496+
<tr><td><tt>static &amp;</tt><i>Name</i></td><td><tt>const void &#42;</tt></td>
497+
<td>The ELF address of the named section/symbol/PLT/GOT entry</td></tr>
496498
<tr><td><b><tt>asm</tt></b></td><td><tt>const char &#42;</tt></td>
497499
<td>Assembly representation of the matching instruction</td></tr>
498500
<tr><td><b><tt>asm.size</tt></b></td><td><tt>size_t</tt></td>
@@ -503,16 +505,22 @@ The following arguments are supported:
503505
<td>The runtime base address of the binary</td></tr>
504506
<tr><td><b><tt>addr</tt></b></td><td><tt>const void &#42;</tt></td>
505507
<td>The runtime address of the matching instruction</td></tr>
508+
<tr><td><b><tt>static addr</tt></b></td><td><tt>size_t</tt></td>
509+
<td>The ELF address of the matching instruction</td></tr>
506510
<tr><td><b><tt>id</tt></b></td><td><tt>intptr_t</tt></td>
507511
<td>A unique identifier (one per patch)</td></tr>
508512
<tr><td><b><tt>instr</tt></b></td><td><tt>const uint8_t &#42;</tt></td>
509513
<td>The machine-code bytes of the matching instruction</td></tr>
510514
<tr><td><b><tt>next</tt></b></td><td><tt>const void &#42;</tt></td>
511515
<td>The runtime address of the next executed instruction</td></tr>
516+
<tr><td><b><tt>static next</tt></b></td><td><tt>const void &#42;</tt></td>
517+
<td>The ELF address of the next executed instruction</td></tr>
512518
<tr><td><b><tt>offset</tt></b></td><td><tt>off_t</tt></td>
513519
<td>The ELF file offset of the matching instruction</td></tr>
514520
<tr><td><b><tt>target</tt></b></td><td><tt>const void &#42;</tt></td>
515521
<td>The runtime address of the jump/call/return target, else <tt>NULL</tt></td></tr>
522+
<tr><td><b><tt>static target</tt></b></td><td><tt>const void &#42;</tt></td>
523+
<td>The ELF address of the jump/call/return target, else <tt>NULL</tt></td></tr>
516524
<tr><td><b><tt>trampoline</tt></b></td><td><tt>const void &#42;</tt></td>
517525
<td>The runtime address of the trampoline</td></tr>
518526
<tr><td><b><tt>random</tt></b></td><td><tt>intptr_t</tt></td>
@@ -521,8 +529,6 @@ The following arguments are supported:
521529
<td>The size of <tt>instr</tt> in bytes</td></tr>
522530
<tr><td><b><tt>state</tt></b></td><td><tt>void &#42;</tt></td>
523531
<td>A pointer to a structure containing all general purpose registers</td></tr>
524-
<tr><td><b><tt>staticAddr</tt></b></td><td><tt>size_t</tt></td>
525-
<td>The ELF virtual address of the matching instruction</td></tr>
526532
<tr><td><b><tt>ah</tt></b>,...,<b><tt>dh</tt></b>, <b><tt>al</tt></b>,...,<b><tt>r15b</tt></b></td><td><tt>int8_t</tt></td>
527533
<td>The corresponding 8bit register</td></tr>
528534
<tr><td><b><tt>ax</tt></b>,...,<b><tt>r15w</tt></b></td><td><tt>int16_t</tt></td>
@@ -728,6 +734,9 @@ Notes:
728734
register will be updated accordingly.
729735
The structure does not include the stack register (`%rsp`) which must be
730736
passed separately.
737+
* The `static` version of some arguments gives the address relative to the ELF
738+
base, given by the formula: *runtime address = ELF address + ELF base*.
739+
This corresponds to the value used by the matching.
731740

732741
---
733742
##### <a id="s2211">2.2.1.1 Pass-by-pointer</a>

e9test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ for ACTION in \
2828
'passthru' \
2929
'call[naked,after] entry@nop' \
3030
'call entry(asm,instr,rflags,rdi,rip,addr,target,next)@nop' \
31-
'call entry(&rsp,&rax,&rsi,&rdi,&r8,&r15,staticAddr,0x1234)@nop' \
31+
'call entry(&rsp,&rax,&rsi,&rdi,&r8,&r15,static addr,0x1234)@nop' \
3232
'call entry(&op[0],&src[0],&dst[0],&op[1],&src[1],&dst[1],&dst[7],&src[7])@nop' \
3333
'call entry(reg[0],&reg[0],imm[0],&imm[0],&mem[0],reg[1],&reg[1],imm[1])@nop' \
3434
'plugin(example).patch()' \

src/e9tool/e9frontend.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ struct CallInfo
873873

874874
const int * const rsave; // Caller save regsters.
875875
const bool before; // Before or after inst.
876+
const bool pic; // PIC?
876877
int32_t rsp_offset = 0x4000; // Stack offset
877878
std::map<Register, RegInfo> info; // Register info
878879
std::vector<Register> pushed; // Pushed registers
@@ -1147,15 +1148,16 @@ struct CallInfo
11471148
* Constructor.
11481149
*/
11491150
CallInfo(bool clean, bool state, bool conditional, size_t num_args,
1150-
bool before) :
1151+
bool before, bool pic) :
11511152
rsave(getCallerSaveRegs(clean, state, conditional, num_args)),
1152-
before(before)
1153+
before(before), pic(pic)
11531154
{
11541155
for (unsigned i = 0; rsave[i] >= 0; i++)
11551156
push(getReg(rsave[i]), /*caller_save=*/true);
1156-
if (clean)
1157+
if (clean || state)
11571158
{
1158-
// For clean calls, %rax will be clobbered when %rflags in pushed.
1159+
// For clean/state calls, %rax will be clobbered when %rflags
1160+
// is pushed.
11591161
clobber(REGISTER_RAX);
11601162
}
11611163
}

src/e9tool/e9frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,6 @@ enum ArgumentKind
22182218
ARGUMENT_ADDR, // Instruction address
22192219
ARGUMENT_NEXT, // Next instruction address
22202220
ARGUMENT_BASE, // Base address of ELF binary in memory
2221-
ARGUMENT_STATIC_ADDR, // (Static) instruction address
22222221
ARGUMENT_ASM, // Assembly string
22232222
ARGUMENT_ASM_SIZE, // Assembly string size
22242223
ARGUMENT_ASM_LEN, // Assembly string length
@@ -2250,6 +2249,7 @@ struct Argument
22502249
ArgumentKind kind; // Argument kind.
22512250
FieldKind field; // Argument field.
22522251
bool ptr; // Argument is passed by pointer?
2252+
bool _static; // Argument is static?
22532253
bool duplicate; // Argument is a duplicate?
22542254
intptr_t value; // Argument value.
22552255
MemOp memop; // Argument memop value.

0 commit comments

Comments
 (0)