Linux platform refactoring (#264)
* Clean up model syscall invocation * Move read_string to Cpu * move push/pop helpers to Cpu * Reorg Linux initialization * Update linux test * fstat64 test harness * assert read_string only considers concrete bytes * Ensure that correct aliases exist during ctor * Improve alias check
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from manticore.platforms import linux
|
||||
from manticore.platforms import linux, linux_syscalls
|
||||
|
||||
|
||||
class LinuxTest(unittest.TestCase):
|
||||
@@ -37,10 +38,10 @@ class LinuxTest(unittest.TestCase):
|
||||
envp_ptr = argv_ptr + len(real_argv)*8 + 8
|
||||
|
||||
for i, arg in enumerate(real_argv):
|
||||
self.assertEqual(self.linux._read_string(cpu.read_int(argv_ptr + i*8)), arg)
|
||||
self.assertEqual(cpu.read_string(cpu.read_int(argv_ptr + i*8)), arg)
|
||||
|
||||
for i, env in enumerate(envp):
|
||||
self.assertEqual(self.linux._read_string(cpu.read_int(envp_ptr + i*8)), env)
|
||||
self.assertEqual(cpu.read_string(cpu.read_int(envp_ptr + i*8)), env)
|
||||
|
||||
def test_load_maps(self):
|
||||
mappings = self.linux.current.memory.mappings()
|
||||
@@ -57,3 +58,25 @@ class LinuxTest(unittest.TestCase):
|
||||
self.assertEqual(first_map_name, '/bin/ls')
|
||||
self.assertEqual(second_map_name, '/bin/ls')
|
||||
|
||||
def test_syscall_fstat(self):
|
||||
nr_fstat64 = 197
|
||||
|
||||
# Create a minimal state
|
||||
model = linux.SLinux.empty_platform('armv7')
|
||||
model.current.memory.mmap(0x1000, 0x1000, 'rw ')
|
||||
model.current.SP = 0x2000-4
|
||||
|
||||
# open a file
|
||||
filename = model.current.push_bytes('/bin/true\x00')
|
||||
fd = model.sys_open(filename, os.O_RDONLY, 0600)
|
||||
|
||||
stat = model.current.SP - 0x100
|
||||
model.current.R0 = fd
|
||||
model.current.R1 = stat
|
||||
model.current.R7 = nr_fstat64
|
||||
self.assertEquals(linux_syscalls.armv7[nr_fstat64], 'sys_fstat64')
|
||||
|
||||
model.syscall()
|
||||
|
||||
print ''.join(model.current.read_bytes(stat, 100)).encode('hex')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user