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

Capstone failing to disassemble instruction #2612

Open
LowLevelSys opened this issue Jan 24, 2025 · 2 comments
Open

Capstone failing to disassemble instruction #2612

LowLevelSys opened this issue Jan 24, 2025 · 2 comments
Labels
bug Something is not working as it should outdated-module Issue due to an outdated arch module X86 Arch

Comments

@LowLevelSys
Copy link

Work environment

I am dissasembling a driver which attempts to detect hypervisors by catching mishandled instructions. Part of this mechanism is to execute an instruction that looks like this: lock sidt fword ptr [rcx]. Notice the lock prefix making the instruction "Invalid". I am not exactly sure whether this instruction should be decodable as it is not executable on any correctly working cpu.

Questions Answers
System Capstone runs on OS/arch/bits Windows x64 (latest Win10)
Capstone module affected x86
Source of Capstone Vcpkg
Version/git commit Latest Vcpkg (not sure which one)

Instruction bytes giving faulty results

F0 0F 01 09

Expected results

It should be:

lock sidt fword ptr [rcx] (IDA)

Steps to get the wrong result

Using a compiler compile a binary in which you manually encode a byte sequence that is F0 0F 01 09
This is the assembly sequence I used

__lock_sidt proc
   db 0F0h  ; lock prefix
   sidt qword ptr [rcx]
   ret
__lock_sidt endp

Then just open cs in x86 mode and try to disasm it

    csh handle;
    cs_insn* insn;
    if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK) {
        output_error("Failed to initialize Capstone disassembler.");
        return;
    }
    cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);

@Rot127 Rot127 added X86 Arch bug Something is not working as it should labels Jan 25, 2025
@Rot127
Copy link
Collaborator

Rot127 commented Jan 25, 2025

llvm-mc disassembles it. So Capstone should as well.

echo "0xF0,0x0F,0x01,0x09" | llvm-mc --arch x86 --disassemble
	.text
	lock
	sidtl	(%ecx)

@Rot127 Rot127 added the outdated-module Issue due to an outdated arch module label Jan 25, 2025
@Rot127
Copy link
Collaborator

Rot127 commented Jan 25, 2025

Be aware of #2505 for your use case.

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