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

update_flags not working as expected for some ARM instructions #1568

Closed
cnheitman opened this issue Nov 27, 2019 · 6 comments · Fixed by #1949
Closed

update_flags not working as expected for some ARM instructions #1568

cnheitman opened this issue Nov 27, 2019 · 6 comments · Fixed by #1949
Labels

Comments

@cnheitman
Copy link

There seems to be an issue with update_flags on some ARM instruction (at least for ADC and SBC). More precisely, Capstone reports update_flags as true when it should be false (according to ARM reference manual).

The following code snippet shows the issue:

from capstone import *
from capstone.arm import *

CODE = [
    b"\x03\x00\xa1\xe0", # adcal r0, r1, r3
    b"\x03\x00\xb1\xe0", # adcsal r0, r1, r3
    b"\x03\x00\xc1\xe0", # sbcal r0, r1, r3
    b"\x03\x00\xd1\xe0", # sbcsal r0, r1, r3
    b"\x03\x00\x81\xe0", # addal r0, r1, r3
    b"\x03\x00\x91\xe0", # addsal r0, r1, r3
    b"\x03\x00\x41\xe0", # subal r0, r1, r3
    b"\x03\x00\x51\xe0", # subsal r0, r1, r3
]

md = Cs(CS_ARCH_ARM, CS_MODE_ARM)
md.detail = True

for code in CODE:
    for i in md.disasm(code, 0x1000):
        print("{} {} ; update_flags: {}".format(i.mnemonic, i.op_str, i.update_flags))

Output:

adc r0, r1, r3 ; update_flags: True
adcs r0, r1, r3 ; update_flags: True
sbc r0, r1, r3 ; update_flags: True
sbcs r0, r1, r3 ; update_flags: True
add r0, r1, r3 ; update_flags: False
adds r0, r1, r3 ; update_flags: True
sub r0, r1, r3 ; update_flags: False
subs r0, r1, r3 ; update_flags: True

Here update_flags is true for ADC and SBC when it should be false (generally, it should only report true for those instructions with the s suffix). Notice that this does not happen with neither ADD nor SUB.

@aquynh
Copy link
Collaborator

aquynh commented Nov 28, 2019

You may use "cstool -d" to avoid writing code.

Is this on the "next" branch?

@cnheitman
Copy link
Author

Thanks, I wasn't aware of the tool.
I tested it originally on version 4.0.1.
I've just tried on "next" branch and it also reports true when it should report false.
Retaled to this issue #247 (apparently reintroduced at some point).

@JonathanSalwan
Copy link

@aquynh up :)

@Rot127
Copy link
Collaborator

Rot127 commented Jun 29, 2023

Gets closed with #1949

@pipe01
Copy link

pipe01 commented May 17, 2024

This still seems to be an issue on 5.0.1

@Rot127 Rot127 added bug ARM Arch labels May 18, 2024
@Rot127
Copy link
Collaborator

Rot127 commented May 18, 2024

Are you able to use the next branch in your project? This fix is not so easily ported back. Because, from v5 on, we introduced a new updater (auto-sync) and changed the architecture module structure quite a bit.
If you use next you would get more precise details, alias detection and is based on LLVM 16 (soon 18).

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

Successfully merging a pull request may close this issue.

5 participants