howardjack / distorm

Automatically exported from code.google.com/p/distorm
GNU General Public License v3.0
0 stars 0 forks source link

Unable to disassemble valid CMPSS instruction #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Using distorm3 python library:

>>> import distorm3
>>> i = distorm3.Decompose(0x0000000001647a58, "f3410fc2c105".decode('hex'), 
distorm3.Decode64Bits)[0]
>>> print i
SS XMM0, XMM9
>>> i.instructionClass
0: 'ISC_SSE'
>>> i.mnemonic
1: 'UNDEFINED'
>>> i.valid
2: True

What is the expected output? What do you see instead?
CMPSS
An undefined instruction

What version of the product are you using? On what operating system?
distorm3.1.0, distorm-package 3.1

Please provide any additional information below.

Original issue reported on code.google.com by cesare.d...@gmail.com on 24 Jan 2012 at 8:34

GoogleCodeExporter commented 9 years ago
0x1179: "CMPSS",
is also missing in distorm3.Mnemonics

Original comment by cesare.d...@gmail.com on 24 Jan 2012 at 8:43

GoogleCodeExporter commented 9 years ago
The same happens for normal (without REX prefix) version:

>>> i = distorm3.Decompose(0x0000000001646b2e, "f30fc2ce06".decode('hex'), 
distorm3.Decode64Bits)[0]
>>> i.opcode
9: 4474
>>> i.mnemonic
10: 'UNDEFINED'
>>> i.valid
11: True

0x1179: "CMPSS",
is also missing in distorm3.Mnemonics

Original comment by cesare.d...@gmail.com on 24 Jan 2012 at 8:50

GoogleCodeExporter commented 9 years ago
This issue and issue 30 seem to be caused by this line:
http://code.google.com/p/distorm/source/browse/trunk/src/decoder.c#296

                                di->opcode = ii->opcodeId + cmpType;

The index into the _MNEMONICS array is being offset by cmpType which has a 
value of 0-7 bytes. For the extended mnemonics of the cmpss/cmpsd/cmpps/cmppd 
instructions, we really want to offset by 0-7 mnemonics.

Original comment by spa...@rotateright.com on 7 Feb 2012 at 5:28

GoogleCodeExporter commented 9 years ago
Here's a possible fix:

                int i;
                unsigned int stringOffset = 0;
                /*
                 * The _MNEMONICS string contains pascal-style strings with the length of each mnemonic specified.
                 * We will sum each mnemonic length to arrive at the final mnemonic offset.
                 */
                for (i=0; i<cmpType; i++) {
                     /* +1 is for the null terminator, +1 is for the length byte itself */
                    if (_MNEMONICS_SIZE <= (ii->opcodeId + stringOffset)) goto _Undecodable;
                    stringOffset += _MNEMONICS[ii->opcodeId + stringOffset] + 2;
                }
                if (_MNEMONICS_SIZE <= (ii->opcodeId + stringOffset)) goto _Undecodable;
               di->opcode = ii->opcodeId + stringOffset;

I added _MNEMONICS_SIZE to mnemonics.c for safety checking:
const unsigned int _MNEMONICS_SIZE = sizeof(_MNEMONICS);

Original comment by spa...@rotateright.com on 7 Feb 2012 at 5:31

GoogleCodeExporter commented 9 years ago
Issue 30 has been merged into this issue.

Original comment by distorm@gmail.com on 26 Feb 2012 at 11:38

GoogleCodeExporter commented 9 years ago

Original comment by distorm@gmail.com on 26 Feb 2012 at 11:38

GoogleCodeExporter commented 9 years ago

Original comment by distorm@gmail.com on 26 Feb 2012 at 3:55

GoogleCodeExporter commented 9 years ago
Sanjay, thanks for your patch suggestion, but I used another way that doesn't 
need to loop - just another static table to look up the offsets.

Original comment by distorm@gmail.com on 27 Feb 2012 at 5:37

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r195.

Original comment by distorm@gmail.com on 27 Feb 2012 at 6:05

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r197.

Original comment by distorm@gmail.com on 28 Feb 2012 at 2:53