X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Fld-acess.so_src%2Fpe.c;h=057345cd85b09836d18fe6d2286fa3848584b4b5;hb=6a28fd66345b484f9dfa5dba869888becdaf7112;hp=ec3b6b840016a697fed89613bbebb7d538d94337;hpb=17e16b3110b4c5124b0707435e0427993d696545;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/ld-acess.so_src/pe.c b/Usermode/Libraries/ld-acess.so_src/pe.c index ec3b6b84..057345cd 100644 --- a/Usermode/Libraries/ld-acess.so_src/pe.c +++ b/Usermode/Libraries/ld-acess.so_src/pe.c @@ -3,6 +3,7 @@ * Portable Executable Loader */ #include "common.h" +#include #include "pe.h" #define PE_DEBUG 0 @@ -18,12 +19,12 @@ #endif // === PROTOTYPES === - int PE_Relocate(void *Base, char **envp, char *Filename); +void *PE_Relocate(void *Base, char **envp, const char *Filename); char *PE_int_GetTrueFile(char *file); - int PE_int_GetForwardSymbol(char *Fwd, Uint *Value); + int PE_int_GetForwardSymbol(char *Fwd, void **Value); // === CODE === -int PE_Relocate(void *Base, char *envp[], char *Filename) +void *PE_Relocate(void *Base, char **envp, const char *Filename) { tPE_DOS_HEADER *dosHdr = Base; tPE_IMAGE_HEADERS *peHeaders; @@ -32,8 +33,8 @@ int PE_Relocate(void *Base, char *envp[], char *Filename) tPE_HINT_NAME *name; Uint32 *importTab, *aIAT; int i, j; - Uint iBase = (Uint)Base; - Uint iLibBase; + intptr_t iBase = (intptr_t)Base; + void *pLibBase; DEBUGS("PE_Relocate: (Base=0x%x)\n", Base); @@ -49,12 +50,12 @@ int PE_Relocate(void *Base, char *envp[], char *Filename) impDir[i].ImportLookupTable += iBase/4; impDir[i].ImportAddressTable += iBase/4; DEBUGS(" PE_Relocate: DLL Required '%s'(0x%x)\n", impDir[i].DLLName, impDir[i].DLLName); - iLibBase = LoadLibrary(PE_int_GetTrueFile(impDir[i].DLLName), DLL_BASE_PATH, envp); - if(iLibBase == 0) { + pLibBase = LoadLibrary(PE_int_GetTrueFile(impDir[i].DLLName), DLL_BASE_PATH, envp); + if(pLibBase == 0) { SysDebug("Unable to load required library '%s'\n", impDir[i].DLLName); return 0; } - DEBUGS(" PE_Relocate: Loaded as 0x%x\n", iLibBase); + DEBUGS(" PE_Relocate: Loaded as 0x%x\n", pLibBase); importTab = impDir[i].ImportLookupTable; aIAT = impDir[i].ImportAddressTable; for( j = 0; importTab[j] != 0; j++ ) @@ -63,12 +64,15 @@ int PE_Relocate(void *Base, char *envp[], char *Filename) DEBUGS(" PE_Relocate: Import Ordinal %i\n", importTab[j] & 0x7FFFFFFF); else { + void *symPtr = 0; name = (void*)( iBase + importTab[j] ); DEBUGS(" PE_Relocate: Import Name '%s', Hint 0x%x\n", name->Name, name->Hint); - if( GetSymbolFromBase(iLibBase, name->Name, (Uint*)&aIAT[j]) == 0 ) { + if( GetSymbolFromBase(pLibBase, name->Name, symPtr, NULL) == 0 ) + { SysDebug("Unable to find symbol '%s' in library '%s'\n", name->Name, impDir[i].DLLName); return 0; } + aIAT[j] = (intptr_t)symPtr; } } } @@ -82,15 +86,15 @@ int PE_Relocate(void *Base, char *envp[], char *Filename) DEBUGS("PE_Relocate: RETURN 0x%x\n", iBase + peHeaders->OptHeader.EntryPoint); - return iBase + peHeaders->OptHeader.EntryPoint; + return (void*)( iBase + peHeaders->OptHeader.EntryPoint ); } /** - * \fn int PE_GetSymbol(Uint Base, char *Name, Uint *Ret) + * \fn int PE_GetSymbol(Uint Base, const char *Name, Uint *Ret) */ -int PE_GetSymbol(Uint Base, char *Name, Uint *Ret) +int PE_GetSymbol(void *Base, const char *Name, void **Ret, size_t *Size) { - tPE_DOS_HEADER *dosHdr = (void*)Base; + tPE_DOS_HEADER *dosHdr = Base; tPE_IMAGE_HEADERS *peHeaders; tPE_DATA_DIR *directory; tPE_EXPORT_DIR *expDir; @@ -99,7 +103,7 @@ int PE_GetSymbol(Uint Base, char *Name, Uint *Ret) int i; int symbolCount; char *name; - Uint retVal; + intptr_t retVal; Uint expLen; peHeaders = (void*)( Base + dosHdr->PeHdrOffs ); @@ -118,14 +122,15 @@ int PE_GetSymbol(Uint Base, char *Name, Uint *Ret) //DEBUGS(" PE_GetSymbol: '%s' = 0x%x\n", name, Base + addrTable[ ordTable[i] ]); if(strcmp(name, Name) == 0) { - retVal = Base + addrTable[ ordTable[i] ]; + retVal = (intptr_t) Base + addrTable[ ordTable[i] ]; // Check for forwarding - if((Uint)expDir < retVal && retVal < (Uint)expDir + expLen) { + if( (intptr_t)expDir < retVal && retVal < (intptr_t)expDir + expLen) { char *fwd = (char*)retVal; DEBUGS(" PE_GetSymbol: '%s' forwards to '%s'\n", name, fwd); return PE_int_GetForwardSymbol(fwd, Ret); } - *Ret = retVal; + *Ret = (void*)retVal; + if(Size) *Size = 0; return 1; } } @@ -149,12 +154,12 @@ char *PE_int_GetTrueFile(char *file) return &file[1]; } -int PE_int_GetForwardSymbol(char *Fwd, Uint *Value) +int PE_int_GetForwardSymbol(char *Fwd, void **Value) { char *libname; char *sym; int i; - Uint libbase; + void *libbase; int ret; // -- Find seperator @@ -171,9 +176,10 @@ int PE_int_GetForwardSymbol(char *Fwd, Uint *Value) DEBUGS(" PE_int_GetForwardSymbol: Get '%s' from '%s'\n", sym, libname); libbase = LoadLibrary(libname, DLL_BASE_PATH, NULL); - ret = GetSymbolFromBase(libbase, sym, Value); + ret = GetSymbolFromBase(libbase, sym, Value, NULL); if(!ret) { SysDebug(" PE_int_GetForwardSymbol: Unable to find '%s' in '%s'\n", sym, libname); + return 0; } Fwd[i] = '.'; return ret;