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.

90 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. Chollian2000.cpp
  5. Abstract:
  6. The application has two problems.
  7. 1. it is expecting metric value 1. it is ok in win9x and win2k but it's not the
  8. case in winXP.
  9. 2. the application calls CreateIpForwardEntry with MIB_IPPROTO_LOCAL.
  10. it will fail in winXP. the application should use MIB_IPPROTO_NETMGMT.
  11. The GetIpForwardTable and CreateIpForwardEntry are shimed to fix this problem.
  12. In GetIpForwardTable, I changed the metric value to 1. In CreateIpForwardEntry,
  13. I changed MIB_IPPROTO_LOCAL to MIB_IPPROTO_NETMGMT.
  14. History:
  15. 06/12/2001 zhongyl Created
  16. --*/
  17. #include "precomp.h"
  18. #include "iphlpapi.h"
  19. IMPLEMENT_SHIM_BEGIN(Chollian2000)
  20. #include "ShimHookMacro.h"
  21. //
  22. // Add APIs that you wish to hook to this macro construction.
  23. //
  24. APIHOOK_ENUM_BEGIN
  25. APIHOOK_ENUM_ENTRY(CreateIpForwardEntry)
  26. APIHOOK_ENUM_ENTRY(GetIpForwardTable)
  27. APIHOOK_ENUM_END
  28. BOOL
  29. APIHOOK(CreateIpForwardEntry)(
  30. PMIB_IPFORWARDROW pRoute
  31. )
  32. {
  33. DWORD dwReturn;
  34. if (pRoute != NULL)
  35. pRoute->dwForwardProto = MIB_IPPROTO_NETMGMT;
  36. // The application used MIB_IPPROTO_LOCAL. It was ok for Win2k but it fails on WinXP. Change it to MIB_IPPROTO_NETMGMT
  37. dwReturn = ORIGINAL_API(CreateIpForwardEntry)(pRoute);
  38. return dwReturn;
  39. }
  40. BOOL
  41. APIHOOK(GetIpForwardTable)(
  42. PMIB_IPFORWARDTABLE pIpForwardTable,
  43. PULONG pdwSize,
  44. BOOL bOrder
  45. )
  46. {
  47. DWORD dwReturn;
  48. dwReturn = ORIGINAL_API(GetIpForwardTable)(pIpForwardTable, pdwSize, bOrder);
  49. if (pIpForwardTable != NULL)
  50. if (pIpForwardTable->dwNumEntries > 0)
  51. pIpForwardTable->table[0].dwForwardMetric1 = 1;
  52. // The application expects the Metric value to be one. In WinXP, the value is changed to 30. Application should not expect a fixed value here.
  53. return dwReturn;
  54. }
  55. /*++
  56. Register hooked functions
  57. --*/
  58. HOOK_BEGIN
  59. //
  60. // Add APIs that you wish to hook here. All API prototypes
  61. // must be declared in Hooks\inc\ShimProto.h. Compiler errors
  62. // will result if you forget to add them.
  63. //
  64. APIHOOK_ENTRY(iphlpapi.dll,GetIpForwardTable)
  65. APIHOOK_ENTRY(iphlpapi.dll,CreateIpForwardEntry)
  66. HOOK_END
  67. IMPLEMENT_SHIM_END