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.

198 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. BigActionConstruction.cpp
  5. Abstract:
  6. The uninstall was not uninstalling the .lnk files on
  7. the ALLUSER start Menu. This was because the uninstaller
  8. script was not getting the right path.
  9. This is an app specific shim.
  10. History:
  11. 03/12/2001 prashkud Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(BigActionConstruction)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(FindFirstFileA)
  18. APIHOOK_ENUM_ENTRY(RemoveDirectoryA)
  19. APIHOOK_ENUM_ENTRY(DeleteFileA)
  20. APIHOOK_ENUM_END
  21. WCHAR g_szAllUsersStartMenu[MAX_PATH];
  22. WCHAR* g_pszFilePath = L"\\Programs\\Big Action Construction";
  23. WCHAR* g_pszReplacementFilePath = L"\\Programs\\Fisher~1\\Big Action Construction";
  24. /*++
  25. This hook replaces the wrong path with the right replacement path.
  26. --*/
  27. HANDLE
  28. APIHOOK(FindFirstFileA)(
  29. LPCSTR lpFileName,
  30. LPWIN32_FIND_DATAA lpFindFileData
  31. )
  32. {
  33. CSTRING_TRY
  34. {
  35. CString AllUserPath(g_szAllUsersStartMenu);
  36. CString FileName(lpFileName);
  37. // Or D:\Documents And Settings\All Users\Start Menu\g_pszFilePath\*.*
  38. AllUserPath.AppendPath(g_pszFilePath);
  39. AllUserPath.AppendPath(L"*.*");
  40. // If any of the above constructed path match
  41. if (AllUserPath.CompareNoCase(FileName) == 0)
  42. {
  43. // Fill in the replacement path
  44. AllUserPath = g_szAllUsersStartMenu;
  45. AllUserPath.AppendPath(g_szAllUsersStartMenu);
  46. AllUserPath.AppendPath(L"*.*");
  47. DPFN( eDbgLevelInfo, "[Notify] FindFirstFileA \
  48. modified %s to %S",lpFileName, AllUserPath.Get());
  49. return ORIGINAL_API(FindFirstFileA)(AllUserPath.GetAnsi(),lpFindFileData);
  50. }
  51. }
  52. CSTRING_CATCH
  53. {
  54. //do nothing
  55. }
  56. return ORIGINAL_API(FindFirstFileA)(lpFileName,lpFindFileData);
  57. }
  58. /*++
  59. This hook replaces the wrong path with the right replacement path.
  60. --*/
  61. BOOL
  62. APIHOOK(RemoveDirectoryA)(
  63. LPCSTR lpFileName
  64. )
  65. {
  66. CSTRING_TRY
  67. {
  68. CString AllUserPath(g_szAllUsersStartMenu);
  69. CString FileName(lpFileName);
  70. // Or D:\Documents And Settings\All Users\Start Menu\g_pszFilePath
  71. AllUserPath.AppendPath(g_pszFilePath);
  72. if (AllUserPath.CompareNoCase(FileName) == 0)
  73. {
  74. // Fill in the replacement path
  75. AllUserPath = g_szAllUsersStartMenu;
  76. AllUserPath.AppendPath(g_szAllUsersStartMenu);
  77. DPFN( eDbgLevelInfo, "[Notify] RemoveDirectoryA \
  78. modified %s to %S", lpFileName, AllUserPath.Get());
  79. return ORIGINAL_API(RemoveDirectoryA)(AllUserPath.GetAnsi());
  80. }
  81. }
  82. CSTRING_CATCH
  83. {
  84. //do nothing
  85. }
  86. return ORIGINAL_API(RemoveDirectoryA)(lpFileName);
  87. }
  88. /*++
  89. This hook replaces the wrong path with the right replacement path.
  90. --*/
  91. BOOL
  92. APIHOOK(DeleteFileA)(
  93. LPCSTR lpFileName
  94. )
  95. {
  96. CSTRING_TRY
  97. {
  98. CString AllUserPath(g_szAllUsersStartMenu);
  99. AllUserPath += g_pszFilePath;
  100. CString csFileName(lpFileName);
  101. int nIndex = AllUserPath.Find(csFileName);
  102. if (nIndex >= 0)
  103. {
  104. // Seperate the title from the path.
  105. char szTitle[MAX_PATH];
  106. GetFileTitleA(lpFileName, szTitle, MAX_PATH);
  107. CString csTitle(szTitle);
  108. csTitle += L".lnk";
  109. // Fill in the replacement path with the title.
  110. AllUserPath = g_szAllUsersStartMenu;
  111. AllUserPath.AppendPath(g_pszReplacementFilePath);
  112. AllUserPath.AppendPath(csTitle);
  113. DPFN( eDbgLevelInfo, "[Notify] DeleteFileA \
  114. modified %s to %S", lpFileName, AllUserPath.Get());
  115. return ORIGINAL_API(DeleteFileA)(AllUserPath.GetAnsi());
  116. }
  117. }
  118. CSTRING_CATCH
  119. {
  120. //do nothing
  121. }
  122. return ORIGINAL_API(DeleteFileA)(lpFileName);
  123. }
  124. /*++
  125. Register hooked functions
  126. --*/
  127. BOOL
  128. NOTIFY_FUNCTION(
  129. DWORD fdwReason
  130. )
  131. {
  132. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED)
  133. {
  134. // Get the %AllUserStartMenu% from SHELL
  135. HRESULT result = SHGetFolderPath(NULL, CSIDL_COMMON_STARTMENU, NULL,
  136. SHGFP_TYPE_DEFAULT, g_szAllUsersStartMenu);
  137. if ((result == S_FALSE) || (result == E_INVALIDARG))
  138. {
  139. return FALSE;
  140. }
  141. }
  142. return TRUE;
  143. }
  144. HOOK_BEGIN
  145. CALL_NOTIFY_FUNCTION
  146. APIHOOK_ENTRY(KERNEL32.DLL, FindFirstFileA)
  147. APIHOOK_ENTRY(KERNEL32.DLL, RemoveDirectoryA)
  148. APIHOOK_ENTRY(KERNEL32.DLL, DeleteFileA)
  149. HOOK_END
  150. IMPLEMENT_SHIM_END