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

Wrong operand type for RISCV compressed instruction disassemble #2351

Open
apach301 opened this issue May 7, 2024 · 0 comments
Open

Wrong operand type for RISCV compressed instruction disassemble #2351

apach301 opened this issue May 7, 2024 · 0 comments
Labels
Milestone

Comments

@apach301
Copy link

apach301 commented May 7, 2024

Hi,

I tried to disassemble a compressed store instruction, but it turned out that capstone detected wrong operands:

>>> import capstone as cs
>>> md = cs.Cs(cs.CS_ARCH_RISCV, cs.CS_MODE_RISCVC)
>>> md.detail = True
>>> ins = md.disasm(b"\x98\xc3", 0).__next__()
>>> ins
<CsInsn 0x0 [98c3]: c.sw a4, 0(a5)>
>>> ins.operands[0].type
1
>>> ins.operands[1].type
2
>>> ins.operands[2].type
1
>>> cs.CS_OP_MEM
128
>>> cs.CS_OP_REG
1
>>> cs.CS_OP_IMM
2

This instruction expected to have two operands: OP_reg and OP_mem. Here is non-compressed analog for store:

>>> md = cs.Cs(cs.CS_ARCH_RISCV, cs.CS_MODE_RISCV64)
>>> md.detail = True
>>> ins = md.disasm(b"\x23\xa0\xe7\x00", 0).__next__()
>>> ins
<CsInsn 0x0 [23a0e700]: sw a4, 0(a5)>
>>> ins.operands
[<capstone.riscv.RISCVOp object at 0x7fe2e8de65c0>, <capstone.riscv.RISCVOp object at 0x7fe2e8de6bc0>]
>>> ins.operands[0].type
1
>>> ins.operands[1].type
3

Work environment

Questions Answers
OS/arch/bits Ubuntu 20.04, amd64
Architecture riscv
Source of Capstone git clone, pip
Version/git commit v5.0.1, current next branch
@Rot127 Rot127 added bug RISCV Arch outdated-module Issue due to an outdated arch module and removed outdated-module Issue due to an outdated arch module labels May 8, 2024
@Rot127 Rot127 added this to the v5.0.2 milestone May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants