* Portable Executable Loader\r
*/\r
#include "common.h"\r
+#include <stdint.h>\r
#include "pe.h"\r
\r
#define PE_DEBUG 0\r
#endif\r
\r
// === PROTOTYPES ===\r
- int PE_Relocate(void *Base, char **envp, char *Filename);\r
+void *PE_Relocate(void *Base, char **envp, const char *Filename);\r
char *PE_int_GetTrueFile(char *file);\r
- int PE_int_GetForwardSymbol(char *Fwd, Uint *Value);\r
+ int PE_int_GetForwardSymbol(char *Fwd, void **Value);\r
\r
// === CODE ===\r
-int PE_Relocate(void *Base, char *envp[], char *Filename)\r
+void *PE_Relocate(void *Base, char **envp, const char *Filename)\r
{\r
tPE_DOS_HEADER *dosHdr = Base;\r
tPE_IMAGE_HEADERS *peHeaders;\r
tPE_HINT_NAME *name;\r
Uint32 *importTab, *aIAT;\r
int i, j;\r
- Uint iBase = (Uint)Base;\r
- Uint iLibBase;\r
+ intptr_t iBase = (intptr_t)Base;\r
+ void *pLibBase;\r
\r
DEBUGS("PE_Relocate: (Base=0x%x)\n", Base);\r
\r
impDir[i].ImportLookupTable += iBase/4;\r
impDir[i].ImportAddressTable += iBase/4;\r
DEBUGS(" PE_Relocate: DLL Required '%s'(0x%x)\n", impDir[i].DLLName, impDir[i].DLLName);\r
- iLibBase = LoadLibrary(PE_int_GetTrueFile(impDir[i].DLLName), DLL_BASE_PATH, envp);\r
- if(iLibBase == 0) {\r
+ pLibBase = LoadLibrary(PE_int_GetTrueFile(impDir[i].DLLName), DLL_BASE_PATH, envp);\r
+ if(pLibBase == 0) {\r
SysDebug("Unable to load required library '%s'\n", impDir[i].DLLName);\r
return 0;\r
}\r
- DEBUGS(" PE_Relocate: Loaded as 0x%x\n", iLibBase);\r
+ DEBUGS(" PE_Relocate: Loaded as 0x%x\n", pLibBase);\r
importTab = impDir[i].ImportLookupTable;\r
aIAT = impDir[i].ImportAddressTable;\r
for( j = 0; importTab[j] != 0; j++ )\r
DEBUGS(" PE_Relocate: Import Ordinal %i\n", importTab[j] & 0x7FFFFFFF);\r
else\r
{\r
+ void *symPtr = 0;\r
name = (void*)( iBase + importTab[j] );\r
DEBUGS(" PE_Relocate: Import Name '%s', Hint 0x%x\n", name->Name, name->Hint);\r
- if( GetSymbolFromBase(iLibBase, name->Name, (Uint*)&aIAT[j]) == 0 ) {\r
+ if( GetSymbolFromBase(pLibBase, name->Name, symPtr, NULL) == 0 )\r
+ {\r
SysDebug("Unable to find symbol '%s' in library '%s'\n", name->Name, impDir[i].DLLName);\r
return 0;\r
}\r
+ aIAT[j] = (intptr_t)symPtr;\r
}\r
}\r
}\r
\r
DEBUGS("PE_Relocate: RETURN 0x%x\n", iBase + peHeaders->OptHeader.EntryPoint);\r
\r
- return iBase + peHeaders->OptHeader.EntryPoint;\r
+ return (void*)( iBase + peHeaders->OptHeader.EntryPoint );\r
}\r
\r
/**\r
- * \fn int PE_GetSymbol(Uint Base, char *Name, Uint *Ret)\r
+ * \fn int PE_GetSymbol(Uint Base, const char *Name, Uint *Ret)\r
*/\r
-int PE_GetSymbol(Uint Base, char *Name, Uint *Ret)\r
+int PE_GetSymbol(void *Base, const char *Name, void **Ret, size_t *Size)\r
{\r
- tPE_DOS_HEADER *dosHdr = (void*)Base;\r
+ tPE_DOS_HEADER *dosHdr = Base;\r
tPE_IMAGE_HEADERS *peHeaders;\r
tPE_DATA_DIR *directory;\r
tPE_EXPORT_DIR *expDir;\r
int i;\r
int symbolCount;\r
char *name;\r
- Uint retVal;\r
+ intptr_t retVal;\r
Uint expLen;\r
\r
peHeaders = (void*)( Base + dosHdr->PeHdrOffs );\r
//DEBUGS(" PE_GetSymbol: '%s' = 0x%x\n", name, Base + addrTable[ ordTable[i] ]);\r
if(strcmp(name, Name) == 0)\r
{\r
- retVal = Base + addrTable[ ordTable[i] ];\r
+ retVal = (intptr_t) Base + addrTable[ ordTable[i] ];\r
// Check for forwarding\r
- if((Uint)expDir < retVal && retVal < (Uint)expDir + expLen) {\r
+ if( (intptr_t)expDir < retVal && retVal < (intptr_t)expDir + expLen) {\r
char *fwd = (char*)retVal;\r
DEBUGS(" PE_GetSymbol: '%s' forwards to '%s'\n", name, fwd);\r
return PE_int_GetForwardSymbol(fwd, Ret);\r
}\r
- *Ret = retVal;\r
+ *Ret = (void*)retVal;\r
+ if(Size) *Size = 0;\r
return 1;\r
}\r
}\r
return &file[1];\r
}\r
\r
-int PE_int_GetForwardSymbol(char *Fwd, Uint *Value)\r
+int PE_int_GetForwardSymbol(char *Fwd, void **Value)\r
{\r
char *libname;\r
char *sym;\r
int i;\r
- Uint libbase;\r
+ void *libbase;\r
int ret;\r
\r
// -- Find seperator\r
DEBUGS(" PE_int_GetForwardSymbol: Get '%s' from '%s'\n", sym, libname);\r
\r
libbase = LoadLibrary(libname, DLL_BASE_PATH, NULL);\r
- ret = GetSymbolFromBase(libbase, sym, Value);\r
+ ret = GetSymbolFromBase(libbase, sym, Value, NULL);\r
if(!ret) {\r
SysDebug(" PE_int_GetForwardSymbol: Unable to find '%s' in '%s'\n", sym, libname);\r
+ return 0;\r
}\r
Fwd[i] = '.';\r
return ret;\r