- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# FakeFilterMapper2.cpp

    00001 /*
    00002  *      Copyright (C) 2003-2005 Gabest
    00003  *      http://www.gabest.org
    00004  *
    00005  *  This Program is free software; you can redistribute it and/or modify
    00006  *  it under the terms of the GNU General Public License as published by
    00007  *  the Free Software Foundation; either version 2, or (at your option)
    00008  *  any later version.
    00009  *
    00010  *  This Program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    00013  *  GNU General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU General Public License
    00016  *  along with GNU Make; see the file COPYING.  If not, write to
    00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00018  *  http://www.gnu.org/copyleft/gpl.html
    00019  *
    00020  */
    00021
    00022 #include "stdafx.h"
    00023 #include "fakefiltermapper2.h"
    00024 #include "MacrovisionKicker.h"
    00025 #include "..\..\..\include\detours\detours.h"
    00026 #include "..\..\DSUtil\DSUtil.h"
    00027
    00028 #include <initguid.h>
    00029 #include <qedit.h>
    00030
    00031 DETOUR_TRAMPOLINE(HRESULT WINAPI Real_CoCreateInstance(IN REFCLSID rclsid, IN LPUNKNOWN pUnkOuter, IN DWORD dwClsContext, IN REFIID riid, OUT LPVOID FAR* ppv), CoCreateInstance);
    00032 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCloseKey(HKEY a0), RegCloseKey);
    00033 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegFlushKey(HKEY a0), RegFlushKey);
    00034 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyA(HKEY a0, LPCSTR a1, PHKEY a2), RegCreateKeyA);
    00035 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyW(HKEY a0, LPCWSTR a1, PHKEY a2), RegCreateKeyW);
    00036 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyExA(HKEY a0, LPCSTR a1, DWORD a2, LPSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8), RegCreateKeyExA);
    00037 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegCreateKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, LPWSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8), RegCreateKeyExW);
    00038 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteKeyA(HKEY a0, LPCSTR a1), RegDeleteKeyA);
    00039 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteKeyW(HKEY a0, LPCWSTR a1), RegDeleteKeyW);
    00040 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteValueA(HKEY a0, LPCSTR a1), RegDeleteValueA);
    00041 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegDeleteValueW(HKEY a0, LPCWSTR a1), RegDeleteValueW);
    00042 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumKeyExA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPSTR a5, LPDWORD a6, struct _FILETIME* a7), RegEnumKeyExA);
    00043 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumKeyExW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPWSTR a5, LPDWORD a6, struct _FILETIME* a7), RegEnumKeyExW);
    00044 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumValueA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7), RegEnumValueA);
    00045 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegEnumValueW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7), RegEnumValueW);
    00046 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyA(HKEY a0, LPCSTR a1, PHKEY a2), RegOpenKeyA);
    00047 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyW(HKEY a0, LPCWSTR a1, PHKEY a2), RegOpenKeyW);
    00048 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyExA(HKEY a0, LPCSTR a1, DWORD a2, REGSAM a3, PHKEY a4), RegOpenKeyExA);
    00049 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegOpenKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, REGSAM a3, PHKEY a4), RegOpenKeyExW);
    00050 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryInfoKeyA(HKEY a0, LPSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11), RegQueryInfoKeyA);
    00051 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryInfoKeyW(HKEY a0, LPWSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11), RegQueryInfoKeyW);
    00052 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueA(HKEY a0, LPCSTR a1, LPSTR a2, PLONG a3), RegQueryValueA);
    00053 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueW(HKEY a0, LPCWSTR a1, LPWSTR a2, PLONG a3), RegQueryValueW);
    00054 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueExA(HKEY a0, LPCSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5), RegQueryValueExA);
    00055 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegQueryValueExW(HKEY a0, LPCWSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5), RegQueryValueExW);
    00056 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueA(HKEY a0, LPCSTR a1, DWORD a2, LPCSTR a3, DWORD a4), RegSetValueA);
    00057 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueW(HKEY a0, LPCWSTR a1, DWORD a2, LPCWSTR a3, DWORD a4), RegSetValueW);
    00058 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueExA(HKEY a0, LPCSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5), RegSetValueExA);
    00059 DETOUR_TRAMPOLINE(LONG WINAPI Real_RegSetValueExW(HKEY a0, LPCWSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5), RegSetValueExW);
    00060
    00061 HRESULT WINAPI Mine_CoCreateInstance(IN REFCLSID rclsid, IN LPUNKNOWN pUnkOuter,
    00062                     IN DWORD dwClsContext, IN REFIID riid, OUT LPVOID FAR* ppv)
    00063 {
    00064         if(CFilterMapper2::m_pFilterMapper2)
    00065         {
    00066                 CheckPointer(ppv, E_POINTER);
    00067
    00068                 if(rclsid == CLSID_FilterMapper)
    00069                 {
    00070                         ASSERT(0);
    00071                         return REGDB_E_CLASSNOTREG; // sorry...
    00072                 }
    00073
    00074                 if(rclsid == CLSID_FilterMapper2)
    00075                 {
    00076                         if(pUnkOuter) return CLASS_E_NOAGGREGATION;
    00077
    00078                         if(riid == __uuidof(IUnknown))
    00079                         {
    00080                                 CFilterMapper2::m_pFilterMapper2->AddRef();
    00081                                 *ppv = (IUnknown*)CFilterMapper2::m_pFilterMapper2;
    00082                                 return S_OK;
    00083                         }
    00084                         else if(riid == __uuidof(IFilterMapper2))
    00085                         {
    00086                                 CFilterMapper2::m_pFilterMapper2->AddRef();
    00087                                 *ppv = (IFilterMapper2*)CFilterMapper2::m_pFilterMapper2;
    00088                                 return S_OK;
    00089                         }
    00090                         else
    00091                         {
    00092                                 return E_NOINTERFACE;
    00093                         }
    00094                 }
    00095         }
    00096 /*      else
    00097         {
    00098                 if(rclsid == CLSID_FilterMapper2)
    00099                 {
    00100                         CFilterMapper2* pFM2 = new CFilterMapper2(true, false, pUnkOuter);
    00101                         CComPtr<IUnknown> pUnk = (IUnknown*)pFM2;
    00102                         return pUnk->QueryInterface(riid, ppv);
    00103                 }
    00104         }
    00105 */
    00106         if(!pUnkOuter)
    00107         if(rclsid == CLSID_VideoMixingRenderer || rclsid == CLSID_VideoMixingRenderer9
    00108         || rclsid == CLSID_VideoRenderer || rclsid == CLSID_VideoRendererDefault
    00109         || rclsid == CLSID_OverlayMixer)// || rclsid == CLSID_OverlayMixer2 - where is this declared?)
    00110         {
    00111                 CMacrovisionKicker* pMK = new CMacrovisionKicker(NAME("CMacrovisionKicker"), NULL);
    00112                 CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)pMK;
    00113                 CComPtr<IUnknown> pInner;
    00114                 HRESULT hr;
    00115                 if(SUCCEEDED(hr = Real_CoCreateInstance(rclsid, pUnk, dwClsContext, __uuidof(IUnknown), (void**)&pInner)))
    00116                 {
    00117                         pMK->SetInner(pInner);
    00118                         return pUnk->QueryInterface(riid, ppv);
    00119                 }
    00120         }
    00121
    00122         return Real_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
    00123 }
    00124
    00125 #define FAKEHKEY (HKEY)0x12345678
    00126
    00127 LONG WINAPI Mine_RegCloseKey(HKEY a0)
    00128 {
    00129         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_SUCCESS;}
    00130         return Real_RegCloseKey(a0);
    00131 }
    00132 LONG WINAPI Mine_RegFlushKey(HKEY a0)
    00133 {
    00134         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_SUCCESS;}
    00135         return Real_RegFlushKey(a0);
    00136 }
    00137 LONG WINAPI Mine_RegCreateKeyA(HKEY a0, LPCSTR a1, PHKEY a2)
    00138 {
    00139         if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
    00140         return Real_RegCreateKeyA(a0, a1, a2);
    00141 }
    00142 LONG WINAPI Mine_RegCreateKeyW(HKEY a0, LPCWSTR a1, PHKEY a2)
    00143 {
    00144         if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
    00145         return Real_RegCreateKeyW(a0, a1, a2);
    00146 }
    00147 LONG WINAPI Mine_RegCreateKeyExA(HKEY a0, LPCSTR a1, DWORD a2, LPSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8)
    00148 {
    00149         if(CFilterMapper2::m_pFilterMapper2) {*a7 = FAKEHKEY; return ERROR_SUCCESS;}
    00150         return Real_RegCreateKeyExA(a0, a1, a2, a3, a4, a5, a6, a7, a8);
    00151 }
    00152 LONG WINAPI Mine_RegCreateKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, LPWSTR a3, DWORD a4, REGSAM a5, LPSECURITY_ATTRIBUTES a6, PHKEY a7, LPDWORD a8)
    00153 {
    00154         if(CFilterMapper2::m_pFilterMapper2) {*a7 = FAKEHKEY; return ERROR_SUCCESS;}
    00155         return Real_RegCreateKeyExW(a0, a1, a2, a3, a4, a5, a6, a7, a8);
    00156 }
    00157 LONG WINAPI Mine_RegDeleteKeyA(HKEY a0, LPCSTR a1)
    00158 {
    00159         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00160         return Real_RegDeleteKeyA(a0, a1);
    00161 }
    00162 LONG WINAPI Mine_RegDeleteKeyW(HKEY a0, LPCWSTR a1)
    00163 {
    00164         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00165         return Real_RegDeleteKeyW(a0, a1);
    00166 }
    00167 LONG WINAPI Mine_RegDeleteValueA(HKEY a0, LPCSTR a1)
    00168 {
    00169         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00170     return Real_RegDeleteValueA(a0, a1);
    00171 }
    00172 LONG WINAPI Mine_RegDeleteValueW(HKEY a0, LPCWSTR a1)
    00173 {
    00174         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00175     return Real_RegDeleteValueW(a0, a1);
    00176 }
    00177 LONG WINAPI Mine_RegEnumKeyExA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPSTR a5, LPDWORD a6, struct _FILETIME* a7)
    00178 {
    00179         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
    00180     return Real_RegEnumKeyExA(a0, a1, a2, a3, a4, a5, a6, a7);
    00181 }
    00182 LONG WINAPI Mine_RegEnumKeyExW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPWSTR a5, LPDWORD a6, struct _FILETIME* a7)
    00183 {
    00184         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
    00185     return Real_RegEnumKeyExW(a0, a1, a2, a3, a4, a5, a6, a7);
    00186 }
    00187 LONG WINAPI Mine_RegEnumValueA(HKEY a0, DWORD a1, LPSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7)
    00188 {
    00189         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
    00190     return Real_RegEnumValueA(a0, a1, a2, a3, a4, a5, a6, a7);
    00191 }
    00192 LONG WINAPI Mine_RegEnumValueW(HKEY a0, DWORD a1, LPWSTR a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPBYTE a6, LPDWORD a7)
    00193 {
    00194         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_NO_MORE_ITEMS;}
    00195     return Real_RegEnumValueW(a0, a1, a2, a3, a4, a5, a6, a7);
    00196 }
    00197 LONG WINAPI Mine_RegOpenKeyA(HKEY a0, LPCSTR a1, PHKEY a2)
    00198 {
    00199         if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
    00200         return Real_RegOpenKeyA(a0, a1, a2);
    00201 }
    00202 LONG WINAPI Mine_RegOpenKeyW(HKEY a0, LPCWSTR a1, PHKEY a2)
    00203 {
    00204         if(CFilterMapper2::m_pFilterMapper2) {*a2 = FAKEHKEY; return ERROR_SUCCESS;}
    00205         return Real_RegOpenKeyW(a0, a1, a2);
    00206 }
    00207 LONG WINAPI Mine_RegOpenKeyExA(HKEY a0, LPCSTR a1, DWORD a2, REGSAM a3, PHKEY a4)
    00208 {
    00209         if(CFilterMapper2::m_pFilterMapper2 && (a3&(KEY_SET_VALUE|KEY_CREATE_SUB_KEY))) {*a4 = FAKEHKEY; return ERROR_SUCCESS;}
    00210         return Real_RegOpenKeyExA(a0, a1, a2, a3, a4);
    00211 }
    00212 LONG WINAPI Mine_RegOpenKeyExW(HKEY a0, LPCWSTR a1, DWORD a2, REGSAM a3, PHKEY a4)
    00213 {
    00214         if(CFilterMapper2::m_pFilterMapper2 && (a3&(KEY_SET_VALUE|KEY_CREATE_SUB_KEY))) {*a4 = FAKEHKEY; return ERROR_SUCCESS;}
    00215         return Real_RegOpenKeyExW(a0, a1, a2, a3, a4);
    00216 }
    00217 LONG WINAPI Mine_RegQueryInfoKeyA(HKEY a0, LPSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11)
    00218 {
    00219         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_INVALID_HANDLE;}
    00220         return Real_RegQueryInfoKeyA(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
    00221 }
    00222 LONG WINAPI Mine_RegQueryInfoKeyW(HKEY a0, LPWSTR a1, LPDWORD a2, LPDWORD a3, LPDWORD a4, LPDWORD a5, LPDWORD a6, LPDWORD a7, LPDWORD a8, LPDWORD a9, LPDWORD a10, struct _FILETIME* a11)
    00223 {
    00224         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {return ERROR_INVALID_HANDLE;}
    00225         return Real_RegQueryInfoKeyW(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
    00226 }
    00227 LONG WINAPI Mine_RegQueryValueA(HKEY a0, LPCSTR a1, LPSTR a2, PLONG a3)
    00228 {
    00229         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a3 = 0; return ERROR_SUCCESS;}
    00230     return Real_RegQueryValueA(a0, a1, a2, a3);
    00231 }
    00232 LONG WINAPI Mine_RegQueryValueW(HKEY a0, LPCWSTR a1, LPWSTR a2, PLONG a3)
    00233 {
    00234         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a3 = 0; return ERROR_SUCCESS;}
    00235     return Real_RegQueryValueW(a0, a1, a2, a3);
    00236 }
    00237 LONG WINAPI Mine_RegQueryValueExA(HKEY a0, LPCSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5)
    00238 {
    00239         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a5 = 0; return ERROR_SUCCESS;}
    00240     return Real_RegQueryValueExA(a0, a1, a2, a3, a4, a5);
    00241 }
    00242 LONG WINAPI Mine_RegQueryValueExW(HKEY a0, LPCWSTR a1, LPDWORD a2, LPDWORD a3, LPBYTE a4, LPDWORD a5)
    00243 {
    00244         if(CFilterMapper2::m_pFilterMapper2 && a0 == FAKEHKEY) {*a5 = 0; return ERROR_SUCCESS;}
    00245     return Real_RegQueryValueExW(a0, a1, a2, a3, a4, a5);
    00246 }
    00247 LONG WINAPI Mine_RegSetValueA(HKEY a0, LPCSTR a1, DWORD a2, LPCSTR a3, DWORD a4)
    00248 {
    00249         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00250     return Real_RegSetValueA(a0, a1, a2, a3, a4);
    00251 }
    00252 LONG WINAPI Mine_RegSetValueW(HKEY a0, LPCWSTR a1, DWORD a2, LPCWSTR a3, DWORD a4)
    00253 {
    00254         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00255     return Real_RegSetValueW(a0, a1, a2, a3, a4);
    00256 }
    00257 LONG WINAPI Mine_RegSetValueExA(HKEY a0, LPCSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5)
    00258 {
    00259         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00260     return Real_RegSetValueExA(a0, a1, a2, a3, a4, a5);
    00261 }
    00262 LONG WINAPI Mine_RegSetValueExW(HKEY a0, LPCWSTR a1, DWORD a2, DWORD a3, BYTE* a4, DWORD a5)
    00263 {
    00264         if(CFilterMapper2::m_pFilterMapper2 && (a0 == FAKEHKEY || (int)a0 < 0)) {return ERROR_SUCCESS;}
    00265     return Real_RegSetValueExW(a0, a1, a2, a3, a4, a5);
    00266 }
    00267
    00268 //
    00269 // CFilterMapper2
    00270 //
    00271
    00272 IFilterMapper2* CFilterMapper2::m_pFilterMapper2 = NULL;
    00273
    00274 bool CFilterMapper2::fInitialized = false;
    00275
    00276 void CFilterMapper2::Init()
    00277 {
    00278         if(!fInitialized)
    00279         {
    00280                 DetourFunctionWithTrampoline((PBYTE)Real_CoCreateInstance, (PBYTE)Mine_CoCreateInstance);
    00281                 DetourFunctionWithTrampoline((PBYTE)Real_RegCloseKey, (PBYTE)Mine_RegCloseKey);
    00282                 DetourFunctionWithTrampoline((PBYTE)Real_RegFlushKey, (PBYTE)Mine_RegFlushKey);
    00283                 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyA, (PBYTE)Mine_RegCreateKeyA);
    00284                 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyW, (PBYTE)Mine_RegCreateKeyW);
    00285                 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyExA, (PBYTE)Mine_RegCreateKeyExA);
    00286                 DetourFunctionWithTrampoline((PBYTE)Real_RegCreateKeyExW, (PBYTE)Mine_RegCreateKeyExW);
    00287                 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteKeyA, (PBYTE)Mine_RegDeleteKeyA);
    00288                 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteKeyW, (PBYTE)Mine_RegDeleteKeyW);
    00289                 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteValueA, (PBYTE)Mine_RegDeleteValueA);
    00290                 DetourFunctionWithTrampoline((PBYTE)Real_RegDeleteValueW, (PBYTE)Mine_RegDeleteValueW);
    00291                 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumKeyExA, (PBYTE)Mine_RegEnumKeyExA);
    00292                 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumKeyExW, (PBYTE)Mine_RegEnumKeyExW);
    00293                 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumValueA, (PBYTE)Mine_RegEnumValueA);
    00294                 DetourFunctionWithTrampoline((PBYTE)Real_RegEnumValueW, (PBYTE)Mine_RegEnumValueW);
    00295                 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyA, (PBYTE)Mine_RegOpenKeyA);
    00296                 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyW, (PBYTE)Mine_RegOpenKeyW);
    00297                 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyExA, (PBYTE)Mine_RegOpenKeyExA);
    00298                 DetourFunctionWithTrampoline((PBYTE)Real_RegOpenKeyExW, (PBYTE)Mine_RegOpenKeyExW);
    00299                 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryInfoKeyA, (PBYTE)Mine_RegQueryInfoKeyA);
    00300                 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryInfoKeyW, (PBYTE)Mine_RegQueryInfoKeyW);
    00301                 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueA, (PBYTE)Mine_RegQueryValueA);
    00302                 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueW, (PBYTE)Mine_RegQueryValueW);
    00303                 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueExA, (PBYTE)Mine_RegQueryValueExA);
    00304                 DetourFunctionWithTrampoline((PBYTE)Real_RegQueryValueExW, (PBYTE)Mine_RegQueryValueExW);
    00305                 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueA, (PBYTE)Mine_RegSetValueA);
    00306                 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueW, (PBYTE)Mine_RegSetValueW);
    00307                 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueExA, (PBYTE)Mine_RegSetValueExA);
    00308                 DetourFunctionWithTrampoline((PBYTE)Real_RegSetValueExW, (PBYTE)Mine_RegSetValueExW);
    00309
    00310                 fInitialized = true;
    00311         }
    00312 }
    00313
    00314 CFilterMapper2::CFilterMapper2(bool fRefCounted, bool fAllowUnreg, LPUNKNOWN pUnkOuter)
    00315         : CUnknown(NAME("CFilterMapper2"), pUnkOuter)
    00316         , m_fRefCounted(fRefCounted), m_fAllowUnreg(fAllowUnreg)
    00317 {
    00318         m_cRef = fRefCounted ? 0 : 1;
    00319
    00320         Init();
    00321
    00322         HRESULT hr = Real_CoCreateInstance(
    00323                 CLSID_FilterMapper2, (IUnknown*)(INonDelegatingUnknown*)this, CLSCTX_ALL,
    00324                 __uuidof(IUnknown), (void**)&m_pFM2);
    00325         if(FAILED(hr) || !m_pFM2)
    00326         {
    00327                 ASSERT(0);
    00328                 return;
    00329         }
    00330 }
    00331
    00332 CFilterMapper2::~CFilterMapper2()
    00333 {
    00334         POSITION pos = m_filters.GetHeadPosition();
    00335         while(pos) delete m_filters.GetNext(pos);
    00336 }
    00337
    00338 STDMETHODIMP CFilterMapper2::NonDelegatingQueryInterface(REFIID riid, void** ppv)
    00339 {
    00340         if(riid == __uuidof(IFilterMapper2))
    00341                 return GetInterface((IFilterMapper2*)this, ppv);
    00342
    00343         HRESULT hr = m_pFM2 ? m_pFM2->QueryInterface(riid, ppv) : E_NOINTERFACE;
    00344
    00345         return
    00346                 SUCCEEDED(hr) ? hr :
    00347                 __super::NonDelegatingQueryInterface(riid, ppv);
    00348 }
    00349
    00350 void CFilterMapper2::Register(CString path)
    00351 {
    00352         if(HMODULE h = LoadLibrary(path))
    00353         {
    00354                 typedef HRESULT (__stdcall * PDllRegisterServer)();
    00355                 if(PDllRegisterServer p = (PDllRegisterServer)GetProcAddress(h, "DllRegisterServer"))
    00356                 {
    00357                         ASSERT(CFilterMapper2::m_pFilterMapper2 == NULL);
    00358
    00359                         CFilterMapper2::m_pFilterMapper2 = this;
    00360                         m_path = path;
    00361                         p();
    00362                         m_path.Empty();
    00363                         CFilterMapper2::m_pFilterMapper2 = NULL;
    00364                 }
    00365
    00366                 FreeLibrary(h);
    00367         }
    00368 }
    00369
    00370 // IFilterMapper2
    00371
    00372 STDMETHODIMP CFilterMapper2::CreateCategory(REFCLSID clsidCategory, DWORD dwCategoryMerit, LPCWSTR Description)
    00373 {
    00374         if(!m_path.IsEmpty())
    00375         {
    00376                 return S_OK;
    00377         }
    00378         else if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
    00379         {
    00380                 return pFM2->CreateCategory(clsidCategory, dwCategoryMerit, Description);
    00381         }
    00382
    00383         return E_NOTIMPL;
    00384 }
    00385
    00386 STDMETHODIMP CFilterMapper2::UnregisterFilter(const CLSID* pclsidCategory, const OLECHAR* szInstance, REFCLSID Filter)
    00387 {
    00388         if(!m_path.IsEmpty())
    00389         {
    00390                 return S_OK;
    00391         }
    00392         else if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
    00393         {
    00394                 return m_fAllowUnreg
    00395                         ? pFM2->UnregisterFilter(pclsidCategory, szInstance, Filter)
    00396                         : S_OK;
    00397         }
    00398
    00399         return E_NOTIMPL;
    00400 }
    00401
    00402 STDMETHODIMP CFilterMapper2::RegisterFilter(REFCLSID clsidFilter, LPCWSTR Name, IMoniker** ppMoniker, const CLSID* pclsidCategory, const OLECHAR* szInstance, const REGFILTER2* prf2)
    00403 {
    00404         if(!m_path.IsEmpty())
    00405         {
    00406                 if(Filter* f = new Filter)
    00407                 {
    00408                         f->fDisabled = false;
    00409                         f->type = Filter::EXTERNAL;
    00410                         f->path = m_path;
    00411                         f->name = CStringW(Name);
    00412                         f->clsid = clsidFilter;
    00413                         f->iLoadType = Filter::MERIT;
    00414                         f->dwMerit = prf2->dwMerit;
    00415
    00416                         if(prf2->dwVersion == 1)
    00417                         {
    00418                                 for(ULONG i = 0; i < prf2->cPins; i++)
    00419                                 {
    00420                                         const REGFILTERPINS& rgPin = prf2->rgPins[i];
    00421                                         if(rgPin.bOutput) continue;
    00422
    00423                                         for(UINT i = 0; i < rgPin.nMediaTypes; i++)
    00424                                         {
    00425                                                 if(!rgPin.lpMediaType[i].clsMajorType || !rgPin.lpMediaType[i].clsMinorType) break;
    00426                                                 f->guids.AddTail(*rgPin.lpMediaType[i].clsMajorType);
    00427                                                 f->guids.AddTail(*rgPin.lpMediaType[i].clsMinorType);
    00428                                         }
    00429                                 }
    00430                         }
    00431                         else if(prf2->dwVersion == 2)
    00432                         {
    00433                                 for(ULONG i = 0; i < prf2->cPins2; i++)
    00434                                 {
    00435                                         const REGFILTERPINS2& rgPin = prf2->rgPins2[i];
    00436                                         if(rgPin.dwFlags&REG_PINFLAG_B_OUTPUT) continue;
    00437
    00438                                         for(UINT i = 0; i < rgPin.nMediaTypes; i++)
    00439                                         {
    00440                                                 if(!rgPin.lpMediaType[i].clsMajorType || !rgPin.lpMediaType[i].clsMinorType) break;
    00441                                                 f->guids.AddTail(*rgPin.lpMediaType[i].clsMajorType);
    00442                                                 f->guids.AddTail(*rgPin.lpMediaType[i].clsMinorType);
    00443                                         }
    00444                                 }
    00445                         }
    00446
    00447                         f->backup.AddTail(&f->guids);
    00448
    00449                         m_filters.AddTail(f);
    00450                 }
    00451
    00452                 return S_OK;
    00453         }
    00454         else if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
    00455         {
    00456                 return pFM2->RegisterFilter(clsidFilter, Name, ppMoniker, pclsidCategory, szInstance, prf2);
    00457         }
    00458
    00459         return E_NOTIMPL;
    00460 }
    00461
    00462 STDMETHODIMP CFilterMapper2::EnumMatchingFilters(IEnumMoniker** ppEnum, DWORD dwFlags, BOOL bExactMatch, DWORD dwMerit,
    00463         BOOL bInputNeeded, DWORD cInputTypes, const GUID* pInputTypes, const REGPINMEDIUM* pMedIn, const CLSID* pPinCategoryIn, BOOL bRender,
    00464         BOOL bOutputNeeded, DWORD cOutputTypes, const GUID* pOutputTypes, const REGPINMEDIUM* pMedOut, const CLSID* pPinCategoryOut)
    00465 {
    00466         if(CComQIPtr<IFilterMapper2> pFM2 = m_pFM2)
    00467         {
    00468                 pFM2->EnumMatchingFilters(ppEnum, dwFlags, bExactMatch, dwMerit,
    00469                         bInputNeeded, cInputTypes, pInputTypes, pMedIn, pPinCategoryIn, bRender,
    00470                         bOutputNeeded, cOutputTypes, pOutputTypes, pMedOut, pPinCategoryOut);
    00471         }
    00472
    00473         return E_NOTIMPL;
    00474 }