从前面可以看到GDI32的初始化函数是调用GdiDllInitialize函数来初始化,下面就来分析这个初始化的具体实现,代码如下:
#001 BOOL
#002 WINAPI
#003 GdiDllInitialize (
#004 HANDLE hDll,
#005 DWORD dwReason,
#006 LPVOID lpReserved)
#007 {
根据不同的调用原因进行初始化。
#008 switch (dwReason)
#009 {
当进程需要绑定到本DLL时调用,就调用函数GdiProcessSetup来进行本进程的初始化动作。
#010 case DLL_PROCESS_ATTACH:
#011 GdiProcessSetup ();
#012 break;
#013
当线程需要绑定到本DLL时调用。
#014 case DLL_THREAD_ATTACH:
#015 NtCurrentTeb()->GdiTebBatch.Offset = 0;
#016 NtCurrentTeb()->GdiBatchCount = 0;
#017 break;
#018
#019 default:
#020 return FALSE;
#021 }
#022
判断是否需要清空对象。
#023 // Very simple,the list will fill itself as it is needed.
#024 if(!SetStockObjects)
#025 {
清空所有对象。
#026 RtlZeroMemory( &stock_objects,NB_STOCK_OBJECTS); //Assume Ros is dirty.
设置已经清空对象。
#027 SetStockObjects = TRUE;
#028 }
#029
#030 return TRUE;
#031 }
下面接着来分析函数GdiProcessSetup,这个函数主要把当前线程环境块的句柄表映射到用户空间。
#001 VOID
#002 WINAPI
#003 GdiProcessSetup (VOID)
#004 {
获取当前进程的堆空间。
#005 hProcessHeap = GetProcessHeap();
#006
映射GDI的句柄表到用户空间。
#007 /* map the gdi handle table to user space */
#008 GdiHandleTable = NtCurrentTeb()->ProcessEnvironmentBlock->GdiSharedHandleTable;
#009 GdiSharedHandleTable = NtCurrentTeb()->ProcessEnvironmentBlock->GdiSharedHandleTable;
当前GDI设备的兼容性。
#010 GdiDevCaps = &GdiSharedHandleTable->DevCaps;
当前进程的标识号。
#011 CurrentProcessId = NtCurrentTeb()->ClientId.UniqueProcess;
#012 GDI_BatchLimit = (DWORD) NtCurrentTeb()->ProcessEnvironmentBlock->GdiDCAttributeList;
#013 GdiHandleCache = (PGDIHANDLECACHE)NtCurrentTeb()->ProcessEnvironmentBlock->GdiHandleBuffer;
#014}
原文链接:https://www.f2er.com/react/308367.html