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.

232 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. strmap.h
  5. Abstract:
  6. Strmap (formally pathmap) is a fast hueristic-based program that
  7. searches strings and attempts to replace substrings when there
  8. are matching substrings in the mapping database.
  9. Author:
  10. Marc R. Whitten (marcw) 20-Mar-1997
  11. Revision History:
  12. Jim Schmidt (jimschm) 08-May-2000 Rewrote mapping, added Flags & ex nodes
  13. Calin Negreanu (calinn) 02-Mar-2000 Ported from win9xupg project
  14. --*/
  15. //
  16. // Constants
  17. //
  18. #define STRMAP_COMPLETE_MATCH_ONLY 0x0001
  19. #define STRMAP_FIRST_CHAR_MUST_MATCH 0x0002
  20. #define STRMAP_RETURN_AFTER_FIRST_REPLACE 0x0004
  21. #define STRMAP_REQUIRE_WACK_OR_NUL 0x0008
  22. //
  23. // Types
  24. //
  25. typedef struct {
  26. BOOL UnicodeData;
  27. //
  28. // The filter can replace NewSubString. (The filter must also
  29. // set NewSubStringSizeInBytes when replacing NewSubString.)
  30. //
  31. union {
  32. struct {
  33. PCWSTR OriginalString;
  34. PCWSTR BeginningOfMatch;
  35. PCWSTR CurrentString;
  36. PCWSTR OldSubString;
  37. PCWSTR NewSubString;
  38. INT NewSubStringSizeInBytes;
  39. } Unicode;
  40. struct {
  41. PCSTR OriginalString;
  42. PCSTR BeginningOfMatch;
  43. PCSTR CurrentString;
  44. PCSTR OldSubString;
  45. PCSTR NewSubString;
  46. INT NewSubStringSizeInBytes;
  47. } Ansi;
  48. };
  49. } REG_REPLACE_DATA, *PREG_REPLACE_DATA;
  50. typedef BOOL(REG_REPLACE_FILTER_PROTOTYPE)(PREG_REPLACE_DATA Data);
  51. typedef REG_REPLACE_FILTER_PROTOTYPE * REG_REPLACE_FILTER;
  52. typedef struct TAG_CHARNODE {
  53. WORD Char;
  54. WORD Flags;
  55. PVOID OriginalStr;
  56. PVOID ReplacementStr;
  57. INT ReplacementBytes;
  58. struct TAG_CHARNODE *NextLevel;
  59. struct TAG_CHARNODE *NextPeer;
  60. } CHARNODE, *PCHARNODE;
  61. typedef struct {
  62. CHARNODE Node;
  63. REG_REPLACE_FILTER Filter;
  64. ULONG_PTR ExtraData;
  65. } CHARNODEEX, *PCHARNODEEX;
  66. typedef struct {
  67. PMHANDLE Pool;
  68. PCHARNODE FirstLevelRoot;
  69. BOOL UsesExNode;
  70. BOOL UsesFilter;
  71. BOOL UsesExtraData;
  72. } MAPSTRUCT, *PMAPSTRUCT;
  73. //
  74. // Macros
  75. //
  76. // None
  77. //
  78. // APIs
  79. //
  80. PMAPSTRUCT
  81. CreateStringMappingEx (
  82. IN BOOL UsesFilter,
  83. IN BOOL UsesExtraData
  84. );
  85. #define CreateStringMapping() CreateStringMappingEx(FALSE,FALSE)
  86. VOID
  87. DestroyStringMapping (
  88. IN PMAPSTRUCT Map
  89. );
  90. VOID
  91. AddStringMappingPairExA (
  92. IN OUT PMAPSTRUCT Map,
  93. IN PCSTR Old,
  94. IN PCSTR New,
  95. IN REG_REPLACE_FILTER Filter, OPTIONAL
  96. IN ULONG_PTR ExtraData, OPTIONAL
  97. IN DWORD Flags
  98. );
  99. #define AddStringMappingPairA(Map,Old,New) AddStringMappingPairExA(Map,Old,New,NULL,0,0)
  100. VOID
  101. AddStringMappingPairExW (
  102. IN OUT PMAPSTRUCT Map,
  103. IN PCWSTR Old,
  104. IN PCWSTR New,
  105. IN REG_REPLACE_FILTER Filter, OPTIONAL
  106. IN ULONG_PTR ExtraData, OPTIONAL
  107. IN DWORD Flags
  108. );
  109. #define AddStringMappingPairW(Map,Old,New) AddStringMappingPairExW(Map,Old,New,NULL,0,0)
  110. BOOL
  111. MappingSearchAndReplaceExA (
  112. IN PMAPSTRUCT Map,
  113. IN PCSTR SrcBuffer,
  114. OUT PSTR Buffer, // can be the same as SrcBuffer
  115. IN INT InboundBytes, OPTIONAL
  116. OUT PINT OutboundBytesPtr, OPTIONAL
  117. IN INT MaxSizeInBytes,
  118. IN DWORD Flags,
  119. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  120. OUT PCSTR *EndOfString OPTIONAL
  121. );
  122. #define MappingSearchAndReplaceA(map,buffer,maxbytes) MappingSearchAndReplaceExA(map,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  123. BOOL
  124. MappingSearchAndReplaceExW (
  125. IN PMAPSTRUCT Map,
  126. IN PCWSTR SrcBuffer,
  127. OUT PWSTR Buffer, // can be the same as SrcBuffer
  128. IN INT InboundBytes, OPTIONAL
  129. OUT PINT OutboundBytes, OPTIONAL
  130. IN INT MaxSizeInBytes,
  131. IN DWORD Flags,
  132. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  133. OUT PCWSTR *EndOfString OPTIONAL
  134. );
  135. #define MappingSearchAndReplaceW(map,buffer,maxbytes) MappingSearchAndReplaceExW(map,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  136. BOOL
  137. MappingMultiTableSearchAndReplaceExA (
  138. IN PMAPSTRUCT *MapArray,
  139. IN UINT MapArrayCount,
  140. IN PCSTR SrcBuffer,
  141. OUT PSTR Buffer, // can be the same as SrcBuffer
  142. IN INT InboundBytes, OPTIONAL
  143. OUT PINT OutboundBytesPtr, OPTIONAL
  144. IN INT MaxSizeInBytes,
  145. IN DWORD Flags,
  146. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  147. OUT PCSTR *EndOfString OPTIONAL
  148. );
  149. #define MappingMultiTableSearchAndReplaceA(array,count,buffer,maxbytes) \
  150. MappingMultiTableSearchAndReplaceExA(array,count,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  151. BOOL
  152. MappingMultiTableSearchAndReplaceExW (
  153. IN PMAPSTRUCT *MapArray,
  154. IN UINT MapArrayCount,
  155. IN PCWSTR SrcBuffer,
  156. OUT PWSTR Buffer, // can be the same as SrcBuffer
  157. IN INT InboundBytes, OPTIONAL
  158. OUT PINT OutboundBytes, OPTIONAL
  159. IN INT MaxSizeInBytes,
  160. IN DWORD Flags,
  161. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  162. OUT PCWSTR *EndOfString OPTIONAL
  163. );
  164. #define MappingMultiTableSearchAndReplaceW(array,count,buffer,maxbytes) \
  165. MappingMultiTableSearchAndReplaceExW(array,count,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  166. //
  167. // Macros
  168. //
  169. #ifdef UNICODE
  170. #define AddStringMappingPairEx AddStringMappingPairExW
  171. #define AddStringMappingPair AddStringMappingPairW
  172. #define MappingSearchAndReplaceEx MappingSearchAndReplaceExW
  173. #define MappingSearchAndReplace MappingSearchAndReplaceW
  174. #define MappingMultiTableSearchAndReplaceEx MappingMultiTableSearchAndReplaceExW
  175. #define MappingMultiTableSearchAndReplace MappingMultiTableSearchAndReplaceW
  176. #else
  177. #define AddStringMappingPairEx AddStringMappingPairExA
  178. #define AddStringMappingPair AddStringMappingPairA
  179. #define MappingSearchAndReplaceEx MappingSearchAndReplaceExA
  180. #define MappingSearchAndReplace MappingSearchAndReplaceA
  181. #define MappingMultiTableSearchAndReplaceEx MappingMultiTableSearchAndReplaceExA
  182. #define MappingMultiTableSearchAndReplace MappingMultiTableSearchAndReplaceA
  183. #endif