+ // Allocate Information Structure\r
+ ret = malloc( sizeof(tBinary) + sizeof(tBinarySection)*nLoadSegments );\r
+ // Fill Info Struct\r
+ ret->Entry = Header->e_entry;\r
+ ret->Base = -1; // Set Base to maximum value\r
+ ret->NumSections = nLoadSegments;\r
+ ret->Interpreter = NULL;\r
+\r
+ j = 0; // LoadSections[] index\r
+ for( i = 0; i < Header->e_phnum; i ++ )\r
+ {\r
+ LOG("phtab[%i] = {", i);\r
+ LOG(" .p_type = %i", phtab[i].p_type);\r
+ LOG(" .p_flags = 0x%x", phtab[i].p_flags);\r
+ LOG(" .p_offset = 0x%llx", phtab[i].p_offset);\r
+ LOG(" .p_vaddr = 0x%llx", phtab[i].p_vaddr);\r
+ LOG(" .p_paddr = 0x%llx", phtab[i].p_paddr);\r
+ LOG(" .p_filesz = 0x%llx", phtab[i].p_filesz);\r
+ LOG(" .p_memsz = 0x%llx", phtab[i].p_memsz);\r
+ LOG(" .p_align = 0x%llx", phtab[i].p_align);\r
+ LOG("}");\r
+\r
+ // Get Interpreter Name\r
+ if( phtab[i].p_type == PT_INTERP )\r
+ {\r
+ char *tmp;\r
+ if(ret->Interpreter) continue;\r
+ tmp = malloc(phtab[i].p_filesz);\r
+ VFS_Seek(FD, phtab[i].p_offset, 1);\r
+ VFS_Read(FD, phtab[i].p_filesz, tmp);\r
+ ret->Interpreter = Binary_RegInterp(tmp);\r
+ LOG("Interpreter '%s'", tmp);\r
+ free(tmp);\r
+ continue;\r
+ }\r
+ \r
+ if( phtab[i].p_type != PT_LOAD ) continue ;\r
+ \r
+ // Find the executable base\r
+ if( phtab[i].p_vaddr < ret->Base ) ret->Base = phtab[i].p_vaddr;\r
+\r
+ ret->LoadSections[j].Offset = phtab[i].p_offset;\r
+ ret->LoadSections[j].Virtual = phtab[i].p_vaddr;\r
+ ret->LoadSections[j].FileSize = phtab[i].p_filesz;\r
+ ret->LoadSections[j].MemSize = phtab[i].p_memsz;\r
+ \r
+ ret->LoadSections[j].Flags = 0;\r
+ if( !(phtab[i].p_flags & PF_W) )\r
+ ret->LoadSections[j].Flags |= BIN_SECTFLAG_RO;\r
+ if( phtab[i].p_flags & PF_X )\r
+ ret->LoadSections[j].Flags |= BIN_SECTFLAG_EXEC;\r
+ j ++;\r
+ }\r
+\r
+ return ret;\r
+}\r
+\r
+tBinary *Elf_Load32(int FD, Elf32_Ehdr *Header)\r
+{\r
+ tBinary *ret;\r
+ Elf32_Phdr *phtab;\r
+ int i, j;\r
+ int iLoadCount;\r
+\r
+ ENTER("xFD", FD);\r
+\r
+ // Check architecture with current CPU\r
+ // - TODO: Support kernel level emulation\r
+ #if ARCH_IS_x86\r
+ if( Header->machine != EM_386 )\r
+ {\r
+ Log_Warning("ELF", "Unknown architecure on ELF-32");\r
+ LEAVE_RET('n');\r
+ return NULL;\r
+ }\r
+ #endif\r
+\r