mirror of
https://github.com/reactos/reactos.git
synced 2025-06-28 18:09:44 +00:00
Create a branch for header work.
svn path=/branches/header-work/; revision=45691
This commit is contained in:
parent
14fe274b1c
commit
9ea495ba33
19538 changed files with 0 additions and 1063950 deletions
100
lib/sdk/delayimp/delayimp.c
Normal file
100
lib/sdk/delayimp/delayimp.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* PROJECT: ReactOS SDK Library
|
||||
* LICENSE: LGPL, see LGPL.txt in top level directory.
|
||||
* FILE: lib/sdk/delayimp/delayimp.c
|
||||
* PURPOSE: Library for delay importing from dlls
|
||||
* PROGRAMMERS: Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <delayimp.h>
|
||||
|
||||
/**** load helper ****/
|
||||
|
||||
FARPROC WINAPI
|
||||
__delayLoadHelper2(PCImgDelayDescr pidd, PImgThunkData pIATEntry)
|
||||
{
|
||||
DelayLoadInfo dli;
|
||||
int index;
|
||||
PImgThunkData pIAT;
|
||||
PImgThunkData pINT;
|
||||
HMODULE *phMod;
|
||||
FARPROC pProc;
|
||||
|
||||
pIAT = PFromRva(pidd->rvaIAT);
|
||||
pINT = PFromRva(pidd->rvaINT);
|
||||
phMod = PFromRva(pidd->rvaHmod);
|
||||
index = IndexFromPImgThunkData(pIATEntry, pIAT);
|
||||
|
||||
dli.cb = sizeof(dli);
|
||||
dli.pidd = pidd;
|
||||
dli.ppfn = (FARPROC*)pIATEntry->u1.Function;
|
||||
dli.szDll = PFromRva(pidd->rvaDLLName);
|
||||
dli.dlp.fImportByName = !(pINT[index].u1.Ordinal & IMAGE_ORDINAL_FLAG);
|
||||
if (dli.dlp.fImportByName)
|
||||
{
|
||||
/* u1.AdressOfData points to a IMAGE_IMPORT_BY_NAME struct */
|
||||
PIMAGE_IMPORT_BY_NAME piibn = PFromRva((RVA)pINT[index].u1.AddressOfData);
|
||||
dli.dlp.szProcName = (LPCSTR)&piibn->Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
dli.dlp.dwOrdinal = pINT[index].u1.Ordinal & ~IMAGE_ORDINAL_FLAG;
|
||||
}
|
||||
dli.hmodCur = *phMod;
|
||||
dli.pfnCur = (FARPROC)pIAT[index].u1.Function;
|
||||
dli.dwLastError = GetLastError();
|
||||
pProc = __pfnDliNotifyHook2(dliStartProcessing, &dli);
|
||||
if (pProc)
|
||||
{
|
||||
pIAT[index].u1.Function = (DWORD_PTR)pProc;
|
||||
return pProc;
|
||||
}
|
||||
|
||||
if (dli.hmodCur == NULL)
|
||||
{
|
||||
dli.hmodCur = LoadLibraryA(dli.szDll);
|
||||
if (!dli.hmodCur)
|
||||
{
|
||||
dli.dwLastError = GetLastError();
|
||||
__pfnDliFailureHook2(dliFailLoadLib, &dli);
|
||||
// if (ret)
|
||||
// {
|
||||
// }
|
||||
// FIXME: raise exception;
|
||||
return NULL;
|
||||
}
|
||||
*phMod = dli.hmodCur;
|
||||
}
|
||||
|
||||
/* dli.dlp.szProcName might also contain the ordinal */
|
||||
pProc = GetProcAddress(dli.hmodCur, dli.dlp.szProcName);
|
||||
if (!pProc)
|
||||
{
|
||||
dli.dwLastError = GetLastError();
|
||||
__pfnDliFailureHook2(dliFailGetProc, &dli);
|
||||
// FIXME: handle return value & raise exception
|
||||
return NULL;
|
||||
}
|
||||
pIAT[index].u1.Function = (DWORD_PTR)pProc;
|
||||
|
||||
return pProc;
|
||||
}
|
||||
|
||||
/*** The default hooks ***/
|
||||
|
||||
FARPROC WINAPI
|
||||
DefaultDliNotifyHook2(unsigned dliNotify, PDelayLoadInfo pdli)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FARPROC WINAPI
|
||||
DefaultDliFailureHook2(unsigned dliNotify, PDelayLoadInfo pdli)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PfnDliHook __pfnDliNotifyHook2 = DefaultDliNotifyHook2;
|
||||
PfnDliHook __pfnDliFailureHook2 = DefaultDliFailureHook2;
|
Loading…
Add table
Add a link
Reference in a new issue