Skip to content

Commit

Permalink
Implement SIB addressing in JIT
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed May 13, 2018
1 parent 7a3a99a commit fb27d93
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
23 changes: 22 additions & 1 deletion emu/gadgets-x86/memory.S
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@
.endm
.reg_gadgets addr

.irp reg, REG_LIST
.irp times, 1,2,4
.gadget si_\reg\()_\times
.ifnc \reg,esp
leal (%_addr,%\reg,\times), %_addr
.else
leal (%_addr,%_esp,\times), %_addr
.endif
gret
.endr
.endr
.section .rodata
.global si_gadgets
si_gadgets:
.irp reg, REG_LIST
.irp times, 1,2,4
.quad gadget_si_\reg\()_\times
.endr
.endr
.previous

# memory stuff that can't go in a header file
.irp type, read,write
.global handle_\type\()_miss
Expand All @@ -47,5 +68,5 @@ segfault:
movl $INT_GPF, %_tmp
jmp jit_exit

.rodata
.section .rodata
.gadget_array_list addr, REG_LIST
3 changes: 3 additions & 0 deletions emu/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern gadget_t sub_gadgets[arg_cnt];
extern gadget_t xor_gadgets[arg_cnt];

extern gadget_t addr_gadgets[reg_cnt];
extern gadget_t si_gadgets[reg_cnt * 3];

#define GEN(thing) gen(state, (unsigned long) (thing))
#define g(g) GEN(gadget_##g)
Expand Down Expand Up @@ -66,6 +67,8 @@ static inline void gen_op(struct gen_state *state, gadget_t *gadgets, enum arg a
if (arg == arg_mem32 || arg == arg_addr) {
GEN(addr_gadgets[modrm->base]);
GEN(modrm->offset);
if (modrm->type == modrm_mem_si)
GEN(si_gadgets[modrm->index * 3 + modrm->shift]);
}
GEN(gadgets[arg]);
if (arg == arg_imm)
Expand Down
3 changes: 2 additions & 1 deletion ish-gdb.gdb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ end

define hook-stop
python
if gdb.selected_frame().find_sal().symtab.filename.endswith('.S'):
symtab = gdb.selected_frame().find_sal().symtab
if symtab is not None and symtab.filename.endswith('.S'):
gdb.execute('set disassemble-next-line on')
else:
gdb.execute('set disassemble-next-line auto')
Expand Down

0 comments on commit fb27d93

Please sign in to comment.