Commit b88ce129 authored by George Hotz's avatar George Hotz

failing at clone

parent 94ca24b1
......@@ -12,6 +12,7 @@ mu = Uc(UC_ARCH_MIPS, UC_MODE_32 + UC_MODE_BIG_ENDIAN)
mregs = [UC_MIPS_REG_AT, UC_MIPS_REG_V0, UC_MIPS_REG_V1, UC_MIPS_REG_A0, UC_MIPS_REG_A1, UC_MIPS_REG_A2, UC_MIPS_REG_A3]
regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
SIZE = 16*1024*1024
heap_start = 16*1024*1024
def hook_interrupt(uc, intno, user_data):
......@@ -19,7 +20,6 @@ def hook_interrupt(uc, intno, user_data):
pc = uc.reg_read(UC_MIPS_REG_PC)
if intno == 17:
syscall_no = uc.reg_read(UC_MIPS_REG_V0)
uc.reg_write(UC_MIPS_REG_A3, 0)
uc.reg_write(UC_MIPS_REG_V0, 0)
if syscall_no == 4004:
# write
......@@ -27,6 +27,7 @@ def hook_interrupt(uc, intno, user_data):
buf = uc.reg_read(UC_MIPS_REG_A1)
count = uc.reg_read(UC_MIPS_REG_A2)
os.write(fd, uc.mem_read(buf, count))
uc.reg_write(UC_MIPS_REG_A3, 0)
return True
print("syscall", syscall_no, hex(pc))
......@@ -35,6 +36,14 @@ def hook_interrupt(uc, intno, user_data):
print('open("%s")' % uc.mem_read(filename, 0x100).split(b"\x00")[0].decode('utf-8'))
# open fd=4
uc.reg_write(UC_MIPS_REG_V0, 4)
elif syscall_no == 4120:
print("clone not supported")
uc.reg_write(UC_MIPS_REG_V0, -1)
uc.reg_write(UC_MIPS_REG_A3, 0)
return True
elif syscall_no == 4263:
print("clock gettime")
#raise Exception
elif syscall_no == 4003:
fd = uc.reg_read(UC_MIPS_REG_A0)
buf = uc.reg_read(UC_MIPS_REG_A1)
......@@ -42,16 +51,22 @@ def hook_interrupt(uc, intno, user_data):
print("read", fd, hex(buf), count)
uc.mem_write(buf, b"16384\n\x00")
uc.reg_write(UC_MIPS_REG_V0, 6)
elif syscall_no == 4246:
print("EXIT")
return False
elif syscall_no == 4090:
a0 = uc.reg_read(UC_MIPS_REG_A0)
a1 = uc.reg_read(UC_MIPS_REG_A1)
a2 = uc.reg_read(UC_MIPS_REG_A2)
print("mmap", hex(a0), hex(a1), hex(a2), "at", hex(heap_start))
a3 = uc.reg_read(UC_MIPS_REG_A3)
a4 = uc.reg_read(UC_MIPS_REG_T0)
a5 = uc.reg_read(UC_MIPS_REG_T1)
print("mmap", hex(a0), hex(a1), hex(a2), hex(a3), hex(a4), hex(a5), "at", hex(heap_start))
if a0 == 0:
print("malloced new")
#mu.mem_map(heap_start, a1)
heap_start += a1
uc.reg_write(UC_MIPS_REG_V0, heap_start)
heap_start += a1
else:
uc.reg_write(UC_MIPS_REG_V0, a0)
......@@ -60,6 +75,7 @@ def hook_interrupt(uc, intno, user_data):
for i,r in zip(mregs, regs):
jj += "%s: %8x " % (r, uc.reg_read(i))
print(''.join(jj))
uc.reg_write(UC_MIPS_REG_A3, 0)
return True
print("interrupt", intno, hex(pc))
......@@ -102,11 +118,10 @@ elf.seek(0)
#rte = data.find(b"\x08\x02\x2c\x95")
#print(hex(rte))
SIZE = 16*1024*1024
mu.mem_map(0, SIZE)
# heap
mu.mem_map(SIZE, 0x10000000)
mu.mem_map(heap_start, 0x10000000)
elffile = ELFFile(elf)
for seg in elffile.iter_segments():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment