x86_64 Fix multiple REX prefix instruction disasm (#1376)

Fix multiple rex prefixes
This commit is contained in:
Konstantin Komarov 2021-07-03 12:04:25 +03:00 committed by GitHub
parent 069440e8b4
commit fcb324e04e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -751,14 +751,18 @@ class mn_x86(cls_mn):
break
pre_dis_info['prefix'] += c
offset += 1
if mode == 64 and c in b'@ABCDEFGHIJKLMNO':
x = ord(c)
rex_prefixes = b'@ABCDEFGHIJKLMNO'
if mode == 64 and c in rex_prefixes:
while c in rex_prefixes:
# multiple REX prefixes case - use last REX prefix
x = ord(c)
offset += 1
c = v.getbytes(offset)
pre_dis_info['rex_p'] = 1
pre_dis_info['rex_w'] = (x >> 3) & 1
pre_dis_info['rex_r'] = (x >> 2) & 1
pre_dis_info['rex_x'] = (x >> 1) & 1
pre_dis_info['rex_b'] = (x >> 0) & 1
offset += 1
elif pre_dis_info.get('g1', None) == 12 and c in [b'\xa6', b'\xa7', b'\xae', b'\xaf']:
pre_dis_info['g1'] = 4
return pre_dis_info, v, mode, offset, offset - offset_o

View file

@ -3125,6 +3125,8 @@ reg_tests = [
"f30f1efa"),
(m32, "00000000 ENDBR32",
"f30f1efb"),
(m64, "00000000 MOV QWORD PTR ES:[RAX], RDX",
"26488910"),
]
@ -3201,3 +3203,8 @@ cProfile.run('profile_dis(o)')
instr_bytes = b'\x65\xc7\x00\x09\x00\x00\x00'
inst = mn_x86.dis(instr_bytes, 32, 0)
assert(inst.b == instr_bytes)
# Test multiple REX prefixes
for i in range(1, 4):
mn = mn_x86.dis(b'\x26' + b'\x48' * i + b'\x89\x10', 64)
assert (str(mn).strip() == 'MOV QWORD PTR ES:[RAX], RDX')