Merge pull request #5 from rad9800/main

Create RfRemoveDllFromPeb.cpp
This commit is contained in:
vxunderground 2022-07-21 23:52:00 -05:00 committed by GitHub
commit d63e92f32d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,78 @@
void RfRemoveEntryList(LIST_ENTRY* Entry)
{
if (Entry != NULL) {
PLIST_ENTRY OldFlink;
PLIST_ENTRY OldBlink;
OldFlink = Entry->Flink;
OldBlink = Entry->Blink;
OldFlink->Blink = OldBlink;
OldBlink->Flink = OldFlink;
Entry->Flink = NULL;
Entry->Blink = NULL;
}
}
BOOL RfRemoveDllFromPebW(LPCWSTR lpModuleName) {
PPEB Peb = GetPeb();
PLDR_MODULE Module = NULL;
PLIST_ENTRY Head = &Peb->LoaderData->InMemoryOrderModuleList;
PLIST_ENTRY Next = Head->Flink;
Module = (PLDR_MODULE)((PBYTE)Next - 16);
while (Next != Head)
{
Module = (PLDR_MODULE)((PBYTE)Next - 16);
if (Module->BaseDllName.Buffer != NULL)
{
if (StringCompareW(lpModuleName, Module->BaseDllName.Buffer) == 0)
{
RemoveEntryList(&Module->InLoadOrderModuleList);
RemoveEntryList(&Module->InInitializationOrderModuleList);
RemoveEntryList(&Module->InMemoryOrderModuleList);
RemoveEntryList(&Module->HashTableEntry);
return TRUE;
}
}
Next = Next->Flink;
}
return FALSE;
}
BOOL RfRemoveDllFromPebA(LPCSTR lpModuleName) {
PPEB Peb = GetPeb();
PLDR_MODULE Module = NULL;
CHAR wDllName[64] = { 0 };
PLIST_ENTRY Head = &Peb->LoaderData->InMemoryOrderModuleList;
PLIST_ENTRY Next = Head->Flink;
Module = (PLDR_MODULE)((PBYTE)Next - 16);
while (Next != Head)
{
Module = (PLDR_MODULE)((PBYTE)Next - 16);
if (Module->BaseDllName.Buffer != NULL)
{
RfZeroMemory(wDllName, sizeof(wDllName));
WCharStringToCharString(wDllName, Module->BaseDllName.Buffer, 64);
if (StringCompareA(lpModuleName, Module->BaseDllName.Buffer) == 0)
{
RemoveEntryList(&Module->InLoadOrderModuleList);
RemoveEntryList(&Module->InInitializationOrderModuleList);
RemoveEntryList(&Module->InMemoryOrderModuleList);
RemoveEntryList(&Module->HashTableEntry);
return TRUE;
}
}
Next = Next->Flink;
}
return FALSE;
}