Leaked source code of windows server 2003
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.

91 lines
2.4 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. if (pRoute->dwForwardProto == MIB_IPPROTO_LOCAL)
  36. pRoute->dwForwardProto = MIB_IPPROTO_NETMGMT;
  37. // The application used MIB_IPPROTO_LOCAL. It was ok for Win2k but it fails on WinXP. Change it to MIB_IPPROTO_NETMGMT
  38. dwReturn = ORIGINAL_API(CreateIpForwardEntry)(pRoute);
  39. return dwReturn;
  40. }
  41. BOOL
  42. APIHOOK(GetIpForwardTable)(
  43. PMIB_IPFORWARDTABLE pIpForwardTable,
  44. PULONG pdwSize,
  45. BOOL bOrder
  46. )
  47. {
  48. DWORD dwReturn;
  49. dwReturn = ORIGINAL_API(GetIpForwardTable)(pIpForwardTable, pdwSize, bOrder);
  50. if (pIpForwardTable != NULL)
  51. if (pIpForwardTable->dwNumEntries > 0)
  52. pIpForwardTable->table[0].dwForwardMetric1 = 1;
  53. // 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.
  54. return dwReturn;
  55. }
  56. /*++
  57. Register hooked functions
  58. --*/
  59. HOOK_BEGIN
  60. //
  61. // Add APIs that you wish to hook here. All API prototypes
  62. // must be declared in Hooks\inc\ShimProto.h. Compiler errors
  63. // will result if you forget to add them.
  64. //
  65. APIHOOK_ENTRY(iphlpapi.dll,GetIpForwardTable)
  66. APIHOOK_ENTRY(iphlpapi.dll,CreateIpForwardEntry)
  67. HOOK_END
  68. IMPLEMENT_SHIM_END