2015-08-26 04:48:12 +03:00
|
|
|
#!/usr/bin/python
|
|
|
|
from unicorn import *
|
|
|
|
from unicorn.x86_const import *
|
|
|
|
|
2015-09-17 23:45:15 +03:00
|
|
|
import regress
|
|
|
|
|
2015-08-26 04:48:12 +03:00
|
|
|
ESP = 0x2000
|
|
|
|
PAGE_SIZE = 1 * 1024 * 1024
|
|
|
|
|
2015-09-19 20:02:30 +03:00
|
|
|
# wait
|
|
|
|
# fnstcw word ptr [esp]
|
|
|
|
# pop ecx
|
2015-08-26 04:48:12 +03:00
|
|
|
CODE = b'\x9B\xD9\x3C\x24\x59'
|
|
|
|
|
|
|
|
def hook_mem_write(uc, access, address, size, value, user_data):
|
2015-09-19 20:02:30 +03:00
|
|
|
print("mem WRITE: 0x%x, data size = %u, data value = 0x%x" % (address, size, value))
|
|
|
|
return True
|
2015-08-26 04:48:12 +03:00
|
|
|
|
2015-09-17 23:45:15 +03:00
|
|
|
class FpuWrite(regress.RegressTest):
|
|
|
|
|
|
|
|
def mem_reader(self, mu, addr, size, expected):
|
|
|
|
tmp = mu.mem_read(addr, size)
|
|
|
|
for i, e in zip(tmp, expected):
|
|
|
|
self.assertEquals(e, i)
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
mu = Uc(UC_ARCH_X86, UC_MODE_32)
|
|
|
|
mu.mem_map(0, PAGE_SIZE)
|
|
|
|
mu.mem_write(0, CODE)
|
|
|
|
mu.reg_write(UC_X86_REG_ESP, ESP)
|
|
|
|
|
|
|
|
mu.hook_add(UC_HOOK_MEM_WRITE, hook_mem_write)
|
2015-09-19 20:21:20 +03:00
|
|
|
mu.emu_start(0x0, 5, 0, 2)
|
2015-09-17 23:45:15 +03:00
|
|
|
esp = mu.reg_read(UC_X86_REG_ESP)
|
|
|
|
self.mem_reader(mu, esp, 10, [0] * 10)
|
2015-08-26 04:48:12 +03:00
|
|
|
|
2015-09-17 23:45:15 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
regress.main()
|