MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / DllMain

Function DllMain

ProcMon/dllmain.cpp:10–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10BOOL APIENTRY DllMain( HMODULE hModule,
11 DWORD ul_reason_for_call,
12 LPVOID lpReserved
13 )
14{
15 switch (ul_reason_for_call)
16 {
17 case DLL_PROCESS_ATTACH:
18 {
19 PTEB pTEB = GetTeb();
20 PPEB pPEB = GetPeb(pTEB);
21
22 // Get current PID
23 CLIENT_ID* pCID = (CLIENT_ID*)((BYTE*)pTEB + sizeof(NT_TIB) + sizeof(void*));
24 ULONG uiPID = (ULONG)(ULONG_PTR)pCID->UniqueProcess;
25
26 // Get current time
27 LARGE_INTEGER liSt = {};
28 NtQuerySystemTime(&liSt);
29 RtlSystemTimeToLocalTime(&liSt, &liSt);
30 TIME_FIELDS tfSt = {};
31 RtlTimeToTimeFields(&liSt, &tfSt);
32
33 //We can't use SEH!
34 if (pPEB->ProcessParameters)
35 {
36 //Simply output where we ran from
37 LogToFileFmt("%04u-%02u-%02u %02u:%02u:%02u.%03u > PID=%u: \"%wZ\"\n"
38 ,
39 tfSt.Year, tfSt.Month, tfSt.Day, tfSt.Hour, tfSt.Minute, tfSt.Second, tfSt.Milliseconds,
40 uiPID, &pPEB->ProcessParameters->ImagePathName
41 );
42 }
43 else
44 {
45 //No path
46 LogToFileFmt("%04u-%02u-%02u %02u:%02u:%02u.%03u > PID=%u: no path\n"
47 ,
48 tfSt.Year, tfSt.Month, tfSt.Day, tfSt.Hour, tfSt.Minute, tfSt.Second, tfSt.Milliseconds,
49 uiPID
50 );
51 }
52 break;
53 }
54 case DLL_THREAD_ATTACH:
55 case DLL_THREAD_DETACH:
56 case DLL_PROCESS_DETACH:
57 break;
58 }
59 return TRUE;
60}
61
62NTSTATUS LogToFile(const char* pOutput,LPCTSTR pFile) {
63 NTSTATUS status = STATUS_INVALID_PARAMETER;

Callers

nothing calls this directly

Calls 3

GetTebFunction · 0.85
GetPebFunction · 0.85
LogToFileFmtFunction · 0.85

Tested by

no test coverage detected