keystone icon indicating copy to clipboard operation
keystone copied to clipboard

MIPS Branch Jump Bug

Open Gift1a opened this issue 5 months ago • 0 comments

When I used the following code, the result is as follows. It stands to reason that the compilation results of the two should be consistent.It seems that there will be problems when the jump address exceeds 0x1FFFF. It may also be that I don’t know enough about MIPS. If it is not a bug, please let me know in time.

import keystone

ks = keystone.Ks(keystone.KS_ARCH_MIPS, keystone.KS_MODE_MIPS64)
print("beq $a1, $v1, 0x1FFFC addr=0x1FFF8")
print(ks.asm("beq $a1, $v1, 0x1FFFC", addr=0x1FFF8)[0][0:4])
print("beq $a1, $v1, 0x20000 addr=0x1FFFC")
print(ks.asm("beq $a1, $v1, 0x20000", addr=0x1FFFC)[0][0:4])
beq $a1, $v1, 0x1FFFC addr=0x1FFF8
[0, 0, 163, 16]
beq $a1, $v1, 0x20000 addr=0x1FFFC
Traceback (most recent call last):
  File "test_c_jmp.py", line 8, in <module>
    print(ks.asm("beq $a1, $v1, 0x20000", addr=0x1FFFC)[0][0:4])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Python/3.11/lib/python/site-packages/keystone/keystone.py", line 213, in asm
    raise KsError(errno, stat_count.value)
keystone.keystone.KsError: Invalid operand (KS_ERR_ASM_INVALIDOPERAND)

Gift1a avatar Jul 25 '25 08:07 Gift1a