keystone-engine / keystone

Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings
http://www.keystone-engine.org
GNU General Public License v2.0
2.3k stars 458 forks source link

keystone failing on certain instructions #546

Open Caesurus opened 1 year ago

Caesurus commented 1 year ago

When I get assembly this way from gcc:

$echo " " |gcc -xc -S -o- - -m64
        .file   ""
        .text
        .ident  "GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0"
        .section        .note.GNU-stack,"",@progbits
        .section        .note.gnu.property,"a"
        .align 8
        .long    1f - 0f
        .long    4f - 1f
        .long    5
0:
        .string  "GNU"
1:
        .align 8
        .long    0xc0000002
        .long    3f - 2f
2:
        .long    0x3
3:
        .align 8
4:

The .long lines without 0x are causing issues:

$ kstool x64 '.long    3f - 2f'
ERROR: failed on ks_asm() with count = 0, error = 'Invalid directive (KS_ERR_ASM_DIRECTIVE_INVALID)' (code = 139)

But if they are reformatted:

$ kstool x64 '.long    0x3f - 0x2f'
.long    0x3f - 0x2f = [ 10 00 00 00 ]

It's fine.

Additionally I have errors on these as well:

kstool x64 'movb     (%rcx,%rdx), %dl'
ERROR: failed on ks_asm() with count = 0, error = 'Invalid operand (KS_ERR_ASM_INVALIDOPERAND)' (code = 512)

and

kstool x64 'leal     -48(%rax,%rdx), %eax'
ERROR: failed on ks_asm() with count = 0, error = 'Invalid operand (KS_ERR_ASM_INVALIDOPERAND)' (code = 512)