Skip to contentSkip to conversation

allow to load android binary

PATCH In review matthieu castet 3 participants 3 messages Mar 2, 2011 – Mar 28, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 allow to load android binary

Hi,

Android binary start with a weird elf program header : the first one is of size 0 pointing to NULL addr.

Ignore LOAD program where MemSiz is 0.

Elf file type is EXEC (Executable file) Entry point 0xb0001000
There are 5 program headers, starting at offset 52

Program Headers:

 Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
 LOAD           0x0000d4 0x00000000 0xb0000000 0x00000 0x00000 R   0x1000
 LOAD           0x001000 0xb0001000 0xb0001000 0x073d4 0x073d4 R E 0x1000
 LOAD           0x009000 0xb0009000 0xb0009000 0x0068c 0x0969c RW  0x1000
 GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0
 EXIDX          0x00801c 0xb000801c 0xb000801c 0x003b8 0x003b8 R   0x4

Section to Segment mapping:
Segment Sections...
00
01 .text .rodata .ARM.extab .ARM.exidx
02 .preinit_array .init_array .fini_array .ctors .data.rel.ro .got .data .bss
03
04 .ARM.exidx

Quoted 1 line

From 4d986b66e9ae04efeabde9ad73f60d3c2d6912f9 Mon Sep 17 00:00:00 2001

From: Matthieu CASTET <[email protected]>
Date: Wed, 2 Mar 2011 17:04:39 +0100
Subject: [PATCH] allow to load android binary

Android binary start with a weird elf program header : the first one is of size 0 pointing to NULL addr.

Ignore LOAD program where MemSiz is 0.

Elf file type is EXEC (Executable file) Entry point 0xb0001000
There are 5 program headers, starting at offset 52

Program Headers:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x0000d4 0x00000000 0xb0000000 0x00000 0x00000 R   0x1000
  LOAD           0x001000 0xb0001000 0xb0001000 0x073d4 0x073d4 R E 0x1000
  LOAD           0x009000 0xb0009000 0xb0009000 0x0068c 0x0969c RW  0x1000
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0
  EXIDX          0x00801c 0xb000801c 0xb000801c 0x003b8 0x003b8 R   0x4

Section to Segment mapping:
Segment Sections...
00
01 .text .rodata .ARM.extab .ARM.exidx
02 .preinit_array .init_array .fini_array .ctors .data.rel.ro .got .data .bss
03
04 .ARM.exidx

---
 linux-user/elfload.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
linux-user/elfload.c +2 -2
index 33d776d..284f3be 100644
@@ -1201,7 +1201,7 @@ static void load_elf_image(const char *image_name, int image_fd,
        amount of memory to handle that.  */
     loaddr = -1, hiaddr = 0;
     for (i = 0; i < ehdr->e_phnum; ++i) {
-        if (phdr[i].p_type == PT_LOAD) {
+        if (phdr[i].p_type == PT_LOAD && phdr[i].p_memsz) {
             abi_ulong a = phdr[i].p_vaddr;
             if (a < loaddr) {
                 loaddr = a;
@@ -1301,7 +1301,7 @@ static void load_elf_image(const char *image_name, int image_fd,
 
     for (i = 0; i < ehdr->e_phnum; i++) {
         struct elf_phdr *eppnt = phdr + i;
-        if (eppnt->p_type == PT_LOAD) {
+        if (eppnt->p_type == PT_LOAD && eppnt->p_memsz) {
             abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em;
             int elf_prot = 0;
 
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 6 lines · matthieu castet <castet.matthieu <at> free.fr> writes:

Android binary start with a weird elf program header : the first one is of size 0 pointing to NULL addr.

Ignore LOAD program where MemSiz is 0.

...

Quoted 2 lines

Attachment (0001-allow-to-load-android-binary.patch): text/x-diff, 2172 bytes

This old patch (not mine) is required to run Android binaries with QEMU user-mode but it was integrated yet, there was no reply indeed. Do you want me to resend it with a more detailed description?

#2 lore raw

2012/3/28 Cédric VINCENT <[email protected]>:

Quoted 10 lines
Quoted 5 lines · matthieu castet <castet.matthieu <at> free.fr> writes:

Android binary start with a weird elf program header : the first one is of size 0 pointing to NULL addr.

Ignore LOAD program where MemSiz is 0.

This old patch (not mine) is required to run Android binaries with QEMU user-mode but it was integrated yet, there was no reply indeed. Do you want me to resend it with a more detailed description?

There was also this thread:
http://lists.gnu.org/archive/html/qemu-devel/2012-02/msg02810.html
about a different patch attempting to fix the same issue. I'm not sure which patch is better, haven't looked closely...

-- PMM