以下是如何在Windows 8 / Server 2012及更高版本中重现加载器锁定挂起的方法。请注意,此代码并非直接调用load library,而是使用触发Load Library调用的Windows API。
创建一个Visual Studio C++ DLL项目,并在DLL主函数中使用此代码:
#define WIN32_LEAN_AND_MEAN
#include "framework.h"
#include <windows.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <ws2tcpip.h>
#include <stdio.h>
#pragma comment(lib, "IPHLPAPI.lib")
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
#pragma comment(lib, "ws2_32.lib")
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
printf("WSAStartup failed with error: %d\n", err);
return 1;
}
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
printf("Could not find a usable version of Winsock.dll\n");
WSACleanup();
return 1;
}
else
printf("The Winsock 2.2 dll was found okay\n");
FIXED_INFO* pFixedInfo;
ULONG ulOutBufLen;
DWORD dwRetVal;
IP_ADDR_STRING* pIPAddr;
pFixedInfo = (FIXED_INFO*)MALLOC(sizeof(FIXED_INFO));
if (pFixedInfo == NULL) {
printf("Error allocating memory needed to call GetNetworkParams\n");
return 1;
}
ulOutBufLen = sizeof(FIXED_INFO);
if (GetNetworkParams(pFixedInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
FREE(pFixedInfo);
pFixedInfo = (FIXED_INFO*)MALLOC(ulOutBufLen);
if (pFixedInfo == NULL) {
printf("Error allocating memory needed to call GetNetworkParams\n");
return 1;
}
}
if (dwRetVal = GetNetworkParams(pFixedInfo, &ulOutBufLen) == NO_ERROR) {
printf("Host Name: %s\n", pFixedInfo->HostName);
printf("Domain Name: %s\n", pFixedInfo->DomainName);
printf("DNS Servers:\n");
printf("\t%s\n", pFixedInfo->DnsServerList.IpAddress.String);
pIPAddr = pFixedInfo->DnsServerList.Next;
while (pIPAddr) {
printf("\t%s\n", pIPAddr->IpAddress.String);
pIPAddr = pIPAddr->Next;
}
printf("Node Type: ");
switch (pFixedInfo->NodeType) {
case BROADCAST_NODETYPE:
printf("Broadcast node\n");
break;
case PEER_TO_PEER_NODETYPE:
printf("Peer to Peer node\n");
break;
case MIXED_NODETYPE:
printf("Mixed node\n");
break;
case HYBRID_NODETYPE:
printf("Hybrid node\n");
break;
default:
printf("Unknown node type %0lx\n", pFixedInfo->NodeType);
break;
}
printf("DHCP scope name: %s\n", pFixedInfo->ScopeId);
if (pFixedInfo->EnableRouting)
printf("Routing: enabled\n");
else
printf("Routing: disabled\n");
if (pFixedInfo->EnableProxy)
printf("ARP proxy: enabled\n");
else
printf("ARP Proxy: disabled\n");
if (pFixedInfo->EnableDns)
printf("DNS: enabled\n");
else
printf("DNS: disabled\n");
}
else {
printf("GetNetworkParams failed with error: %d\n", dwRetVal);
return 1;
}
if (pFixedInfo)
FREE(pFixedInfo);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
从第二个应用程序(尚未导入任何网络API或调用任何网络函数)创建一个控制台桌面C++应用程序,其中包含以下代码:
HMODULE hModule
hModule = LoadLibrary(L"<specify DLL created in previous example>")