dispoffset not set in AM_A operand handling?

16 views
Skip to first unread message

Catalin Patulea

unread,
Sep 2, 2011, 12:23:03 AM9/2/11
to libdasm
Hi,

I'm decoding a far jump and need the OPERAND.dispoffset field so I can
mangle the jump target. I don't think libdasm is setting dispoffset
correctly. Here's a sample program (in Python but the bug I think is
in libdasm itself).

#!/usr/bin/python
from pydasm import *

def print_opnd(o):
print "type:", o.type
print "dispbytes:", o.dispbytes
print "dispoffset:", o.dispoffset
print "displacement:", "%08x" % o.displacement
print "flags:", "%08x" % o.flags

bytes = "\xEA\x80\xB3\x40\x00\x1B\x00"
instr = get_instruction(bytes, MODE_32)
print "= Disassembly ="
print get_instruction_string(instr, FORMAT_INTEL, 0)
print "= Operand ="
print_opnd(instr.op1)

And this is the output:

= Disassembly =
jmpf 0x1b:0x40b380
= Operand =
type: 3
dispbytes: 6
dispoffset: 0
displacement: 0040b380
flags: 07011000

The displacement value is decoded properly, but dispoffset should be
1.

I think the issue is in libdasm.c line 534. dispoffset just isn't set.
Here is a patch against trunk (assuming this is the right fix, I'm not
100% familiar with IA-32 and libdasm code).


Index: libdasm.c
===================================================================
--- libdasm.c (revision 15)
+++ libdasm.c (working copy)
@@ -531,6 +531,7 @@
mode = MODE_CHECK_OPERAND(mode, iflags);

op->dispbytes = (mode == MODE_32) ? 6 : 4;
+ op->dispoffset = offset;
op->displacement = (mode == MODE_32) ?
FETCH32(addr) : FETCH16(addr);
op->section = FETCH16(addr + op->dispbytes -
2);

Catalin
Reply all
Reply to author
Forward
0 new messages