about summary refs log tree commit diff stats
path: root/miasm2/jitter
diff options
context:
space:
mode:
authorserpilliere <serpilliere@users.noreply.github.com>2015-03-19 13:43:20 +0100
committerserpilliere <serpilliere@users.noreply.github.com>2015-03-19 13:43:20 +0100
commite472b3b6ab1a86c0522e70f1fc5c8cb6361372eb (patch)
treeff384a705779e93badf5bf531ba630e46789e214 /miasm2/jitter
parentf05424a7acf75f7ab490e9df72c0006380def927 (diff)
parent595fda5b35238a9e468af5d3d674129d62e369dc (diff)
downloadmiasm-e472b3b6ab1a86c0522e70f1fc5c8cb6361372eb.tar.gz
miasm-e472b3b6ab1a86c0522e70f1fc5c8cb6361372eb.zip
Merge pull request #116 from commial/container-arch
Container arch
Diffstat (limited to '')
-rw-r--r--miasm2/jitter/loader/elf.py18
-rw-r--r--miasm2/jitter/loader/pe.py10
2 files changed, 28 insertions, 0 deletions
diff --git a/miasm2/jitter/loader/elf.py b/miasm2/jitter/loader/elf.py
index 916b37c4..c0427e79 100644
--- a/miasm2/jitter/loader/elf.py
+++ b/miasm2/jitter/loader/elf.py
@@ -3,6 +3,8 @@ from collections import defaultdict
 
 from elfesteem import cstruct
 from elfesteem import *
+import elfesteem.elf as elf_csts
+
 from miasm2.jitter.csts import *
 from miasm2.jitter.loader.utils import canon_libname_libfunc, libimp
 from miasm2.core.interval import interval
@@ -80,3 +82,19 @@ def vm_load_elf(vm, fdata, **kargs):
 
 class libimp_elf(libimp):
     pass
+
+
+# machine, size, sex -> arch_name
+ELF_machine = {(elf_csts.EM_ARM, 32, elf_csts.ELFDATA2LSB): "arml",
+               (elf_csts.EM_ARM, 32, elf_csts.ELFDATA2MSB): "armb",
+               (elf_csts.EM_MIPS, 32, elf_csts.ELFDATA2MSB): "mips32b",
+               (elf_csts.EM_MIPS, 32, elf_csts.ELFDATA2LSB): "mips32l",
+               (elf_csts.EM_386, 32, elf_csts.ELFDATA2LSB): "x86_32",
+               (elf_csts.EM_X86_64, 64, elf_csts.ELFDATA2LSB): "x86_64",
+               (elf_csts.EM_SH, 32, elf_csts.ELFDATA2LSB): "sh4",
+               }
+
+def guess_arch(elf):
+    """Return the architecture specified by the ELF container @elf.
+    If unknown, return None"""
+    return ELF_machine.get((elf.Ehdr.machine, elf.size, elf.sex), None)
diff --git a/miasm2/jitter/loader/pe.py b/miasm2/jitter/loader/pe.py
index a3834d03..7c11b9c5 100644
--- a/miasm2/jitter/loader/pe.py
+++ b/miasm2/jitter/loader/pe.py
@@ -406,3 +406,13 @@ class libimp_pe(libimp):
                 all_ads = all_ads[i + 1:]
 
         return new_lib
+
+# machine -> arch
+PE_machine = {0x14c: "x86_32",
+              0x8664: "x86_64",
+              }
+
+def guess_arch(pe):
+    """Return the architecture specified by the PE container @pe.
+    If unknown, return None"""
+    return PE_machine.get(pe.Coffhdr.machine, None)