Changeset View
Changeset View
Standalone View
Standalone View
source/lib/sysdep/os/win/wdll_delay_load.cpp
/* Copyright (C) 2013 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | extern "C" FARPROC WINAPI __delayLoadHelper2(PCImgDelayDescr pidd, FARPROC* ppfnIATEntry) | ||||
if (dli.dlp.fImportByName) | if (dli.dlp.fImportByName) | ||||
dli.dlp.szProcName = LPCSTR(PFromRva<PIMAGE_IMPORT_BY_NAME>(RVA(UINT_PTR(pitd->u1.AddressOfData)))->Name); | dli.dlp.szProcName = LPCSTR(PFromRva<PIMAGE_IMPORT_BY_NAME>(RVA(UINT_PTR(pitd->u1.AddressOfData)))->Name); | ||||
else | else | ||||
dli.dlp.dwOrdinal = DWORD(IMAGE_ORDINAL(pitd->u1.Ordinal)); | dli.dlp.dwOrdinal = DWORD(IMAGE_ORDINAL(pitd->u1.Ordinal)); | ||||
// Call the initial hook. If it exists and returns a function pointer, | // Call the initial hook. If it exists and returns a function pointer, | ||||
// abort the rest of the processing and just return it for the call. | // abort the rest of the processing and just return it for the call. | ||||
// | // | ||||
FARPROC pfnRet = NULL; | FARPROC pfnRet = nullptr; | ||||
if (__pfnDliNotifyHook2) { | if (__pfnDliNotifyHook2) { | ||||
pfnRet = ((*__pfnDliNotifyHook2)(dliStartProcessing, &dli)); | pfnRet = ((*__pfnDliNotifyHook2)(dliStartProcessing, &dli)); | ||||
if (pfnRet != NULL) | if (pfnRet != nullptr) | ||||
goto HookBypass; | goto HookBypass; | ||||
} | } | ||||
// Check to see if we need to try to load the library. | // Check to see if we need to try to load the library. | ||||
// | // | ||||
if (hmod == 0) { | if (hmod == 0) { | ||||
if (__pfnDliNotifyHook2) { | if (__pfnDliNotifyHook2) { | ||||
hmod = HMODULE(((*__pfnDliNotifyHook2)(dliNotePreLoadLibrary, &dli))); | hmod = HMODULE(((*__pfnDliNotifyHook2)(dliNotePreLoadLibrary, &dli))); | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | if(pui->pidd->rvaUnloadIAT) | ||||
HMODULE* phmod = PFromRva<HMODULE*>(pidd->rvaHmod); | HMODULE* phmod = PFromRva<HMODULE*>(pidd->rvaHmod); | ||||
HMODULE hmod = *phmod; | HMODULE hmod = *phmod; | ||||
OverlayIAT( | OverlayIAT( | ||||
PFromRva<PImgThunkData>(pidd->rvaIAT), | PFromRva<PImgThunkData>(pidd->rvaIAT), | ||||
PFromRva<PCImgThunkData>(pidd->rvaUnloadIAT) | PFromRva<PCImgThunkData>(pidd->rvaUnloadIAT) | ||||
); | ); | ||||
::FreeLibrary(hmod); | ::FreeLibrary(hmod); | ||||
*phmod = NULL; | *phmod = nullptr; | ||||
delete (ULI*)pui; // changes __puiHead! | delete (ULI*)pui; // changes __puiHead! | ||||
} | } | ||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
static Status wdll_Shutdown() | static Status wdll_Shutdown() | ||||
{ | { | ||||
UnloadAllDlls(); | UnloadAllDlls(); | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } |
Wildfire Games · Phabricator