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

Incorrect/Missing Python Binding for operands within the X86-64 STOS Instruction #2305

Open
LMS57 opened this issue Mar 30, 2024 · 0 comments
Labels
bug python bindings X86 Arch
Milestone

Comments

@LMS57
Copy link

LMS57 commented Mar 30, 2024

Work environment

Questions Answers
OS/arch/bits Debian X86 64
Architecture X86-64
Source of Capstone Python Pip Release
Version/git commit v5.0.1

Problem

Appears that there is missing or incorrect information when attempting to grab the register memory base from an operand within the STOS instruction in X86-64. This was found to exist within version 5.0.1 in the Python pip release version. This appears to have appeared since version v5.0.0 commit 34749cf. (That is not release version but just the version I happened to have compiled for easy testing). The expected behavior is below from the v5.0.0 test. The actual results from the v5.0.1 test shows that the instruction base value is now returning 0 instead of 39 for the needed registers.

Expected

5.0.0
<CsInsn 0x0 [f348ab]: rep stosq qword ptr [rdi], rax>
op_count: 2
39
0
<CsInsn 0x0 [48ab]: stosq qword ptr [rdi], rax>
op_count: 2
39
0
<CsInsn 0x0 [ab]: stosd dword ptr [rdi], eax>
op_count: 2
39
0

Actual behavior

5.0.1
<CsInsn 0x0 [f348ab]: rep stosq qword ptr [rdi], rax>
op_count: 2
0
0
<CsInsn 0x0 [48ab]: stosq qword ptr [rdi], rax>
op_count: 2
0
0
<CsInsn 0x0 [ab]: stosd dword ptr [rdi], eax>
op_count: 2
0
0

Code used for Testing

import capstone
from capstone import *

print(capstone.__version__)

code = [b'\xf3\x48\xab', b'\x48\xab', b'\xab']
'''
0:  f3 48 ab                rep stos QWORD PTR es:[rdi],rax
3:  48 ab                   stos   QWORD PTR es:[rdi],rax
5:  ab                      stos   DWORD PTR es:[rdi],eax
'''

if __name__ == '__main__':

    md = Cs(CS_ARCH_X86, CS_MODE_64)
    md.detail = True
    for c in code:
        for insn in md.disasm(c, 0):
            print(insn)
            print("op_count: %u" % len(insn.operands))
            for x in insn.operands:
                print(x.mem.base)

@Rot127 Rot127 added bug X86 Arch python bindings labels Mar 30, 2024
@Rot127 Rot127 added this to the v5.0.2 milestone Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug python bindings X86 Arch
Projects
None yet
Development

No branches or pull requests

2 participants