about summary refs log tree commit diff stats
path: root/miasm2/analysis/binary.py
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/analysis/binary.py
parentf05424a7acf75f7ab490e9df72c0006380def927 (diff)
parent595fda5b35238a9e468af5d3d674129d62e369dc (diff)
downloadmiasm-e472b3b6ab1a86c0522e70f1fc5c8cb6361372eb.tar.gz
miasm-e472b3b6ab1a86c0522e70f1fc5c8cb6361372eb.zip
Merge pull request #116 from commial/container-arch
Container arch
Diffstat (limited to 'miasm2/analysis/binary.py')
-rw-r--r--miasm2/analysis/binary.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/miasm2/analysis/binary.py b/miasm2/analysis/binary.py
index f5cecc87..c71c5e9b 100644
--- a/miasm2/analysis/binary.py
+++ b/miasm2/analysis/binary.py
@@ -88,6 +88,13 @@ class Container(object):
 
     def __init__(self, *args, **kwargs):
         "Alias for 'parse'"
+        # Init attributes
+        self._executable = None
+        self._bin_stream = None
+        self._entry_point = None
+        self._arch = None
+
+        # Launch parsing
         self.parse(*args, **kwargs)
 
     @property
@@ -105,14 +112,18 @@ class Container(object):
         "Return the detected entry_point"
         return self._entry_point
 
+    @property
+    def arch(self):
+        "Return the guessed architecture"
+        return self._arch
+
 
 ## Format dependent classes
 class ContainerPE(Container):
     "Container abstraction for PE"
 
-
     def parse(self, data, vm=None):
-        from miasm2.jitter.loader.pe import vm_load_pe, preload_pe
+        from miasm2.jitter.loader.pe import vm_load_pe, preload_pe, guess_arch
         from elfesteem import pe_init
 
         # Parse signature
@@ -133,6 +144,9 @@ class ContainerPE(Container):
                 self._executable.NTsig.signature_value != 0x4550:
             raise ContainerSignatureException()
 
+        # Guess the architecture
+        self._arch = guess_arch(self._executable)
+
         # Build the bin_stream instance and set the entry point
         try:
             self._bin_stream = bin_stream_pe(self._executable.virt)
@@ -146,7 +160,8 @@ class ContainerELF(Container):
     "Container abstraction for ELF"
 
     def parse(self, data, vm=None):
-        from miasm2.jitter.loader.elf import vm_load_elf, preload_elf
+        from miasm2.jitter.loader.elf import \
+            vm_load_elf, preload_elf, guess_arch
         from elfesteem import elf_init
 
         # Parse signature
@@ -162,6 +177,9 @@ class ContainerELF(Container):
         except Exception, error:
             raise ContainerParsingException('Cannot read ELF: %s' % error)
 
+        # Guess the architecture
+        self._arch = guess_arch(self._executable)
+
         # Build the bin_stream instance and set the entry point
         try:
             self._bin_stream = bin_stream_elf(self._executable.virt)