-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdllmain.cpp
More file actions
80 lines (70 loc) · 2.22 KB
/
Copy pathdllmain.cpp
File metadata and controls
80 lines (70 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @file dllmain.cpp
* @date 01-10-2020
* @author Paul Laine (@am0nsec)
* @version 1.0
* @brief Windows module entry point.
* @details
* @link https://github.com/am0nsec/DynamicWrapperEx
* @copyright This project has been released under the GNU Public License v3 license.
*/
#include <windows.h>
#include <memory>
#include "CDynamicWrapperEx.hpp"
/**
* @brief Dynamic-Link Library entry point.
* @param hModule The address of the module in memory.
* @param dwReasonToCall Notification.
* @param lpReserved Reserved.
* @return Whether the function executed successfully.
*/
BOOL STDMETHODCALLTYPE DllMain(
_In_ HMODULE hModule,
_In_ DWORD dwReasonForCall,
_In_ LPVOID lpReserved
) {
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(lpReserved);
// Disables the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications
if (dwReasonForCall == DLL_PROCESS_ATTACH)
::DisableThreadLibraryCalls(hModule);
return TRUE;
}
/**
* @brief Check if the module can be unloaded.
* @return Whether the module can be unloaded.
*/
HRESULT STDMETHODCALLTYPE DllCanUnloadNow(VOID) {
return S_OK;
}
/**
* @brief Register the COM server into the Windows Registry.
* @return Whether the COM server has been successfully registered.
*/
HRESULT STDMETHODCALLTYPE DllRegisterServer(VOID) {
return S_OK;
}
/**
* @brief Unregister the COM server into the Windows Registry.
* @return Whether the COM server has been successfully unregistered.
*/
HRESULT STDMETHODCALLTYPE DllUnregisterServer(VOID) {
return S_OK;
}
/**
* @brief Get a COM class factory to create a COM object.
* @param rclsid GUID of the COM class factory.
* @param riid GUID of the COM server interface.
* @param ppv Address of the COM object.
* @return Whether the COM object has been successfully created.
*/
HRESULT STDMETHODCALLTYPE DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
if (!IsEqualGUID(rclsid, CLSID_CDynamicWrapperEx))
return CLASS_E_CLASSNOTAVAILABLE;
CDynamicWrapperEx* pClassFactory = new CDynamicWrapperEx;
if (pClassFactory == nullptr)
return E_OUTOFMEMORY;
HRESULT hr = pClassFactory->QueryInterface(riid, ppv);
pClassFactory->Release();
return hr;
}