Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to disassemble valid CMPSS instruction #29

Closed
GoogleCodeExporter opened this issue Apr 20, 2015 · 10 comments
Closed

Unable to disassemble valid CMPSS instruction #29

GoogleCodeExporter opened this issue Apr 20, 2015 · 10 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

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

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Issue 30 has been merged into this issue.

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

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: Priority-High
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision r195.

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

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision r197.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant