mydll.cpp
上传用户:nbcables
上传日期:2007-01-11
资源大小:1243k
文件大小:6k
源码类别:

钩子与API截获

开发平台:

Visual C++

  1. // ------------------------------------- //
  2. // 您如果要使用本文件,请不要删除本说明  //
  3. // ------------------------------------- //
  4. //             HOOKAPI 开发例子          //
  5. //   Copyright 2002 编程沙龙 Paladin     //
  6. //       www.ProgramSalon.com            //
  7. // ------------------------------------- //
  8. #include "stdafx.h"
  9. #include <stdio.h>
  10. #include "mydll.h"
  11. #include "util.h"
  12. #include "psapi.h"
  13. #include "tlhelp32.h"
  14. #include <shellapi.h>
  15. #include <shlobj.h>
  16. #include <shlwapi.h>
  17. #include "ps.h"
  18. HINSTANCE g_hInstance =NULL;
  19. BOOL APIENTRY DllMain( HANDLE hModule, 
  20.                        DWORD  ul_reason_for_call, 
  21.                        LPVOID lpReserved
  22.  )
  23. {
  24. g_hInstance =(HINSTANCE)hModule;
  25.     return TRUE;
  26. }
  27. LPITEMIDLIST WINAPI mySHBrowseForFolderA(BROWSEINFOA *pbi)
  28. {
  29. WriteLog("mySHBrowseForFolderA");
  30. return SHBrowseForFolderA(pbi);
  31. }
  32. LPITEMIDLIST WINAPI mySHBrowseForFolderW(BROWSEINFOW *pbi)
  33. {          
  34. WriteLog("mySHBrowseForFolderW");
  35. return SHBrowseForFolderW(pbi);
  36. }
  37. HRESULT WINAPI mySHGetDataFromIDListA( LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, PVOID pv, int cb)
  38. {
  39. WriteLog("myShGetDataFromIDListA");
  40. return SHGetDataFromIDListA( psf, pidl, nFormat, pv, cb);
  41. }
  42. HRESULT WINAPI mySHGetDataFromIDListW( LPSHELLFOLDER psf, LPCITEMIDLIST pidl, int nFormat, PVOID pv, int cb)
  43. {
  44. WriteLog("myShGetDataFromIDListW");
  45. return 0;
  46. //return SHGetDataFromIDListW( psf, pidl, nFormat, pv, cb);
  47. }
  48. HRESULT WINAPI mySHGetDesktopFolder( LPSHELLFOLDER *ppshf)
  49. {
  50. //WriteLog("myShGetDesktopFolder");
  51. return SHGetDesktopFolder(ppshf);
  52. }
  53. HRESULT WINAPI mySHGetSpecialFolderLocation(HWND hwndOwner, int nFolder, LPITEMIDLIST *ppidl)
  54. {
  55. WriteLog("mySHGetSpecialFolderLocation,nFolder=%d", nFolder);
  56. //return 0;
  57. return SHGetSpecialFolderLocation(hwndOwner, nFolder, ppidl);
  58. }
  59. BOOL WINAPI mySHGetPathFromIDListA( LPCITEMIDLIST pidl, LPSTR pszPath)
  60. {
  61. WriteLog("mySHGetPathFromIDListA");
  62. return SHGetPathFromIDListA(pidl, pszPath);
  63. }
  64. BOOL WINAPI mySHGetPathFromIDListW( LPCITEMIDLIST pidl, LPWSTR pszPath)
  65. {
  66. WriteLog("mySHGetPathFromIDListW");
  67. return 0;
  68. //return SHGetPathFromIDListW(pidl, pszPath);
  69. }
  70. DWORD WINAPI mySHGetFileInfoA( LPCSTR pszPath, DWORD dwFileAttributes, SHFILEINFOA FAR *psfi, UINT cbFileInfo, UINT uFlags)
  71. {
  72. WriteLog("mySHGetFileInfoA");
  73. return SHGetFileInfoA(pszPath, dwFileAttributes, psfi, cbFileInfo, uFlags);
  74. }
  75. DWORD WINAPI mySHGetFileInfoW( LPCWSTR pszPath, DWORD dwFileAttributes, SHFILEINFOW FAR *psfi, UINT cbFileInfo, UINT uFlags)
  76. {
  77. char path[128];
  78. int len =WideCharToMultiByte(CP_ACP, 0, pszPath, -1, path, sizeof(path), NULL, NULL);
  79. path[len] =0;
  80. WriteLog("mySHGetFileInfoW:%s", path);
  81. //return 0;
  82. return SHGetFileInfoW(pszPath, dwFileAttributes, psfi, cbFileInfo, uFlags);
  83. }
  84. typedef HRESULT (WINAPI *FuncSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
  85. typedef HRESULT (WINAPI *FuncSHGetFolderPathW)(HWND, int, HANDLE, DWORD, LPWSTR);
  86. HRESULT WINAPI mySHGetFolderPathA( HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath)
  87. {
  88. WriteLog("SHGetFolderPathA");
  89. HMODULE hmod =GetModuleHandle("shell32.dll");
  90. FuncSHGetFolderPathA SHGetFolderPathA=(FuncSHGetFolderPathA)GetProcAddress(hmod, "SHGetFolderPathA");
  91. if(SHGetFolderPathA)
  92. return SHGetFolderPathA( hwndOwner, nFolder, hToken, dwFlags, pszPath); 
  93. else return 0;
  94. }
  95. HRESULT WINAPI mySHGetFolderPathW( HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
  96. {
  97. HMODULE hmod =GetModuleHandle("shell32.dll");
  98. FuncSHGetFolderPathW SHGetFolderPathW=(FuncSHGetFolderPathW)GetProcAddress(hmod, "SHGetFolderPathW");
  99. if(SHGetFolderPathW)
  100. {
  101. HRESULT l=SHGetFolderPathW( hwndOwner, nFolder, hToken, dwFlags, pszPath); 
  102. char path[128];
  103. int len =WideCharToMultiByte(CP_ACP, 0, pszPath, -1, path, sizeof(path), NULL, NULL);
  104. path[len] =0;
  105. WriteLog("SHGetFolderPathW:%s", path);
  106. return l;
  107. }
  108. else
  109. return 0;
  110. }
  111. typedef HRESULT (WINAPI *FuncSHGetFolderLocation)(HWND, int, HANDLE, DWORD, LPITEMIDLIST*);
  112. HRESULT WINAPI mySHGetFolderLocation( HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPITEMIDLIST* ppidl)
  113. {
  114. WriteLog("mySHGetFolderLocation");
  115. HMODULE hmod =GetModuleHandle("shell32.dll");
  116. FuncSHGetFolderLocation SHGetFolderLocation=(FuncSHGetFolderLocation)GetProcAddress(hmod, "SHGetFolderLocation");
  117. if(SHGetFolderLocation)
  118. return SHGetFolderLocation( hwndOwner, nFolder, hToken, dwReserved, ppidl); 
  119. else
  120. return 0;
  121. }
  122. BOOL WINAPI myPathFileExistsW(LPCWSTR pstr)
  123. {
  124. char path[128];
  125. int len =WideCharToMultiByte(CP_ACP, 0, pstr, -1, path, sizeof(path), NULL, NULL);
  126. path[len] =0;
  127. WriteLog("PathFileExistsW:%s", path);
  128. return PathFileExistsW(pstr);
  129. }
  130. typedef int (WINAPI *FuncSheChangeDirW)(LPCWSTR);
  131. int WINAPI mySheChangeDirW(LPCWSTR pstr)
  132. {
  133. char path[128];
  134. int len =WideCharToMultiByte(CP_ACP, 0, pstr, -1, path, sizeof(path), NULL, NULL);
  135. path[len] =0;
  136. WriteLog("SheChangeDirW:%s", path);
  137. HMODULE hmod =GetModuleHandle("shell32.dll");
  138. FuncSheChangeDirW SheChangeDirW=(FuncSheChangeDirW)GetProcAddress(hmod, "SheChangeDirW");
  139. if(SheChangeDirW)
  140. return SheChangeDirW(pstr); 
  141. else
  142. return 0;
  143. }
  144. MYAPIINFO myapi_info[] =
  145. {
  146. {"SHELL32.DLL", "SHBrowseForFolderA", 1, "mySHBrowseForFolderA"},
  147. {"SHELL32.DLL", "SHBrowseForFolderW", 1, "mySHBrowseForFolderW"},
  148. {"SHELL32.DLL", "SHGetDataFromIDListA", 5, "mySHGetDataFromIDListA"},
  149. {"SHELL32.DLL", "SHGetDataFromIDListW", 5, "mySHGetDataFromIDListW"},
  150. {"SHELL32.DLL", "SHGetDesktopFolder", 1, "mySHGetDesktopFolder"},
  151. {"SHELL32.DLL", "SHGetSpecialFolderLocation", 3, "mySHGetSpecialFolderLocation"},
  152. {"SHELL32.DLL", "SHGetPathFromIDListA", 2, "mySHGetPathFromIDListA"},
  153. {"SHELL32.DLL", "SHGetPathFromIDListW", 2, "mySHGetPathFromIDListW"},
  154. {"SHELL32.DLL", "SHGetFileInfoA", 5, "mySHGetFileInfoA"},
  155. {"SHELL32.DLL", "SHGetFileInfoW", 5, "mySHGetFileInfoW"},
  156. {"SHELL32.DLL", "SHGetFolderPathA", 5, "mySHGetFolderPathA"},
  157. {"SHELL32.DLL", "SHGetFolderPathW", 5, "mySHGetFolderPathW"},
  158. {"SHELL32.DLL", "SHGetFolderLocation", 5,"mySHGetFolderLocation"},
  159. {"SHLWAPI.DLL", "PathFileExistsW", 1, "myPathFileExistsW"},
  160. {"SHELL32.DLL", "SheChangeDirW", 1, "mySheChangeDirW"},
  161. {NULL,NULL,NULL}
  162. };
  163. MYAPIINFO *GetMyAPIInfo()
  164. {
  165. return &myapi_info[0];
  166. }