X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=inline;f=Usermode%2FLibraries%2Fld-acess.so_src%2Fmain.c;h=ff715bb33502853568f04b76e7d694745098b011;hb=032ec5adf8d4faeaa9293da50ad2e32c83dd1704;hp=dfb1b6158e02d876d76ac8b6b28e6373db482fb6;hpb=3d6a345b39afa454f0f33fc8d48b96229971e6ed;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/ld-acess.so_src/main.c b/Usermode/Libraries/ld-acess.so_src/main.c index dfb1b615..ff715bb3 100644 --- a/Usermode/Libraries/ld-acess.so_src/main.c +++ b/Usermode/Libraries/ld-acess.so_src/main.c @@ -3,16 +3,15 @@ By thePowersGang */ #include +#include #include "common.h" // === PROTOTYPES === -void *DoRelocate(void *base, char **envp, char *Filename); +void *DoRelocate(void *base, char **envp, const char *Filename); int CallUser(void *Entry, void *SP); -void *ElfRelocate(void *Base, char *envp[], char *Filename); -void *PE_Relocate(void *Base, char *envp[], char *Filename); // === Imports === -extern void gLinkedBase; +extern char gLinkedBase[]; extern tLoadedLib gLoadedLibraries[]; // === CODE === @@ -21,7 +20,7 @@ extern tLoadedLib gLoadedLibraries[]; \brief Library entry point \note This is the entrypoint for the library */ -int SoMain(void *base, void *arg1) +void *SoMain(void *base) { void *ret; @@ -50,28 +49,29 @@ int SoMain(void *base, void *arg1) _exit(-1); for(;;); } - - // And call user - //SysDebug("Calling User at 0x%x\n", ret); - CallUser( ret, &arg1 ); - - return 0; + + SysDebug("ld-acess - SoMain: ret = %p", ret); + return ret; } /** \fn int DoRelocate(void *base, char **envp) \brief Relocates an in-memory image */ -void *DoRelocate(void *base, char **envp, char *Filename) +void *DoRelocate(void *base, char **envp, const char *Filename) { + uint8_t *hdr = base; // Load Executable - if(*(Uint32*)base == (0x7F|('E'<<8)|('L'<<16)|('F'<<24))) + if(memcmp(base, "\x7F""ELF", 4) == 0) return ElfRelocate(base, envp, Filename); - if(*(Uint16*)base == ('M'|('Z'<<8))) + if(hdr[0] == 0x7F && hdr[1] == 'E' && hdr[2] == 'L' && hdr[3] == 'F') + return ElfRelocate(base, envp, Filename); + + if(hdr[0] == 'M' && hdr[1] == 'Z') return PE_Relocate(base, envp, Filename); SysDebug("ld-acess - DoRelocate: Unkown file format '0x%x 0x%x 0x%x 0x%x'\n", - *(Uint8*)(base), *(Uint8*)(base+1), *(Uint8*)(base+2), *(Uint8*)(base+3) ); + hdr[0], hdr[1], hdr[2], hdr[3] ); SysDebug("ld-acess - DoRelocate: File '%s'\n", Filename); _exit(-1); for(;;);