* Acess v0.1\r
* ELF Executable Loader Code\r
*/\r
-#define DEBUG 0\r
+#define DEBUG 1\r
#include <stdlib.h>\r
#include <stdio.h>\r
#include <string.h>\r
#define PTR(_val) ((void*)(uintptr_t)(_val))\r
\r
#if DEBUG\r
-# define ENTER(...)\r
+# define ENTER(...) printf("%s: ---- ENTER ----\n", __func__);\r
# define LOG(s, ...) printf("%s: " s, __func__, __VA_ARGS__)\r
# define LOGS(s) printf("%s: " s, __func__)\r
# define LEAVE(...)\r
Elf32_Ehdr hdr;\r
\r
// Read ELF Header\r
- acess_read(FD, sizeof(hdr), &hdr);\r
+ acess_read(FD, &hdr, sizeof(hdr));\r
\r
// Check the file type\r
if(hdr.e_ident[0] != 0x7F || hdr.e_ident[1] != 'E' || hdr.e_ident[2] != 'L' || hdr.e_ident[3] != 'F') {\r
}\r
LOG("hdr.phoff = 0x%08x\n", hdr->phoff);\r
acess_seek(FD, hdr->phoff, ACESS_SEEK_SET);\r
- acess_read(FD, sizeof(Elf32_Phdr) * hdr->phentcount, phtab);\r
+ acess_read(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount);\r
\r
// Count Pages\r
iPageCount = 0;\r
// Load Pages\r
for( i = 0; i < hdr->phentcount; i++ )\r
{\r
- //LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type);\r
- LOG("phtab[%i] = {\n", i);\r
- LOG(" .Type = 0x%08x\n", phtab[i].Type);\r
- LOG(" .Offset = 0x%08x\n", phtab[i].Offset);\r
- LOG(" .VAddr = 0x%08x\n", phtab[i].VAddr);\r
- LOG(" .PAddr = 0x%08x\n", phtab[i].PAddr);\r
- LOG(" .FileSize = 0x%08x\n", phtab[i].FileSize);\r
- LOG(" .MemSize = 0x%08x\n", phtab[i].MemSize);\r
- LOG(" .Flags = 0x%08x\n", phtab[i].Flags);\r
- LOG(" .Align = 0x%08x\n", phtab[i].Align);\r
- LOGS(" }\n");\r
// Get Interpreter Name\r
if( phtab[i].Type == PT_INTERP )\r
{\r
//if(ret->Interpreter) continue;\r
tmp = malloc(phtab[i].FileSize);\r
acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
- acess_read(FD, phtab[i].FileSize, tmp);\r
+ acess_read(FD, tmp, phtab[i].FileSize);\r
//ret->Interpreter = Binary_RegInterp(tmp);\r
LOG("Interpreter '%s'\n", tmp);\r
free(tmp);\r
// Ignore non-LOAD types\r
if(phtab[i].Type != PT_LOAD) continue;\r
\r
- LOG("phtab[%i] = {VAddr:0x%x,Offset:0x%x,FileSize:0x%x}\n",\r
- i, phtab[i].VAddr+baseDiff, phtab[i].Offset, phtab[i].FileSize);\r
+ LOG("phtab[%i] = PT_LOAD {Adj VAddr:0x%x, Offset:0x%x, FileSize:0x%x, MemSize:0x%x}\n",\r
+ i, phtab[i].VAddr+baseDiff, phtab[i].Offset, phtab[i].FileSize, phtab[i].MemSize);\r
\r
addr = phtab[i].VAddr + baseDiff;\r
\r
}\r
\r
acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
- acess_read(FD, phtab[i].FileSize, PTRMK(void, addr) );\r
+ acess_read(FD, PTRMK(void, addr), phtab[i].FileSize);\r
memset( PTRMK(char, addr) + phtab[i].FileSize, 0, phtab[i].MemSize - phtab[i].FileSize );\r
}\r
\r