A forum for reverse engineering, OS internals and malware analysis 

Ask your beginner questions here.
 #17573  by Buster_BSA
 Thu Jan 03, 2013 9:14 pm
The DllMain function is an optional entry point into a dynamic-link library (DLL).

Is possible to know if a DLL contains a DllMain function? If yes, what methods can be used to detect DllMain´s presence or absence?
 #17577  by EP_X0FF
 Fri Jan 04, 2013 3:28 am
OptionalHeader->AddressOfEntryPoint
 #17579  by Buster_BSA
 Fri Jan 04, 2013 9:14 am
Attached there are 2 DLLs.

Could you explain how to know what of them has DllMain, please?

I checked OptionalHeader->AddressOfEntryPoint but I was not able to figure out anything that may help me to know if the DLL has DllMain or not.
Attachments
Password: infected
(437.46 KiB) Downloaded 24 times
 #17586  by EP_X0FF
 Fri Jan 04, 2013 11:06 am
AddressOfEntryPoint is the address from where code being executed. There is no difference how it named in sources "DllMain", "MegaCode" or "WhatEverShit".

DLLMAIN.DLL - is x86 DLL with EntryPoint set as 0041E084, here is "DllMain"
NODLLMAIN.DLL - is x86 EXE with EntryPoint set as 0040DD16, here is "main".
Code: Select all
LPVOID WINAPI PELoaderGetEntryPoint(
	LPVOID ImageBase
	)
{
	PIMAGE_DOS_HEADER			pdosh;
	PIMAGE_FILE_HEADER			pfh1;
	PIMAGE_OPTIONAL_HEADER32	poh32;
	PIMAGE_OPTIONAL_HEADER64	poh64;
	LPVOID						EntryPoint = NULL;

	__try {

		pdosh = (PIMAGE_DOS_HEADER)ImageBase;
		pfh1 = (PIMAGE_FILE_HEADER)((ULONG_PTR)ImageBase + (pdosh->e_lfanew + sizeof(DWORD)));
		poh32 = (PIMAGE_OPTIONAL_HEADER32)((ULONG_PTR)pfh1 + sizeof(IMAGE_FILE_HEADER));
		poh64 = (PIMAGE_OPTIONAL_HEADER64)poh32;

		EntryPoint = (pfh1->Machine == IMAGE_FILE_MACHINE_AMD64) ?
			(LPVOID)(poh64->AddressOfEntryPoint + (ULONG_PTR)ImageBase) : 
			(LPVOID)(poh32->AddressOfEntryPoint + (ULONG_PTR)ImageBase);

	} __except (EXCEPTION_EXECUTE_HANDLER) {

#ifdef PELDRDBG
		LdrOutputDebugString(TEXT("PELoader: GetEntryPoint failed\n"));
#endif
	}

	return EntryPoint;
}