Skip to content

Commit 3106426

Browse files
committed
Implement vpbroadcastq
1 parent c4b7854 commit 3106426

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/dumpulator/dumpulator.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,7 @@ def _get_regs(instr, include_write=False):
14501450

14511451
def _hook_code(uc: Uc, address, size, dp: Dumpulator):
14521452
try:
1453+
uc.ctl_remove_cache(address, address + 16)
14531454
code = b""
14541455
try:
14551456
code = dp.read(address, min(size, 15))
@@ -1693,7 +1694,6 @@ def op_mem(op: X86Op, *, aligned: bool):
16931694
mem_address = 0
16941695
if op.mem.base == X86_REG_RIP:
16951696
mem_address += instr.address + instr.size
1696-
raise NotImplementedError("TODO: check if the disp is already adjusted")
16971697
else:
16981698
base = op.mem.base
16991699
if base != X86_REG_INVALID:
@@ -1749,13 +1749,25 @@ def op_write(index: int, value: int, *, aligned=False):
17491749
else:
17501750
raise NotImplementedError()
17511751

1752+
def op_bits(index: int):
1753+
return instr.operands[index].size * 8
1754+
17521755
def cip_next():
17531756
dp.regs.cip += instr.size
17541757

17551758
if instr.id == X86_INS_RDRAND:
17561759
# TODO: PRNG based on dmp hash
17571760
op_write(0, 42)
17581761
cip_next()
1762+
elif instr.id == X86_INS_RDTSCP:
1763+
# TODO: properly implement
1764+
dp.regs.rdx = 0
1765+
dp.regs.rax = 0
1766+
dp.regs.rcx = 0
1767+
cip_next()
1768+
elif instr.id == X86_INS_RDGSBASE:
1769+
op_write(0, dp.regs.gs_base)
1770+
cip_next()
17591771
elif instr.id in [X86_INS_VMOVDQU, X86_INS_VMOVUPS]:
17601772
src = op_read(1)
17611773
op_write(0, src)
@@ -1774,9 +1786,16 @@ def cip_next():
17741786
src = (src & 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff) | (xmm1 << 128)
17751787
op_write(0, src)
17761788
cip_next()
1777-
1789+
elif instr.id == X86_INS_VPBROADCASTQ:
1790+
src = op_read(1) & 0xFFFFFFFFFFFFFFFF
1791+
result = 0
1792+
for _ in range(op_bits(0) // 64):
1793+
result <<= 64
1794+
result |= src
1795+
op_write(0, result)
1796+
cip_next()
17781797
else:
1779-
dp.error(f"unsupported: {instr.mnemonic} {instr.op_str}")
1798+
dp.error(f"unsupported: {hex(instr.address)}|{instr.mnemonic} {instr.op_str}")
17801799
# Unsupported instruction
17811800
return False
17821801
dp.debug(f"emulated: {hex(instr.address)}|{instr.bytes.hex()}|{instr.mnemonic} {instr.op_str}")
@@ -1794,6 +1813,7 @@ def _hook_invalid(uc: Uc, dp: Dumpulator):
17941813
try:
17951814
code = dp.read(address, 15)
17961815
instr = next(dp.cs.disasm(code, address, 1))
1816+
dp.debug(f"invalid hook {hex(address)}|{code.hex()}|{instr.mnemonic} {instr.op_str}")
17971817
# TODO: add a hook
17981818
if _emulate_unsupported_instruction(dp, instr):
17991819
# Resume execution with a context switch
@@ -1807,5 +1827,8 @@ def _hook_invalid(uc: Uc, dp: Dumpulator):
18071827
pass # Unsupported instruction
18081828
except IndexError:
18091829
pass # Invalid memory access (NOTE: this should not be possible actually)
1830+
except Exception as err:
1831+
print(f"Unexpected exception {type(err)}")
1832+
traceback.print_exc()
18101833
dp.error(f"invalid instruction at {hex(address)}")
18111834
raise NotImplementedError("TODO: throw invalid instruction exception")

0 commit comments

Comments
 (0)