B.R.
unread,Aug 20, 2012, 11:20:09 AM8/20/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DynamoRIO Users
Hello,
I am now using drutil_insert_get_mem_addr to compute memory addresses used at analysis time.
However I have strange readings and I believe I made mistakes instrumenting the memory context.
He is my code sample:
reg_id_t reg1 = DR_REG_XBX; /* We can optimize it by picking dead reg */
reg_id_t reg2 = DR_REG_XCX; /* reg2 must be ECX or RCX for jecxz */
dr_save_reg(drcontext, bb, instr, reg1, SPILL_SLOT_2);
dr_save_reg(drcontext, bb, instr, reg2, SPILL_SLOT_3);
drutil_insert_get_mem_addr(drcontext, bb, instr, operand, reg1, reg2);
/* memory operand address shall be computed with registers context before the instruction has been executed */
dr_insert_clean_call(drcontext, bb, instr, (void *)processMemOperand, false, 4, OPND_CREATE_INTPTR(1), OPND_CREATE_INTPTR(tIns), OPND_CREATE_INTPTR(operandSize), OPND_CREATE_INTPTR(reg_get_value(reg1, &mcontext)));
/* Supplementary call for (re)filling values *after* the instruction has been executed */
dr_insert_clean_call(drcontext, bb, next_instr, (void *)fillMemValues, false, 1, OPND_CREATE_INTPTR(tIns));
dr_restore_reg(drcontext, bb, instr, reg1, SPILL_SLOT_2);
dr_restore_reg(drcontext, bb, instr, reg2, SPILL_SLOT_3);
Things you'll need to understand that piece of code:
processMemOperand takes:
- int 1 -> I/O mode (W)
- tIns -> pointer on structure storing instruction data
- size of operand -> needed for safe_read
- computed address to read from
The second clean call calls a procedure reading the memory address stored in the tIns structure after the instruction has been executed. This is done for written memory operands only.
Sample (XP's hostname.exe):
(6A 28) PUSH 28
(68 B0100001) PUSH hostname.010010B0
Output:
6a28
Written register: esp = 7ffc4
Written memory: 7ffd4000 (4) = 0 --> should be 7ffc0 (4) = 28 (new ESP value + value stored on stack)
Written register: esp = 7ffc0
68b0100001
Read register: esp = 7ffc0
Written memory: 7ffd4000 (4) = 0 --> should be 7ffbc (4) = 10010B0 (new ESP value + value stored on stack)
Written register: esp = 7ffbc
Am I doing it right? I guess not... but where/why?
---
B.