1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2015 |
---|
3 | // Created by Roman Ryltsov roman@alax.info, http://alax.info |
---|
4 | // |
---|
5 | // This source code is published to complement DirectShowSpy developer powertoy |
---|
6 | // and demonstrate the internal use of APIs and tricks powering the tool. It is |
---|
7 | // allowed to freely re-use the portions of the code in other projects, commercial |
---|
8 | // or otherwise (provided that you dont pretend that you wrote the original tool). |
---|
9 | // |
---|
10 | // Please keep in mind that DirectShowSpy is a developer tool, it is strongly recommended |
---|
11 | // that it is not shipped with release grade software. It is allowed to distribute |
---|
12 | // DirectShowSpy if only it is not registered with Windows by default and either |
---|
13 | // used privately, or registered on specific throubleshooting request. The advice applies |
---|
14 | // to hooking methods used by DirectShowSpy in general as well. |
---|
15 | |
---|
16 | #include "stdafx.h" |
---|
17 | #include <dshow.h> |
---|
18 | #include "resource.h" |
---|
19 | #include "Common.h" |
---|
20 | #include "Configuration.h" |
---|
21 | |
---|
22 | //////////////////////////////////////////////////////////// |
---|
23 | // UnregisterTreatAsClasses |
---|
24 | |
---|
25 | #if defined(_WIN64) |
---|
26 | extern "C" __declspec(dllexport) |
---|
27 | #else |
---|
28 | #pragma comment(linker, "/EXPORT:UnregisterTreatAsClasses=_UnregisterTreatAsClasses@0,PRIVATE") |
---|
29 | extern "C" // __declspec(dllexport) |
---|
30 | #endif // defined(_WIN64) |
---|
31 | |
---|
32 | HRESULT STDMETHODCALLTYPE UnregisterTreatAsClasses() throw() |
---|
33 | { |
---|
34 | _ATLTRY |
---|
35 | { |
---|
36 | static const CLSID* g_ppClassIdentifiers[] = |
---|
37 | { |
---|
38 | &CLSID_FilterMapper2, // CFilterMapperSpy |
---|
39 | &CLSID_SystemDeviceEnum, // CLSID_SystemDeviceEnumeratorSpy |
---|
40 | &CLSID_FilterGraph, // CLSID_Spy |
---|
41 | &CLSID_FilterGraphNoThread, // CLSID_NoThreadSpy |
---|
42 | }; |
---|
43 | const ULONG nOsVersion = GetOsVersion(); |
---|
44 | _Z4(atlTraceGeneral, 4, _T("nOsVersion 0x%08x\n"), nOsVersion); |
---|
45 | CProcessTokenPrivileges ProcessTokenPrivileges; |
---|
46 | BOOL bProcessTokenPrivilegesAdjustNeeded = TRUE; |
---|
47 | for(SIZE_T nIndex = 0; nIndex < DIM(g_ppClassIdentifiers); nIndex++) |
---|
48 | { |
---|
49 | const CLSID& ClassIdentifier = *g_ppClassIdentifiers[nIndex]; |
---|
50 | _Z4(atlTraceGeneral, 4, _T("nIndex %d, ClassIdentifier %ls\n"), nIndex, _PersistHelper::StringFromIdentifier(ClassIdentifier)); |
---|
51 | _ATLTRY |
---|
52 | { |
---|
53 | CLSID CurrentTreatAsClassIdentifier = CLSID_NULL; |
---|
54 | const HRESULT nCoGetTreatAsClassResult = CoGetTreatAsClass(ClassIdentifier, &CurrentTreatAsClassIdentifier); |
---|
55 | _Z4_HRESULT(nCoGetTreatAsClassResult); |
---|
56 | __C(nCoGetTreatAsClassResult); |
---|
57 | if(nCoGetTreatAsClassResult != S_OK) |
---|
58 | continue; |
---|
59 | _Z4(atlTraceGeneral, 4, _T("CurrentTreatAsClassIdentifier %ls\n"), _PersistHelper::StringFromIdentifier(CurrentTreatAsClassIdentifier)); |
---|
60 | #pragma region Adjust |
---|
61 | if(bProcessTokenPrivilegesAdjustNeeded) |
---|
62 | { |
---|
63 | bProcessTokenPrivilegesAdjustNeeded = FALSE; |
---|
64 | if(nOsVersion >= 0x060000) // Win Vista+ |
---|
65 | _ATLTRY |
---|
66 | { |
---|
67 | ProcessTokenPrivileges.Adjust(); |
---|
68 | } |
---|
69 | _ATLCATCHALL() |
---|
70 | { |
---|
71 | _Z_EXCEPTION(); |
---|
72 | } |
---|
73 | } |
---|
74 | #pragma endregion |
---|
75 | CClassIdentifierRegKeySecurity ClassIdentifierRegKeySecurity(ClassIdentifier); |
---|
76 | if(nOsVersion >= 0x060000) // Win Vista+ |
---|
77 | ClassIdentifierRegKeySecurity.Adjust(); |
---|
78 | const HRESULT nCoTreatAsClassResult = CoTreatAsClass(ClassIdentifier, CLSID_NULL); |
---|
79 | _Z4_HRESULT(nCoTreatAsClassResult); |
---|
80 | __C(nCoTreatAsClassResult); |
---|
81 | } |
---|
82 | _ATLCATCHALL() |
---|
83 | { |
---|
84 | _Z_EXCEPTION(); |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | _ATLCATCH(Exception) |
---|
89 | { |
---|
90 | _C(Exception); |
---|
91 | } |
---|
92 | return S_OK; |
---|
93 | } |
---|
94 | |
---|
95 | //////////////////////////////////////////////////////////// |
---|
96 | // DoRegistrationPropertySheetModal |
---|
97 | |
---|
98 | #if defined(_WIN64) |
---|
99 | extern "C" __declspec(dllexport) |
---|
100 | #else |
---|
101 | #pragma comment(linker, "/EXPORT:DoRegistrationPropertySheetModal=_DoRegistrationPropertySheetModal@0,PRIVATE") |
---|
102 | extern "C" // __declspec(dllexport) |
---|
103 | #endif // defined(_WIN64) |
---|
104 | |
---|
105 | HRESULT STDMETHODCALLTYPE DoRegistrationPropertySheetModal() throw() |
---|
106 | { |
---|
107 | _ATLTRY |
---|
108 | { |
---|
109 | CSingleThreadedApartment SingleThreadedApartment; |
---|
110 | _W(AtlInitCommonControls(ICC_WIN95_CLASSES | ICC_COOL_CLASSES | ICC_STANDARD_CLASSES)); |
---|
111 | CRegistrationPropertySheet PropertySheet; |
---|
112 | PropertySheet.DoModal(GetActiveWindow()); |
---|
113 | } |
---|
114 | _ATLCATCH(Exception) |
---|
115 | { |
---|
116 | _C(Exception); |
---|
117 | } |
---|
118 | return S_OK; |
---|
119 | } |
---|