capstone-engine / capstone

Capstone disassembly/disassembler framework for ARM, ARM64 (ARMv8), Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
http://www.capstone-engine.org
7.17k stars 1.52k forks source link

Incorrect aarch64 umov decoding #2372

Open psi-func opened 1 month ago

psi-func commented 1 month ago

Work environment

Questions Answers
OS/arch/bits Ubuntu 20.04, 64 bit
Architecture armv8
Source of Capstone git clone
Version/git commit v5.0.1, 097c04d9413c59a58b00d4d1c8d5dc0ac158ffaa

Instruction bytes giving faulty results

0x43,0x3c,0x1c,0x0e

Expected results

It should be:

umov w3, v2.S[3]

Steps to get the wrong result

./cstool -d arm64  0x43,0x3c,0x1c,0x0e 0x1000
1000  43 3c 1c 0e  mov  w3, v2.s[3]
        ID: 488 (mov)
        op_count: 2
                operands[0].type: REG = w3
                operands[0].access: WRITE
                operands[1].type: REG = v2
                operands[1].access: WRITE
                        Vector Arrangement Specifier: 0xb
                        Vector Index: 3
        Registers modified: w3 v2
        Groups: neon

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

According to official arm doc it's really alias on UMOV instruction, that's why ID: 488 (mov) is incorrect and leads to errors while using capstone as a library

Rot127 commented 1 month ago

I would advice to use the next branch for AArch64. It is better in every dimension. This one is fixed there in more then one way (note the incorrect access of operands in the example of yours):

On next branch:

./cstool -d aarch64  0x43,0x3c,0x1c,0x0e 0x1000
1000  43 3c 1c 0e  mov  w3, v2.s[3]
    ID: 1285 (umov)
    Is alias: 1429 (mov) with ALIAS operand set
    op_count: 2
        operands[0].type: REG = w3
        operands[0].access: WRITE
        operands[1].type: REG = q2 (vreg)
        operands[1].access: READ
            Vector Arrangement Specifier: 0x20
            Vector Index: 3
    Registers read: q2
    Registers modified: w3
    Groups: HasNEON 

Added it of course to the v5.0.2 milestone nonetheless.

If you want to use the next branch I advice to wait for https://github.com/capstone-engine/capstone/pull/2298 and https://github.com/capstone-engine/capstone/pull/2321 to be merged.

psi-func commented 1 month ago

Sorry, but next branch totally breaks API could it be possible to change the major version of the project to make life easier

Rot127 commented 1 month ago

could it be possible to change the major version of the project to make life easier

The next branch is the development branch and will be released as v6 (planned in September). If you need to check the "next" version number in source, you can use the CS_NEXT_VERSION macro.

Sorry, but next branch totally breaks API

Have you already tried to use https://github.com/capstone-engine/capstone/pull/2321? This should fix the rename problem from ARM64 to AArch64. If you don't want to fiddle with merging PRs locally please stand by until @aquynh and @kabeor reviewed and merged it.

Also, as a general overview and justifications for API changes see the release guide: https://github.com/capstone-engine/capstone/blob/next/docs/cs_v6_release_guide.md

When it comes to new or removed instructions, please note that they changed unfortunately in the past quite often as well. This was because Capstone didn't do a clear distinction between instruction alias and real instructions. This is now fixed. But this is as well explained in the release guide.