-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject.cpp
More file actions
40 lines (32 loc) · 1.54 KB
/
Copy pathinject.cpp
File metadata and controls
40 lines (32 loc) · 1.54 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
// Injector: asks XAML Diagnostics to load our TAP DLL into the process that owns
// the taskbar. Windows does the loading; we never touch remote memory ourselves.
#include <windows.h>
#include <xamlom.h>
#include <cstdio>
// Must match tap.cpp
// {6D5F7B21-3C8A-44E1-9E2B-7A1F4C905E10}
static const CLSID CLSID_TaskbarTap =
{ 0x6d5f7b21, 0x3c8a, 0x44e1, { 0x9e, 0x2b, 0x7a, 0x1f, 0x4c, 0x90, 0x5e, 0x10 } };
typedef HRESULT (WINAPI *PFN_InitializeXamlDiagnosticsEx)(
LPCWSTR endPointName, DWORD pid, LPCWSTR wszDllXamlDiagnostics,
LPCWSTR wszTAPDllName, CLSID tapClsid, LPCWSTR wszInitializationData);
int wmain(int argc, wchar_t** argv)
{
if (argc < 2) {
wprintf(L"usage: inject.exe <full path to tap.dll>\n");
return 1;
}
const wchar_t* tapPath = argv[1];
HWND tray = FindWindowW(L"Shell_TrayWnd", nullptr);
if (!tray) { wprintf(L"Shell_TrayWnd not found\n"); return 2; }
DWORD pid = 0;
GetWindowThreadProcessId(tray, &pid);
wprintf(L"taskbar pid = %lu\n", pid);
HMODULE xaml = LoadLibraryW(L"Windows.UI.Xaml.dll");
if (!xaml) { wprintf(L"LoadLibrary Windows.UI.Xaml.dll failed %lu\n", GetLastError()); return 3; }
auto fn = (PFN_InitializeXamlDiagnosticsEx)GetProcAddress(xaml, "InitializeXamlDiagnosticsEx");
if (!fn) { wprintf(L"InitializeXamlDiagnosticsEx not exported\n"); return 4; }
HRESULT hr = fn(L"VisualDiagConnection1", pid, nullptr, tapPath, CLSID_TaskbarTap, nullptr);
wprintf(L"InitializeXamlDiagnosticsEx hr = 0x%08X\n", hr);
return SUCCEEDED(hr) ? 0 : 5;
}