about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <serpilliere@users.noreply.github.com>2018-02-16 20:18:41 +0100
committerGitHub <noreply@github.com>2018-02-16 20:18:41 +0100
commit143f02d418906279ac7a52043eab37e5c6d323e5 (patch)
treedd825f615d0043c98b5bc505c2d71eca07634813
parente933c0c31742ddb9dcfd9b46d93fe2a47553af5e (diff)
parentbc593098f878168ab974f4ae5e23f14edffcb775 (diff)
downloadmiasm-143f02d418906279ac7a52043eab37e5c6d323e5.tar.gz
miasm-143f02d418906279ac7a52043eab37e5c6d323e5.zip
Merge pull request #685 from a-vincent/fix-preload_elf-endianness
Enforce correct endianness of PLT entries
-rw-r--r--miasm2/jitter/loader/elf.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/miasm2/jitter/loader/elf.py b/miasm2/jitter/loader/elf.py
index db0f1cb7..336f522a 100644
--- a/miasm2/jitter/loader/elf.py
+++ b/miasm2/jitter/loader/elf.py
@@ -42,8 +42,13 @@ def preload_elf(vm, e, runtime_lib, patch_vm_imp=True):
             dyn_funcs[libname_s] = ad_libfunc
             if patch_vm_imp:
                 log.debug('patch 0x%x 0x%x %s', ad, ad_libfunc, libfunc)
-                vm.set_mem(
-                    ad, struct.pack(cstruct.size2type[e.size], ad_libfunc))
+                set_endianness = { elf_csts.ELFDATA2MSB: ">",
+                                   elf_csts.ELFDATA2LSB: "<",
+                                   elf_csts.ELFDATANONE: "" }[e.sex]
+                vm.set_mem(ad,
+                           struct.pack(set_endianness +
+                                       cstruct.size2type[e.size],
+                                       ad_libfunc))
     return runtime_lib, dyn_funcs