From 4ad028b0df5472b2b29ed5eacff775f6afbb3dda Mon Sep 17 00:00:00 2001 From: Mark Mossberg Date: Thu, 20 Apr 2017 14:03:35 -0400 Subject: [PATCH] Fix arm/x86(32) linux stat (#153) * Fix sys_fstat i'm pretty sure it was totally wrong before, in terms of how it laid out the struct I'm based this on using arm-linux-gnueabi-gcc -E which shows me this struct: struct stat { __dev_t st_dev; unsigned short int __pad1; __ino_t st_ino; __mode_t st_mode; __nlink_t st_nlink; __uid_t st_uid; __gid_t st_gid; __dev_t st_rdev; unsigned short int __pad2; __off_t st_size; __blksize_t st_blksize; __blkcnt_t st_blocks; # 72 "/usr/arm-linux-gnueabi/include/bits/stat.h" 3 struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; # 87 "/usr/arm-linux-gnueabi/include/bits/stat.h" 3 unsigned long int __glibc_reserved4; unsigned long int __glibc_reserved5; }; * Add stat32 * Minor --- manticore/models/linux.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/manticore/models/linux.py b/manticore/models/linux.py index 09c6d14..edd3ddc 100644 --- a/manticore/models/linux.py +++ b/manticore/models/linux.py @@ -1535,7 +1535,7 @@ class Linux(object): 0x0000008d: self.sys_getpriority, 0x00000092: self.sys_writev32, 0x000000c0: self.sys_mmap2, - 0x000000c3: self.sys_stat64, + 0x000000c3: self.sys_stat32, 0x000000c5: self.sys_fstat, 0x000000c7: self.sys_getuid, 0x000000c8: self.sys_getgid, @@ -1789,8 +1789,17 @@ class Linux(object): :param buf: a buffer where data about the file will be stored. :return: C{0} on success. ''' + return self._stat(cpu, path, buf, True) + + def sys_stat32(self, cpu, path, buf): + return self._stat(cpu, path, buf, False) + + def _stat(self, cpu, path, buf, is64bit): fd = self.sys_open(cpu, path, 0, 'r') - ret = self.sys_fstat64(cpu, fd, buf) + if is64bit: + ret = self.sys_fstat64(cpu, fd, buf) + else: + ret = self.sys_fstat(cpu, fd, buf) self.sys_close(cpu, fd) return ret @@ -1938,26 +1947,22 @@ class SLinux(Linux): ''' stat = self.files[fd].stat() bufstat = '' - bufstat += struct.pack('