Ticket #12736: dlltest.c

File dlltest.c, 807 bytes (added by underdoge, 5 years ago)

dlltest.c

Line 
1#include <Windows.h>
2#include <stdio.h>
3
4BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
5{
6        HMODULE hm = NULL;
7        CHAR String[512];
8        CHAR Username[260] = { 0 };
9        CHAR Filename[260] = { 0 };
10        CHAR DllName[260] = { 0 };
11        DWORD UsernameSize = sizeof(Username);
12        GetUserNameA(Username, &UsernameSize);
13        GetModuleFileNameA(NULL, Filename, sizeof(Filename));
14
15        if (fdwReason != DLL_PROCESS_ATTACH)
16                return TRUE;
17        if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
18                GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
19                (LPCSTR)&rdl,
20                &hm))
21                GetModuleFileNameA(hm, DllName, sizeof(DllName));       
22
23        _snprintf(String, sizeof(String), "HIJACKDLL (%s) Started from: %s as user %s\n", DllName, Filename, Username);
24        OutputDebugStringA(String);
25        return TRUE;
26}