diff options
| author | Frky <3105926+Frky@users.noreply.github.com> | 2020-02-19 09:03:19 +0100 |
|---|---|---|
| committer | Frky <3105926+Frky@users.noreply.github.com> | 2020-02-19 09:03:19 +0100 |
| commit | a36dc59b783b526c5455a2062ffa2c70b35fb7ef (patch) | |
| tree | ef6b999048cb6290a9103eab3accefd5456b41e5 | |
| parent | 34adff431fc01ede5dc08363535172967c723ba5 (diff) | |
| download | miasm-a36dc59b783b526c5455a2062ffa2c70b35fb7ef.tar.gz miasm-a36dc59b783b526c5455a2062ffa2c70b35fb7ef.zip | |
Implement minimalistic Linux environment and syscall table for x86_32
| -rw-r--r-- | miasm/arch/x86/jit.py | 11 | ||||
| -rw-r--r-- | miasm/os_dep/linux/environment.py | 13 | ||||
| -rw-r--r-- | miasm/os_dep/linux/syscall.py | 36 |
3 files changed, 60 insertions, 0 deletions
diff --git a/miasm/arch/x86/jit.py b/miasm/arch/x86/jit.py index 3c0d1b33..0144c289 100644 --- a/miasm/arch/x86/jit.py +++ b/miasm/arch/x86/jit.py @@ -182,6 +182,17 @@ class jitter_x86_32(Jitter): return getattr(self.cpu, args_regs[index]) return self.get_stack_arg(index - len(args_regs)) + def syscall_args_systemv(self, n_args): + # Documentation: http://man7.org/linux/man-pages/man2/syscall.2.html + # args: + # i386 ebx ecx edx esi edi ebp - + args = [self.cpu.EBX, self.cpu.ECX, self.cpu.EDX, self.cpu.ESI, + self.cpu.EDI, self.cpu.EBP][:n_args] + return args + + def syscall_ret_systemv(self, value): + # Documentation: http://man7.org/linux/man-pages/man2/syscall.2.html + self.cpu.EAX = value class jitter_x86_64(Jitter): diff --git a/miasm/os_dep/linux/environment.py b/miasm/os_dep/linux/environment.py index 07a7c9d4..53a97ce8 100644 --- a/miasm/os_dep/linux/environment.py +++ b/miasm/os_dep/linux/environment.py @@ -666,6 +666,19 @@ class LinuxEnvironment(object): return addr +class LinuxEnvironment_x86_32(LinuxEnvironment): + platform_arch = b"x86_32" + sys_machine = b"x86_32" + + # TODO FIXME + ## O_ACCMODE = 0x3 + ## O_CLOEXEC = 0x80000 + ## O_DIRECTORY = 0x10000 + ## O_LARGEFILE = 0x8000 + ## O_NONBLOCK = 0x800 + ## O_RDONLY = 0 + + class LinuxEnvironment_x86_64(LinuxEnvironment): platform_arch = b"x86_64" sys_machine = b"x86_64" diff --git a/miasm/os_dep/linux/syscall.py b/miasm/os_dep/linux/syscall.py index ca631fc8..fc6bbd8a 100644 --- a/miasm/os_dep/linux/syscall.py +++ b/miasm/os_dep/linux/syscall.py @@ -89,6 +89,37 @@ def sys_generic_brk(jitter, linux_env): jitter.syscall_ret_systemv(linux_env.brk(addr, jitter.vm)) +def sys_x86_32_newuname(jitter, linux_env): + # struct utsname { + # char sysname[]; /* Operating system name (e.g., "Linux") */ + # char nodename[]; /* Name within "some implementation-defined + # network" */ + # char release[]; /* Operating system release (e.g., "2.6.28") */ + # char version[]; /* Operating system version */ + # char machine[]; /* Hardware identifier */ + # } + + # Parse arguments + nameptr, = jitter.syscall_args_systemv(1) + log.debug("sys_newuname(%x)", nameptr) + + # Stub + info = [ + linux_env.sys_sysname, + linux_env.sys_nodename, + linux_env.sys_release, + linux_env.sys_version, + linux_env.sys_machine + ] + # TODO: Elements start at 0x41 multiples on my tests... + output = b"" + for elem in info: + output += elem + output += b"\x00" * (0x41 - len(elem)) + jitter.vm.set_mem(nameptr, output) + jitter.syscall_ret_systemv(0) + + def sys_x86_64_newuname(jitter, linux_env): # struct utsname { # char sysname[]; /* Operating system name (e.g., "Linux") */ @@ -867,6 +898,11 @@ def sys_arml_gettimeofday(jitter, linux_env): jitter.cpu.R0 = 0 +syscall_callbacks_x86_32 = { + 0x7A: sys_x86_32_newuname, +} + + syscall_callbacks_x86_64 = { 0x0: sys_generic_read, 0x1: sys_generic_write, |