-
Notifications
You must be signed in to change notification settings - Fork 5
/
utilities.cpp
148 lines (118 loc) · 4.12 KB
/
utilities.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "utilities.h"
HRESULT CreateProperty(IDataModelManager* pManager,
IModelPropertyAccessor* pProperty,
IModelObject** ppPropertyObject) {
*ppPropertyObject = nullptr;
VARIANT vtVal;
vtVal.vt = VT_UNKNOWN;
vtVal.punkVal = pProperty;
HRESULT hr = pManager->CreateIntrinsicObject(ObjectPropertyAccessor, &vtVal,
ppPropertyObject);
return hr;
}
HRESULT CreateULong64(ULONG64 value, IModelObject** ppInt) {
HRESULT hr = S_OK;
*ppInt = nullptr;
VARIANT vtVal;
vtVal.vt = VT_UI8;
vtVal.ullVal = value;
hr =
spDataModelManager->CreateIntrinsicObject(ObjectIntrinsic, &vtVal, ppInt);
return hr;
}
HRESULT CreateInt32(int value, IModelObject** ppInt) {
HRESULT hr = S_OK;
*ppInt = nullptr;
VARIANT vtVal;
vtVal.vt = VT_I4;
vtVal.intVal = value;
hr =
spDataModelManager->CreateIntrinsicObject(ObjectIntrinsic, &vtVal, ppInt);
return hr;
}
HRESULT CreateUInt32(uint32_t value, IModelObject** ppInt) {
HRESULT hr = S_OK;
*ppInt = nullptr;
VARIANT vtVal;
vtVal.vt = VT_UI4;
vtVal.uintVal = value;
hr =
spDataModelManager->CreateIntrinsicObject(ObjectIntrinsic, &vtVal, ppInt);
return hr;
}
HRESULT CreateBool(bool value, IModelObject** ppVal) {
HRESULT hr = S_OK;
*ppVal = nullptr;
VARIANT vtVal;
vtVal.vt = VT_BOOL;
vtVal.boolVal = value;
hr =
spDataModelManager->CreateIntrinsicObject(ObjectIntrinsic, &vtVal, ppVal);
return hr;
}
HRESULT CreateNumber(double value, IModelObject** ppVal) {
HRESULT hr = S_OK;
*ppVal = nullptr;
VARIANT vtVal;
vtVal.vt = VT_R8;
vtVal.dblVal = value;
hr =
spDataModelManager->CreateIntrinsicObject(ObjectIntrinsic, &vtVal, ppVal);
return hr;
}
HRESULT CreateString(std::u16string value, IModelObject** ppVal) {
HRESULT hr = S_OK;
*ppVal = nullptr;
VARIANT vtVal;
vtVal.vt = VT_BSTR;
vtVal.bstrVal =
::SysAllocString(reinterpret_cast<const OLECHAR*>(value.c_str()));
hr =
spDataModelManager->CreateIntrinsicObject(ObjectIntrinsic, &vtVal, ppVal);
return hr;
}
bool GetModelAtIndex(winrt::com_ptr<IModelObject>& spParent,
winrt::com_ptr<IModelObject>& spIndex,
IModelObject** pResult) {
winrt::com_ptr<IIndexableConcept> spIndexableConcept;
HRESULT hr = spParent->GetConcept(
__uuidof(IIndexableConcept),
reinterpret_cast<IUnknown**>(spIndexableConcept.put()), nullptr);
if (FAILED(hr)) return false;
std::vector<IModelObject*> pIndexers{spIndex.get()};
hr = spIndexableConcept->GetAt(spParent.get(), 1, pIndexers.data(), pResult,
nullptr);
return SUCCEEDED(hr);
}
bool GetCurrentThread(winrt::com_ptr<IDebugHostContext>& spHostContext,
IModelObject** pCurrentThread) {
HRESULT hr = S_OK;
winrt::com_ptr<IModelObject> spBoxedContext, spRootNamespace;
winrt::com_ptr<IModelObject> spDebugger, spSessions, spProcesses, spThreads;
winrt::com_ptr<IModelObject> spCurrSession, spCurrProcess, spCurrThread;
// Get the current context boxed as an IModelObject
VARIANT vtContext;
vtContext.vt = VT_UNKNOWN;
vtContext.punkVal = spHostContext.get();
hr = spDataModelManager->CreateIntrinsicObject(ObjectContext, &vtContext,
spBoxedContext.put());
if (FAILED(hr)) return false;
hr = spDataModelManager->GetRootNamespace(spRootNamespace.put());
if (FAILED(hr)) return false;
hr = spRootNamespace->GetKeyValue(L"Debugger", spDebugger.put(), nullptr);
if (FAILED(hr)) return false;
hr = spDebugger->GetKeyValue(L"Sessions", spSessions.put(), nullptr);
if (!GetModelAtIndex(spSessions, spBoxedContext, spCurrSession.put())) {
return false;
}
hr = spCurrSession->GetKeyValue(L"Processes", spProcesses.put(), nullptr);
if (!GetModelAtIndex(spProcesses, spBoxedContext, spCurrProcess.put())) {
return false;
}
hr = spCurrProcess->GetKeyValue(L"Threads", spThreads.put(), nullptr);
if (!GetModelAtIndex(spThreads, spBoxedContext, spCurrThread.put())) {
return false;
}
*pCurrentThread = spCurrThread.detach();
return true;
}