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

[X86] Disassembly Error, over-decode invalid instruction with mutual exclusive prefix #2547

Open
Mar3yZhang opened this issue Nov 14, 2024 · 2 comments
Labels
bug Something is not working as it should outdated-module Issue due to an outdated arch module X86 Arch

Comments

@Mar3yZhang
Copy link

Mar3yZhang commented Nov 14, 2024

Work environment

Questions Answers
OS/arch/bits x86_64 Ubuntu 20.04
Architecture x86_64
Source of Capstone git clone, default on next branch.
Version/git commit v6.0.0, d7be5f9

Instruction bytes giving faulty results

0xf0,0xf2,0x41,0x0f,0xb7,0xd6

Expected results

It should be:

ERROR: invalid assembly code

Steps to get the wrong result

With cstool:

$ ./cstool -d x64 "0xf0,0xf2,0x41,0x0f,0xb7,0xd6"
 0  f0 f2 41 0f b7 d6                                movzx      edx, r14w
        ID: 496 (movzx)
        Prefix:0x00 0x00 0x00 0x00 
        Opcode:0x0f 0xb7 0x00 0x00 
        rex: 0x41
        addr_size: 8
        modrm: 0xd6
        disp: 0x0
        sib: 0x0
        op_count: 2
                operands[0].type: REG = edx
                operands[0].size: 4
                operands[0].access: WRITE
                operands[1].type: REG = r14w
                operands[1].size: 2
                operands[1].access: READ
        Registers read: r14w
        Registers modified: edx
        
$ ./cstool -d x64 "0xf0,0x41,0x0f,0xb7,0xd6" 
ERROR: invalid assembly code

$ ./cstool -d x64 "0xf2,0x41,0x0f,0xb7,0xd6"
 0  f2 41 0f b7 d6                                   movzx      edx, r14w
        ID: 496 (movzx)
        Prefix:0x00 0x00 0x00 0x00 
        Opcode:0x0f 0xb7 0x00 0x00 
        rex: 0x41
        addr_size: 8
        modrm: 0xd6
        disp: 0x0
        sib: 0x0
        op_count: 2
                operands[0].type: REG = edx
                operands[0].size: 4
                operands[0].access: WRITE
                operands[1].type: REG = r14w
                operands[1].size: 2
                operands[1].access: READ
        Registers read: r14w
        Registers modified: edx

Additional Logs, screenshots, source code, configuration dump, ...

Capstone correctly identifies that the LOCK prefix (0xf0) is incompatible with the movzx instruction. It also has no problem with the REPNE/REPNZ prefix (0xf2). However, it fails to recognize that the prefixes 0xf2 and 0xf0 are mutually exclusive and cannot appear together in a single instruction. In contrast, both XED and Zydis disassemblers return an 'invalid assembly code' error for the sequence 0xf0, 0xf2, 0x41, 0x0f, 0xb7, 0xd6

@Mar3yZhang Mar3yZhang changed the title Disassembly Error, over-decode invalid movzx instruction with LOCK prefix Disassembly Error, over-decode invalid movzx instruction with mutual exclusive prefix Nov 14, 2024
@Mar3yZhang Mar3yZhang changed the title Disassembly Error, over-decode invalid movzx instruction with mutual exclusive prefix Disassembly Error, over-decode invalid instruction with mutual exclusive prefix Nov 14, 2024
@Rot127 Rot127 added bug Something is not working as it should X86 Arch outdated-module Issue due to an outdated arch module labels Nov 14, 2024
@Rot127
Copy link
Collaborator

Rot127 commented Nov 14, 2024

Thanks for reporting it.
Idk what your use case is, but please also take a look at #2505.

@Mar3yZhang
Copy link
Author

Thanks for reporting it. Idk what your use case is, but please also take a look at #2505.

Hi, Rot.
Thank you for your prompt reply! I think unified x86 instruction modeling will help the x86 software instruction decoder community.

@Mar3yZhang Mar3yZhang changed the title Disassembly Error, over-decode invalid instruction with mutual exclusive prefix [X86] Disassembly Error, over-decode invalid instruction with mutual exclusive prefix Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working as it should outdated-module Issue due to an outdated arch module X86 Arch
Projects
None yet
Development

No branches or pull requests

2 participants