InLoadOrderModuleList
InMemoryOrderModuleList
InInitializationOrderModuleList
LdrpHashTable
InMemoryOrderModuleList
InInitializationOrderModuleList
LdrpHashTable
Code: Select all
Done a million times before but may be useful.//===========================================================================
typedef struct _PEB_LDR_DATA
{
ULONG Length;
BOOLEAN Initialized;
PVOID SsHandle;
LIST_ENTRY InLoadOrderModuleList;
LIST_ENTRY InMemoryOrderModuleList;
LIST_ENTRY InInitializationOrderModuleList;
} PEB_LDR_DATA, *PPEB_LDR_DATA;
//===========================================================================
typedef struct _LDR_MODULE
{
LIST_ENTRY InLoadOrderModuleList;
LIST_ENTRY InMemoryOrderModuleList;
LIST_ENTRY InInitializationOrderModuleList;
PVOID BaseAddress;
PVOID EntryPoint;
ULONG SizeOfImage;
UNICODE_STRING FullDllName;
UNICODE_STRING BaseDllName;
ULONG Flags;
SHORT LoadCount;
SHORT TlsIndex;
LIST_ENTRY HashTableEntry;
ULONG TimeDateStamp;
} LDR_MODULE, *PLDR_MODULE;
//===========================================================================
void UnlinkModule(char *szModule)
{
DWORD dwPEB = 0, dwOffset = 0;
PLIST_ENTRY pUserModuleHead, pUserModule;
PPEB_LDR_DATA pLdrData;
PLDR_MODULE pLdrModule = NULL;
PUNICODE_STRING lpModule = NULL;
char szModuleName[512];
int i = 0, n = 0;
_asm
{
pushad
mov eax, fs: [48]
mov dwPEB, eax
popad
}
pLdrData=(PPEB_LDR_DATA)(PDWORD)(*(PDWORD)(dwPEB + 12));
for(; i < 3; i++)
{
switch(i)
{
case 0:
pUserModuleHead = pUserModule =(PLIST_ENTRY)(&(pLdrData->InLoadOrderModuleList));
dwOffset = 0;
break;
case 1:
pUserModuleHead = pUserModule =(PLIST_ENTRY)(&(pLdrData->InMemoryOrderModuleList));
dwOffset = 8;
break;
case 2:
pUserModuleHead = pUserModule =(PLIST_ENTRY)(&(pLdrData->InInitializationOrderModuleList));
dwOffset = 16;
break;
}
while(pUserModule->Flink != pUserModuleHead)
{
pUserModule = pUserModule->Flink;
lpModule =(PUNICODE_STRING)(((DWORD)(pUserModule)) +(36-dwOffset));
for(n = 0; n <(lpModule->Length)/2 && n < 512; n++)
szModuleName[n] =(CHAR)(*((lpModule->Buffer)+(n)));
szModuleName[n] = '\0';
if(strstr(szModuleName, szModule))
{
if (!pLdrModule)
pLdrModule = (PLDR_MODULE)(((DWORD)(pUserModule)) - dwOffset);
pUserModule->Blink->Flink = pUserModule->Flink;
pUserModule->Flink->Blink = pUserModule->Blink;
}
}
}
// Unlink from LdrpHashTable
if (pLdrModule)
{
pLdrModule->HashTableEntry.Blink->Flink = pLdrModule->HashTableEntry.Flink;
pLdrModule->HashTableEntry.Flink->Blink = pLdrModule->HashTableEntry.Blink;
}
}