Note that there are some explanatory texts on larger screens.

plurals
  1. POIDropTarget::Drop method Hooking
    text
    copied!<p>I am trying to hook IDropTarget::Drop COM method but i am not, before this i was hooking the IFileOperation::RenameItems Method it is working fine and for RenameItems hooking i used the following code ..</p> <pre><code>#include "stdafx.h" #include &lt;windows.h&gt; #include "MinHook.h" #include &lt;Winternl.h&gt; #include &lt;stdio.h&gt; #include &lt;shlwapi.h&gt; #include &lt;tchar.h&gt; #include &lt;string.h&gt; #include &lt;psapi.h&gt; #include &lt;strsafe.h&gt; #include &lt;Shobjidl.h&gt; #include &lt;Shellapi.h&gt; #include &lt;Shlguid.h&gt; #if defined _M_X64 #pragma comment(lib, "libMinHook.x64.lib") bool __is32bitMachine = false ; #elif defined _M_IX86 #pragma comment(lib, "libMinHook.x86.lib") bool __is32bitMachine = true; #endif PVOID GetInterfaceMethod(PVOID intf, DWORD methodIndex) { if (__is32bitMachine) return *(PVOID*)(*(DWORD_PTR*)intf + methodIndex * 4); else return *(PVOID*)(*(DWORD_PTR*)intf + methodIndex * 8); } typedef HRESULT (STDMETHODCALLTYPE *RenameItemsNext)(IFileOperation *pThis, IUnknown *pUnkItems, LPCWSTR pszNewName); RenameItemsNext Real_RenameItems = NULL; RenameItemsNext Actual_RenameItems ; HRESULT STDMETHODCALLTYPE RenameItemsCallback(IFileOperation *pThis, IUnknown *pUnkItems, LPCWSTR pszNewName) { IID IID_ShellItemArray; IID IID_DataObject; CLSIDFromString(L"{b63ea76d-1f85-456f-a19c-48159efa858b}", &amp;IID_ShellItemArray); CLSIDFromString(L"{0000010E-0000-0000-C000-000000000046}", &amp;IID_DataObject); void *shellItemArray; void *dataObject; LPWSTR dstFN; if (pUnkItems-&gt;QueryInterface(IID_ShellItemArray, &amp;shellItemArray) == S_OK) { DWORD numItems = 0; IShellItem *shell; IShellItemArray *pItems = (IShellItemArray *) pUnkItems; pItems-&gt;GetCount(&amp;numItems); for (int i = 0; i &lt; numItems; i++) { pItems-&gt;GetItemAt(i, &amp;shell); shell-&gt;GetDisplayName(SIGDN_FILESYSPATH, &amp;dstFN); MessageBoxW(NULL, dstFN, L"Renamed From", MB_OK); } MessageBoxW(NULL, pszNewName, L"Renamed To", MB_OK); } if (pUnkItems-&gt;QueryInterface(IID_DataObject, &amp;dataObject) == S_OK) { Real_SHCreateShell = (SHCreateShellNext)GetProcAddress(LoadLibraryA("shell32.dll"), "SHCreateShellItemArrayFromDataObject"); if (Real_SHCreateShell != NULL) { if (Real_SHCreateShell((IDataObject*)dataObject, IID_ShellItemArray, &amp;shellItemArray) == S_OK) { DWORD numItems = 0; IShellItem *shell; IShellItemArray *pItems = (IShellItemArray *)shellItemArray; pItems-&gt;GetCount(&amp;numItems); if (pItems-&gt;GetCount(&amp;numItems) == S_OK) { for (int i = 0; i &lt; numItems; i++) { if (pItems-&gt;GetItemAt(i, &amp;shell) == S_OK) { shell-&gt;GetDisplayName(SIGDN_FILESYSPATH, &amp;dstFN); MessageBoxW(NULL, dstFN, L"Renamed From", MB_OK); } } } } } MessageBoxW(NULL, dstFN, L"Renamed To", MB_OK); } return Real_RenameItems(pThis, pUnkItems, pszNewName); } typedef HRESULT (WINAPI *COCREATEINSTANCE)(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID*); COCREATEINSTANCE Real_CoCreateInstance = NULL; HRESULT WINAPI CoCreateInstanceCallback(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv) { const char *IFileOperation_GUID = "{3AD05575-8857-4850-9277-11B85BDB8E09}"; char GUIDString[64]; HRESULT HR = Real_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv); sprintf_s(GUIDString, 64, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}\0", rclsid.Data1, rclsid.Data2, rclsid.Data3, rclsid.Data4[0], rclsid.Data4[1], rclsid.Data4[2], rclsid.Data4[3], rclsid.Data4[4], rclsid.Data4[5], rclsid.Data4[6], rclsid.Data4[7]); if (strcmp(GUIDString, IFileOperation_GUID) == 0) { if(Real_RenameItems == NULL) { Actual_RenameItems = (RenameItemsNext) GetInterfaceMethod(*ppv, 13); if (MH_CreateHook(Actual_RenameItems, &amp;RenameItemsCallback, reinterpret_cast&lt;void**&gt;(&amp;Real_RenameItems)) != MH_OK) { MessageBoxW(NULL, L"Failed CreateHook Real_RenameItems", L"Info!", MB_ICONWARNING|MB_OK); } if (MH_EnableHook(Actual_RenameItems) != MH_OK) { MessageBoxW(NULL, L"Failed EnableHook Real_RenameItems", L"Info!", MB_ICONWARNING|MB_OK); } } } return HR; } BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: if (MH_Initialize() != MH_OK) { MessageBoxW(NULL, L"Failed Initialize", L"Info!", MB_ICONWARNING|MB_OK); } if (MH_CreateHook(&amp;CoCreateInstance, &amp;CoCreateInstanceCallback, reinterpret_cast&lt;void**&gt;(&amp;Real_CoCreateInstance)) != MH_OK) { MessageBoxW(NULL, L"Failed MH_CreateHook CoCreateInstance", L"Info!", MB_ICONWARNING|MB_OK); } if (MH_EnableHook(&amp;CoCreateInstance) != MH_OK) { MessageBoxW(NULL, L"Failed MH_EnableHook CoCreateInstance", L"Info!", MB_ICONWARNING|MB_OK); } break; case DLL_PROCESS_DETACH: if (MH_Uninitialize() != MH_OK) { } if (MH_DisableHook(Actual_RenameItems) != MH_OK) { } if (MH_DisableHook(&amp;CoCreateInstance) != MH_OK) { } break; } return TRUE; } </code></pre> <p>The above code is working fine for IOFileOperation::RenameItems and i am trying to implement the same code for IDropTarget::Drop Method but what is happening is the CoCreateInstance Function itself is not calling for Drop operation , so can any help me how to implement this IDropTarget::Drop Hooking .......</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload