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.

177 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. blbind.c
  5. Abstract:
  6. This module contains the code that implements the funtions required
  7. to relocate an image and bind DLL entry points.
  8. Author:
  9. David N. Cutler (davec) 21-May-1991
  10. Revision History:
  11. --*/
  12. #include "bldr.h"
  13. #include "ctype.h"
  14. #include "string.h"
  15. //
  16. // Define local procedure prototypes.
  17. //
  18. ARC_STATUS
  19. BlpBindImportName (
  20. IN PVOID DllBase,
  21. IN PVOID ImageBase,
  22. IN PIMAGE_THUNK_DATA ThunkEntry,
  23. IN PIMAGE_EXPORT_DIRECTORY ExportDirectory,
  24. IN ULONG ExportSize,
  25. IN BOOLEAN SnapForwarder
  26. );
  27. BOOLEAN
  28. BlpCompareDllName (
  29. IN PCHAR Name,
  30. IN PUNICODE_STRING UnicodeString
  31. );
  32. ARC_STATUS
  33. BlpScanImportAddressTable(
  34. IN PVOID DllBase,
  35. IN PVOID ImageBase,
  36. IN PIMAGE_THUNK_DATA ThunkTable
  37. );
  38. #include "blbindt.c"
  39. BOOLEAN
  40. BlCheckForLoadedDll (
  41. IN PCHAR DllName,
  42. OUT PKLDR_DATA_TABLE_ENTRY *FoundEntry
  43. )
  44. /*++
  45. Routine Description:
  46. This routine scans the loaded DLL list to determine if the specified
  47. DLL has already been loaded. If the DLL has already been loaded, then
  48. its reference count is incremented.
  49. Arguments:
  50. DllName - Supplies a pointer to a null terminated DLL name.
  51. FoundEntry - Supplies a pointer to a variable that receives a pointer
  52. to the matching data table entry.
  53. Return Value:
  54. If the specified DLL has already been loaded, then TRUE is returned.
  55. Otherwise, FALSE is returned.
  56. --*/
  57. {
  58. PKLDR_DATA_TABLE_ENTRY DataTableEntry;
  59. PLIST_ENTRY NextEntry;
  60. //
  61. // Scan the loaded data table list to determine if the specified DLL
  62. // has already been loaded.
  63. //
  64. NextEntry = BlLoaderBlock->LoadOrderListHead.Flink;
  65. while (NextEntry != &BlLoaderBlock->LoadOrderListHead) {
  66. DataTableEntry = CONTAINING_RECORD(NextEntry,
  67. KLDR_DATA_TABLE_ENTRY,
  68. InLoadOrderLinks);
  69. if (BlpCompareDllName(DllName, &DataTableEntry->BaseDllName) != FALSE) {
  70. *FoundEntry = DataTableEntry;
  71. DataTableEntry->LoadCount += 1;
  72. return TRUE;
  73. }
  74. NextEntry = NextEntry->Flink;
  75. }
  76. return FALSE;
  77. }
  78. BOOLEAN
  79. BlpCompareDllName (
  80. IN PCHAR DllName,
  81. IN PUNICODE_STRING UnicodeString
  82. )
  83. /*++
  84. Routine Description:
  85. This routine compares a zero terminated character string with a unicode
  86. string. The UnicodeString's extension is ignored.
  87. Arguments:
  88. DllName - Supplies a pointer to a null terminated DLL name.
  89. UnicodeString - Supplies a pointer to a Unicode string descriptor.
  90. Return Value:
  91. If the specified name matches the Unicode name, then TRUE is returned.
  92. Otherwise, FALSE is returned.
  93. --*/
  94. {
  95. PWSTR Buffer;
  96. ULONG Index;
  97. ULONG Length;
  98. //
  99. // Compute the length of the DLL Name and compare with the length of
  100. // the Unicode name. If the DLL Name is longer, the strings are not
  101. // equal.
  102. //
  103. Length = strlen(DllName);
  104. if ((Length * sizeof(WCHAR)) > UnicodeString->Length) {
  105. return FALSE;
  106. }
  107. //
  108. // Compare the two strings case insensitive, ignoring the Unicode
  109. // string's extension.
  110. //
  111. Buffer = UnicodeString->Buffer;
  112. for (Index = 0; Index < Length; Index += 1) {
  113. if (toupper(*DllName) != toupper((CHAR)*Buffer)) {
  114. return FALSE;
  115. }
  116. DllName += 1;
  117. Buffer += 1;
  118. }
  119. if ((UnicodeString->Length == Length * sizeof(WCHAR)) ||
  120. (*Buffer == L'.')) {
  121. //
  122. // Strings match exactly or match up until the UnicodeString's extension.
  123. //
  124. return(TRUE);
  125. }
  126. return FALSE;
  127. }