diff options
| author | Ajax <commial@gmail.com> | 2015-03-19 10:12:42 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2015-03-19 10:12:42 +0100 |
| commit | 84832715898091f0da98e49502e45fdd77bc5748 (patch) | |
| tree | f15b31e16e70cb9b46312f349f198d06f28c9d6a /miasm2/jitter/loader/elf.py | |
| parent | 9adbbb771d946523f5fa140ec38e0292d5a76ee5 (diff) | |
| download | miasm-84832715898091f0da98e49502e45fdd77bc5748.tar.gz miasm-84832715898091f0da98e49502e45fdd77bc5748.zip | |
LoaderELF: Add `guess_arch` and link it to ContainerELF.arch
Diffstat (limited to 'miasm2/jitter/loader/elf.py')
| -rw-r--r-- | miasm2/jitter/loader/elf.py | 18 |
1 files changed, 18 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) |