Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. IgnoreCoCreateInstance.cpp
  5. Abstract:
  6. Ignore specified CoCreateInstance calls.
  7. Notes:
  8. This is a general purpose shim.
  9. History:
  10. 01/07/2001 linstev Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(IgnoreCoCreateInstance)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(CoCreateInstance)
  17. APIHOOK_ENUM_END
  18. int g_nCount = 0;
  19. CString *g_rGUIDs = NULL;
  20. /*++
  21. Ignore specified CoCreateInstance calls
  22. --*/
  23. STDAPI
  24. APIHOOK(CoCreateInstance)(
  25. REFCLSID rclsid,
  26. LPUNKNOWN pUnkOuter,
  27. DWORD dwClsContext,
  28. REFIID riid,
  29. LPVOID* ppv
  30. )
  31. {
  32. CSTRING_TRY
  33. {
  34. //
  35. // Convert the CLSID to a string so we can compare it to our guids
  36. //
  37. LPOLESTR wszCLSID;
  38. if (StringFromCLSID(rclsid, &wszCLSID) == S_OK) {
  39. // Run the list and jump out if we match
  40. CString csClass(wszCLSID);
  41. for (int i = 0; i < g_nCount; i++) {
  42. if (csClass.CompareNoCase(g_rGUIDs[i]) == 0) {
  43. LOGN(eDbgLevelWarning, "[CoCreateInstance] Failed %S", wszCLSID);
  44. // Free the memory
  45. CoTaskMemFree(wszCLSID);
  46. return REGDB_E_CLASSNOTREG;
  47. }
  48. }
  49. // Free the memory
  50. CoTaskMemFree(wszCLSID);
  51. }
  52. }
  53. CSTRING_CATCH
  54. {
  55. // Do Nothing
  56. }
  57. return ORIGINAL_API(CoCreateInstance)(rclsid, pUnkOuter, dwClsContext, riid,
  58. ppv);
  59. }
  60. /*++
  61. Register hooked functions
  62. --*/
  63. BOOL ParseCommandLine()
  64. {
  65. CSTRING_TRY
  66. {
  67. CString csCl(COMMAND_LINE);
  68. CStringParser csParser(csCl, L";");
  69. g_nCount = csParser.GetCount();
  70. g_rGUIDs = csParser.ReleaseArgv();
  71. }
  72. CSTRING_CATCH
  73. {
  74. return FALSE;
  75. }
  76. for (int i = 0; i < g_nCount; ++i) {
  77. DPFN(eDbgLevelInfo, "ClassID = %S", g_rGUIDs[i].Get());
  78. }
  79. return TRUE;
  80. }
  81. BOOL
  82. NOTIFY_FUNCTION(
  83. DWORD fdwReason)
  84. {
  85. if (fdwReason == DLL_PROCESS_ATTACH) {
  86. return ParseCommandLine();
  87. }
  88. return TRUE;
  89. }
  90. HOOK_BEGIN
  91. CALL_NOTIFY_FUNCTION
  92. APIHOOK_ENTRY(OLE32.DLL, CoCreateInstance)
  93. HOOK_END
  94. IMPLEMENT_SHIM_END