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.

140 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. Resonate.cpp
  5. Abstract:
  6. The name of the TCP loopback adapter was changed from MS Loopback Adapter to
  7. Microsoft Loopback Adapter. Resonate looks for the old name.
  8. Notes:
  9. This is an app specific shim.
  10. History:
  11. 08/12/2002 robkenny Created
  12. --*/
  13. #include "precomp.h"
  14. #include "Iphlpapi.h"
  15. IMPLEMENT_SHIM_BEGIN(Resonate)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(GetAdaptersInfo)
  19. APIHOOK_ENUM_ENTRY(GetIfTable)
  20. APIHOOK_ENUM_ENTRY(GetIfEntry)
  21. APIHOOK_ENUM_END
  22. typedef DWORD (*_pfn_GetAdaptersInfo)(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen);
  23. typedef DWORD (*_pfn_GetIfTable)( PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder );
  24. typedef DWORD (*_pfn_GetIfEntry)( PMIB_IFROW pIfRow );
  25. /*++
  26. Convert the loopback adaptor name from Microsoft Loopback Adapter to MS Loopback Adapter
  27. --*/
  28. DWORD
  29. APIHOOK(GetAdaptersInfo)(
  30. PIP_ADAPTER_INFO pAdapterInfo, // buffer to receive data
  31. PULONG pOutBufLen // size of data returned
  32. )
  33. {
  34. DWORD dwRet = ORIGINAL_API(GetAdaptersInfo)(pAdapterInfo, pOutBufLen);
  35. if (dwRet == ERROR_SUCCESS)
  36. {
  37. DPFN(eDbgLevelInfo, "GetAdaptersInfo called successfully");
  38. // Traverse the linked list, looking for the old name
  39. for (PIP_ADAPTER_INFO ll = pAdapterInfo; ll != NULL; ll = ll->Next)
  40. {
  41. DPFN(eDbgLevelInfo, "Adapter Name(%s)", ll->AdapterName);
  42. DPFN(eDbgLevelInfo, "Adapter Desc(%s)", ll->Description);
  43. if (strcmp(ll->Description, "Microsoft Loopback Adapter") == 0)
  44. {
  45. (void)StringCchCopyA(ll->Description, MAX_ADAPTER_DESCRIPTION_LENGTH + 4, "MS Loopback Adapter");
  46. LOGN(eDbgLevelError, "Changing name of loopback adapter to %s", ll->Description);
  47. break;
  48. }
  49. }
  50. }
  51. return dwRet;
  52. }
  53. DWORD
  54. APIHOOK(GetIfTable)(
  55. PMIB_IFTABLE pIfTable, // buffer for interface table
  56. PULONG pdwSize, // size of buffer
  57. BOOL bOrder // sort the table by index?
  58. )
  59. {
  60. DWORD dwRet = ORIGINAL_API(GetIfTable)(pIfTable, pdwSize, bOrder);
  61. if (dwRet == NO_ERROR)
  62. {
  63. DPFN(eDbgLevelInfo, "GetIfTable called successfully");
  64. // Traverse the array, looking for the old name
  65. for (DWORD i = 0; i < pIfTable->dwNumEntries; ++i)
  66. {
  67. DPFN(eDbgLevelInfo, "Interface Name(%s)", pIfTable->table[i].bDescr);
  68. if (strcmp((const char *)pIfTable->table[i].bDescr, "Microsoft Loopback Adapter") == 0)
  69. {
  70. (void)StringCchCopyA((char *)pIfTable->table[i].bDescr, MAXLEN_IFDESCR, "MS LoopBack Driver");
  71. LOGN(eDbgLevelError, "Changing name of interface to %s", pIfTable->table[i].bDescr);
  72. break;
  73. }
  74. }
  75. }
  76. return dwRet;
  77. }
  78. DWORD
  79. APIHOOK(GetIfEntry)(
  80. PMIB_IFROW pIfRow // pointer to interface entry
  81. )
  82. {
  83. DWORD dwRet = ORIGINAL_API(GetIfEntry)(pIfRow);
  84. if (dwRet == NO_ERROR)
  85. {
  86. DPFN(eDbgLevelInfo, "GetIfEntry called successfully");
  87. DPFN(eDbgLevelInfo, "Interface Name(%s)", pIfRow->bDescr);
  88. if (strcmp((const char *)pIfRow->bDescr, "Microsoft Loopback Adapter") == 0)
  89. {
  90. (void)StringCchCopyA((char *)pIfRow->bDescr, MAXLEN_IFDESCR, "MS LoopBack Driver");
  91. LOGN(eDbgLevelError, "Changing name of interface to %s", pIfRow->bDescr);
  92. }
  93. }
  94. return dwRet;
  95. }
  96. /*++
  97. Register hooked functions
  98. --*/
  99. HOOK_BEGIN
  100. APIHOOK_ENTRY(Iphlpapi.DLL, GetAdaptersInfo)
  101. APIHOOK_ENTRY(Iphlpapi.DLL, GetIfTable)
  102. APIHOOK_ENTRY(Iphlpapi.DLL, GetIfEntry)
  103. HOOK_END
  104. IMPLEMENT_SHIM_END