Last active
March 29, 2016 09:44
-
-
Save lniwn/c351eacd640b67a92510 to your computer and use it in GitHub Desktop.
使用优雅的方式自定义程序加载的flash插件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef HRESULT (STDCALL * fnDllGetClassObject)(REFCLSID rclsid, REFIID riid, LPVOID * ppvObj); | |
class CustomFlash | |
{ | |
DWORD m_dwCookie; | |
CLSID m_clsid; | |
CComPtr<IClassFactory> m_spFactory; | |
HINSTANCE m_mod; | |
public: | |
CustomFlash() : m_dwCookie(0), m_mod(NULL) | |
{ | |
// | |
} | |
~CustomFlash() | |
{ | |
UnInit(); | |
} | |
BOOL Init(LPCWSTR lpszOcx) | |
{ | |
if (m_dwCookie == 0) | |
{ | |
m_mod = ::CoLoadLibrary((LPOLESTR)lpszOcx, FALSE); | |
if (m_mod == NULL) return UnInit(), FALSE; | |
HRESULT hr = CLSIDFromProgID(L"ShockwaveFlash.ShockwaveFlash", &m_clsid); | |
if (FAILED(hr)) return UnInit(), FALSE; | |
fnDllGetClassObject fn = (fnDllGetClassObject)::GetProcAddress(m_mod, "DllGetClassObject"); | |
if (fn == NULL) return UnInit(), FALSE; | |
hr = fn(m_clsid, IID_IClassFactory, (LPVOID*)&m_spFactory.p); | |
if (FAILED(hr)) return UnInit(), FALSE; | |
hr = ::CoRegisterClassObject(m_clsid, m_spFactory.p, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &m_dwCookie); | |
if (FAILED(hr)) return UnInit(), FALSE; | |
return TRUE; | |
} | |
return FALSE; | |
} | |
void UnInit() | |
{ | |
if (m_dwCookie) | |
{ | |
HRESULT hr = ::CoRevokeClassObject(m_dwCookie); | |
m_dwCookie = 0; | |
} | |
m_spFactory = NULL; | |
if (m_mod) | |
{ | |
::CoFreeLibrary(m_mod); | |
m_mod = NULL; | |
} | |
} | |
}; | |
CustomFlash g_customFlash; // 创建全局变量 | |
// 在HOOK的地方,直接调用g_customFlash.Init(L"...\flash.ocx"); 即可完成替换 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment