Index: elfutils-0.122/libelf/elf32_getshdr.c
===================================================================
--- elfutils-0.122.orig/libelf/elf32_getshdr.c	2006-08-13 16:43:26.000000000 +0000
+++ elfutils-0.122/libelf/elf32_getshdr.c	2006-08-13 16:45:20.000000000 +0000
@@ -158,16 +158,30 @@
 
 	  for (size_t cnt = 0; cnt < shnum; ++cnt)
 	    {
-	      CONVERT_TO (shdr[cnt].sh_name, notcvt[cnt].sh_name);
-	      CONVERT_TO (shdr[cnt].sh_type, notcvt[cnt].sh_type);
-	      CONVERT_TO (shdr[cnt].sh_flags, notcvt[cnt].sh_flags);
-	      CONVERT_TO (shdr[cnt].sh_addr, notcvt[cnt].sh_addr);
-	      CONVERT_TO (shdr[cnt].sh_offset, notcvt[cnt].sh_offset);
-	      CONVERT_TO (shdr[cnt].sh_size, notcvt[cnt].sh_size);
-	      CONVERT_TO (shdr[cnt].sh_link, notcvt[cnt].sh_link);
-	      CONVERT_TO (shdr[cnt].sh_info, notcvt[cnt].sh_info);
-	      CONVERT_TO (shdr[cnt].sh_addralign, notcvt[cnt].sh_addralign);
-	      CONVERT_TO (shdr[cnt].sh_entsize, notcvt[cnt].sh_entsize);
+		if (ehdr->e_ident[EI_DATA] != MY_ELFDATA)
+		{
+		    CONVERT_TO (shdr[cnt].sh_name, notcvt[cnt].sh_name);
+		    CONVERT_TO (shdr[cnt].sh_type, notcvt[cnt].sh_type);
+		    CONVERT_TO (shdr[cnt].sh_flags, notcvt[cnt].sh_flags);
+		    CONVERT_TO (shdr[cnt].sh_addr, notcvt[cnt].sh_addr);
+		    CONVERT_TO (shdr[cnt].sh_offset, notcvt[cnt].sh_offset);
+		    CONVERT_TO (shdr[cnt].sh_size, notcvt[cnt].sh_size);
+		    CONVERT_TO (shdr[cnt].sh_link, notcvt[cnt].sh_link);
+		    CONVERT_TO (shdr[cnt].sh_info, notcvt[cnt].sh_info);
+		    CONVERT_TO (shdr[cnt].sh_addralign, notcvt[cnt].sh_addralign);
+		    CONVERT_TO (shdr[cnt].sh_entsize, notcvt[cnt].sh_entsize);
+		} else {
+		    shdr[cnt].sh_name = notcvt[cnt].sh_name;
+		    shdr[cnt].sh_type = notcvt[cnt].sh_type;
+		    shdr[cnt].sh_flags = notcvt[cnt].sh_flags;
+		    shdr[cnt].sh_addr = notcvt[cnt].sh_addr;
+		    shdr[cnt].sh_offset = notcvt[cnt].sh_offset;
+		    shdr[cnt].sh_size = notcvt[cnt].sh_size;
+		    shdr[cnt].sh_link = notcvt[cnt].sh_link;
+		    shdr[cnt].sh_info = notcvt[cnt].sh_info;
+		    shdr[cnt].sh_addralign = notcvt[cnt].sh_addralign;
+		    shdr[cnt].sh_entsize = notcvt[cnt].sh_entsize;
+		}
 	    }
 	}
       else if (likely (elf->fildes != -1))
Index: elfutils-0.122/libelf/elf32_getphdr.c
===================================================================
--- elfutils-0.122.orig/libelf/elf32_getphdr.c	2006-08-13 16:43:30.000000000 +0000
+++ elfutils-0.122/libelf/elf32_getphdr.c	2006-08-13 16:47:49.000000000 +0000
@@ -170,14 +170,26 @@
 
 	      for (size_t cnt = 0; cnt < phnum; ++cnt)
 		{
-		  CONVERT_TO (phdr[cnt].p_type, notcvt[cnt].p_type);
-		  CONVERT_TO (phdr[cnt].p_offset, notcvt[cnt].p_offset);
-		  CONVERT_TO (phdr[cnt].p_vaddr, notcvt[cnt].p_vaddr);
-		  CONVERT_TO (phdr[cnt].p_paddr, notcvt[cnt].p_paddr);
-		  CONVERT_TO (phdr[cnt].p_filesz, notcvt[cnt].p_filesz);
-		  CONVERT_TO (phdr[cnt].p_memsz, notcvt[cnt].p_memsz);
-		  CONVERT_TO (phdr[cnt].p_flags, notcvt[cnt].p_flags);
-		  CONVERT_TO (phdr[cnt].p_align, notcvt[cnt].p_align);
+		  if (ehdr->e_ident[EI_DATA] != MY_ELFDATA)
+		  {
+		      CONVERT_TO (phdr[cnt].p_type, notcvt[cnt].p_type);
+		      CONVERT_TO (phdr[cnt].p_offset, notcvt[cnt].p_offset);
+		      CONVERT_TO (phdr[cnt].p_vaddr, notcvt[cnt].p_vaddr);
+		      CONVERT_TO (phdr[cnt].p_paddr, notcvt[cnt].p_paddr);
+		      CONVERT_TO (phdr[cnt].p_filesz, notcvt[cnt].p_filesz);
+		      CONVERT_TO (phdr[cnt].p_memsz, notcvt[cnt].p_memsz);
+		      CONVERT_TO (phdr[cnt].p_flags, notcvt[cnt].p_flags);
+		      CONVERT_TO (phdr[cnt].p_align, notcvt[cnt].p_align);
+		  } else {
+		      phdr[cnt].p_type = notcvt[cnt].p_type;
+		      phdr[cnt].p_offset = notcvt[cnt].p_offset;
+		      phdr[cnt].p_vaddr = notcvt[cnt].p_vaddr;
+		      phdr[cnt].p_paddr = notcvt[cnt].p_paddr;
+		      phdr[cnt].p_filesz = notcvt[cnt].p_filesz;
+		      phdr[cnt].p_memsz = notcvt[cnt].p_memsz;
+		      phdr[cnt].p_flags = notcvt[cnt].p_flags;
+		      phdr[cnt].p_align = notcvt[cnt].p_align;
+		  }
 		}
 	    }
 	}

