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.

470 lines
16 KiB

  1. //
  2. // patchapi.h
  3. //
  4. // Interface for creating and applying patches to files.
  5. //
  6. // Copyright (C) Microsoft, 1997-2001.
  7. //
  8. #ifndef _PATCHAPI_H_
  9. #define _PATCHAPI_H_
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. //
  14. // The following constants can be combined and used as the OptionFlags
  15. // parameter in the patch creation apis.
  16. //
  17. #define PATCH_OPTION_USE_BEST 0x00000000 // auto choose best (slower)
  18. #define PATCH_OPTION_USE_LZX_BEST 0x00000003 // auto choose best of LZX A/B (but not large)
  19. #define PATCH_OPTION_USE_LZX_A 0x00000001 // normal
  20. #define PATCH_OPTION_USE_LZX_B 0x00000002 // better on some x86 binaries
  21. #define PATCH_OPTION_USE_LZX_LARGE 0x00000004 // better support for large files (version 1.97 and higher)
  22. #define PATCH_OPTION_NO_BINDFIX 0x00010000 // PE bound imports
  23. #define PATCH_OPTION_NO_LOCKFIX 0x00020000 // PE smashed locks
  24. #define PATCH_OPTION_NO_REBASE 0x00040000 // PE rebased image
  25. #define PATCH_OPTION_FAIL_IF_SAME_FILE 0x00080000 // don't create if same
  26. #define PATCH_OPTION_FAIL_IF_BIGGER 0x00100000 // fail if patch is larger than simply compressing new file (slower)
  27. #define PATCH_OPTION_NO_CHECKSUM 0x00200000 // PE checksum zero
  28. #define PATCH_OPTION_NO_RESTIMEFIX 0x00400000 // PE resource timestamps
  29. #define PATCH_OPTION_NO_TIMESTAMP 0x00800000 // don't store new file timestamp in patch
  30. #define PATCH_OPTION_SIGNATURE_MD5 0x01000000 // use MD5 instead of CRC32
  31. #define PATCH_OPTION_INTERLEAVE_FILES 0x40000000 // better support for large files (version 1.99 and higher)
  32. #define PATCH_OPTION_RESERVED1 0x80000000 // (used internally)
  33. #define PATCH_OPTION_VALID_FLAGS 0xC0FF0007
  34. #define PATCH_SYMBOL_NO_IMAGEHLP 0x00000001 // don't use imagehlp.dll
  35. #define PATCH_SYMBOL_NO_FAILURES 0x00000002 // don't fail patch due to imagehlp failures
  36. #define PATCH_SYMBOL_UNDECORATED_TOO 0x00000004 // after matching decorated symbols, try to match remaining by undecorated names
  37. #define PATCH_SYMBOL_RESERVED1 0x80000000 // (used internally)
  38. //
  39. // The following constants can be combined and used as the ApplyOptionFlags
  40. // parameter in the patch apply and test apis.
  41. //
  42. #define APPLY_OPTION_FAIL_IF_EXACT 0x00000001 // don't copy new file
  43. #define APPLY_OPTION_FAIL_IF_CLOSE 0x00000002 // differ by rebase, bind
  44. #define APPLY_OPTION_TEST_ONLY 0x00000004 // don't create new file
  45. #define APPLY_OPTION_VALID_FLAGS 0x00000007
  46. //
  47. // In addition to standard Win32 error codes, the following error codes may
  48. // be returned via GetLastError() when one of the patch APIs fails.
  49. //
  50. #define ERROR_PATCH_ENCODE_FAILURE 0xC00E3101 // create
  51. #define ERROR_PATCH_INVALID_OPTIONS 0xC00E3102 // create
  52. #define ERROR_PATCH_SAME_FILE 0xC00E3103 // create
  53. #define ERROR_PATCH_RETAIN_RANGES_DIFFER 0xC00E3104 // create
  54. #define ERROR_PATCH_BIGGER_THAN_COMPRESSED 0xC00E3105 // create
  55. #define ERROR_PATCH_IMAGEHLP_FAILURE 0xC00E3106 // create
  56. #define ERROR_PATCH_DECODE_FAILURE 0xC00E4101 // apply
  57. #define ERROR_PATCH_CORRUPT 0xC00E4102 // apply
  58. #define ERROR_PATCH_NEWER_FORMAT 0xC00E4103 // apply
  59. #define ERROR_PATCH_WRONG_FILE 0xC00E4104 // apply
  60. #define ERROR_PATCH_NOT_NECESSARY 0xC00E4105 // apply
  61. #define ERROR_PATCH_NOT_AVAILABLE 0xC00E4106 // apply
  62. typedef BOOL (CALLBACK PATCH_PROGRESS_CALLBACK)(
  63. PVOID CallbackContext,
  64. ULONG CurrentPosition,
  65. ULONG MaximumPosition
  66. );
  67. typedef PATCH_PROGRESS_CALLBACK *PPATCH_PROGRESS_CALLBACK;
  68. typedef BOOL (CALLBACK PATCH_SYMLOAD_CALLBACK)(
  69. IN ULONG WhichFile, // 0 for new file, 1 for first old file, etc
  70. IN LPCSTR SymbolFileName,
  71. IN ULONG SymType, // see SYM_TYPE in imagehlp.h
  72. IN ULONG SymbolFileCheckSum,
  73. IN ULONG SymbolFileTimeDate,
  74. IN ULONG ImageFileCheckSum,
  75. IN ULONG ImageFileTimeDate,
  76. IN PVOID CallbackContext
  77. );
  78. typedef PATCH_SYMLOAD_CALLBACK *PPATCH_SYMLOAD_CALLBACK;
  79. typedef struct _PATCH_IGNORE_RANGE {
  80. ULONG OffsetInOldFile;
  81. ULONG LengthInBytes;
  82. } PATCH_IGNORE_RANGE, *PPATCH_IGNORE_RANGE;
  83. typedef struct _PATCH_RETAIN_RANGE {
  84. ULONG OffsetInOldFile;
  85. ULONG LengthInBytes;
  86. ULONG OffsetInNewFile;
  87. } PATCH_RETAIN_RANGE, *PPATCH_RETAIN_RANGE;
  88. typedef struct _PATCH_OLD_FILE_INFO_A {
  89. ULONG SizeOfThisStruct;
  90. LPCSTR OldFileName;
  91. ULONG IgnoreRangeCount; // maximum 255
  92. PPATCH_IGNORE_RANGE IgnoreRangeArray;
  93. ULONG RetainRangeCount; // maximum 255
  94. PPATCH_RETAIN_RANGE RetainRangeArray;
  95. } PATCH_OLD_FILE_INFO_A, *PPATCH_OLD_FILE_INFO_A;
  96. typedef struct _PATCH_OLD_FILE_INFO_W {
  97. ULONG SizeOfThisStruct;
  98. LPCWSTR OldFileName;
  99. ULONG IgnoreRangeCount; // maximum 255
  100. PPATCH_IGNORE_RANGE IgnoreRangeArray;
  101. ULONG RetainRangeCount; // maximum 255
  102. PPATCH_RETAIN_RANGE RetainRangeArray;
  103. } PATCH_OLD_FILE_INFO_W, *PPATCH_OLD_FILE_INFO_W;
  104. typedef struct _PATCH_OLD_FILE_INFO_H {
  105. ULONG SizeOfThisStruct;
  106. HANDLE OldFileHandle;
  107. ULONG IgnoreRangeCount; // maximum 255
  108. PPATCH_IGNORE_RANGE IgnoreRangeArray;
  109. ULONG RetainRangeCount; // maximum 255
  110. PPATCH_RETAIN_RANGE RetainRangeArray;
  111. } PATCH_OLD_FILE_INFO_H, *PPATCH_OLD_FILE_INFO_H;
  112. typedef struct _PATCH_OLD_FILE_INFO {
  113. ULONG SizeOfThisStruct;
  114. union {
  115. LPCSTR OldFileNameA;
  116. LPCWSTR OldFileNameW;
  117. HANDLE OldFileHandle;
  118. };
  119. ULONG IgnoreRangeCount; // maximum 255
  120. PPATCH_IGNORE_RANGE IgnoreRangeArray;
  121. ULONG RetainRangeCount; // maximum 255
  122. PPATCH_RETAIN_RANGE RetainRangeArray;
  123. } PATCH_OLD_FILE_INFO, *PPATCH_OLD_FILE_INFO;
  124. typedef struct _PATCH_INTERLEAVE_MAP {
  125. ULONG CountRanges;
  126. struct {
  127. ULONG OldOffset;
  128. ULONG OldLength;
  129. ULONG NewLength; // NewOffset implied by sum of previous NewLengths
  130. } Range[ 1 ]; // Variable length (CountRanges)
  131. } PATCH_INTERLEAVE_MAP, *PPATCH_INTERLEAVE_MAP;
  132. typedef struct _PATCH_OPTION_DATA {
  133. ULONG SizeOfThisStruct;
  134. ULONG SymbolOptionFlags; // PATCH_SYMBOL_xxx flags
  135. LPCSTR NewFileSymbolPath; // always ANSI, never Unicode
  136. LPCSTR *OldFileSymbolPathArray; // array[ OldFileCount ]
  137. ULONG ExtendedOptionFlags;
  138. PPATCH_SYMLOAD_CALLBACK SymLoadCallback;
  139. PVOID SymLoadContext;
  140. PPATCH_INTERLEAVE_MAP* InterleaveMapArray; // array[ OldFileCount ]
  141. ULONG MaxLzxWindowSize;
  142. } PATCH_OPTION_DATA, *PPATCH_OPTION_DATA;
  143. //
  144. // Note that PATCH_OPTION_DATA contains LPCSTR paths, and no LPCWSTR (Unicode)
  145. // path argument is available, even when used with one of the Unicode APIs
  146. // such as CreatePatchFileW. This is because the underlying system services
  147. // for symbol file handling (IMAGEHLP.DLL) only support ANSI file/path names.
  148. //
  149. //
  150. // A note about PATCH_RETAIN_RANGE specifiers with multiple old files:
  151. //
  152. // Each old version file must have the same RetainRangeCount, and the same
  153. // retain range LengthInBytes and OffsetInNewFile values in the same order.
  154. // Only the OffsetInOldFile values can differ between old files for retain
  155. // ranges.
  156. //
  157. #ifdef IMPORTING_PATCHAPI_DLL
  158. #define PATCHAPI WINAPI __declspec( dllimport )
  159. #else
  160. #define PATCHAPI WINAPI
  161. #endif
  162. //
  163. // The following prototypes are interface for creating patches from files.
  164. //
  165. BOOL
  166. PATCHAPI
  167. CreatePatchFileA(
  168. IN LPCSTR OldFileName,
  169. IN LPCSTR NewFileName,
  170. OUT LPCSTR PatchFileName,
  171. IN ULONG OptionFlags,
  172. IN PPATCH_OPTION_DATA OptionData // optional
  173. );
  174. BOOL
  175. PATCHAPI
  176. CreatePatchFileW(
  177. IN LPCWSTR OldFileName,
  178. IN LPCWSTR NewFileName,
  179. OUT LPCWSTR PatchFileName,
  180. IN ULONG OptionFlags,
  181. IN PPATCH_OPTION_DATA OptionData // optional
  182. );
  183. BOOL
  184. PATCHAPI
  185. CreatePatchFileByHandles(
  186. IN HANDLE OldFileHandle,
  187. IN HANDLE NewFileHandle,
  188. OUT HANDLE PatchFileHandle,
  189. IN ULONG OptionFlags,
  190. IN PPATCH_OPTION_DATA OptionData // optional
  191. );
  192. BOOL
  193. PATCHAPI
  194. CreatePatchFileExA(
  195. IN ULONG OldFileCount, // maximum 255
  196. IN PPATCH_OLD_FILE_INFO_A OldFileInfoArray,
  197. IN LPCSTR NewFileName,
  198. OUT LPCSTR PatchFileName,
  199. IN ULONG OptionFlags,
  200. IN PPATCH_OPTION_DATA OptionData, // optional
  201. IN PPATCH_PROGRESS_CALLBACK ProgressCallback,
  202. IN PVOID CallbackContext
  203. );
  204. BOOL
  205. PATCHAPI
  206. CreatePatchFileExW(
  207. IN ULONG OldFileCount, // maximum 255
  208. IN PPATCH_OLD_FILE_INFO_W OldFileInfoArray,
  209. IN LPCWSTR NewFileName,
  210. OUT LPCWSTR PatchFileName,
  211. IN ULONG OptionFlags,
  212. IN PPATCH_OPTION_DATA OptionData, // optional
  213. IN PPATCH_PROGRESS_CALLBACK ProgressCallback,
  214. IN PVOID CallbackContext
  215. );
  216. BOOL
  217. PATCHAPI
  218. CreatePatchFileByHandlesEx(
  219. IN ULONG OldFileCount, // maximum 255
  220. IN PPATCH_OLD_FILE_INFO_H OldFileInfoArray,
  221. IN HANDLE NewFileHandle,
  222. OUT HANDLE PatchFileHandle,
  223. IN ULONG OptionFlags,
  224. IN PPATCH_OPTION_DATA OptionData, // optional
  225. IN PPATCH_PROGRESS_CALLBACK ProgressCallback,
  226. IN PVOID CallbackContext
  227. );
  228. BOOL
  229. PATCHAPI
  230. ExtractPatchHeaderToFileA(
  231. IN LPCSTR PatchFileName,
  232. OUT LPCSTR PatchHeaderFileName
  233. );
  234. BOOL
  235. PATCHAPI
  236. ExtractPatchHeaderToFileW(
  237. IN LPCWSTR PatchFileName,
  238. OUT LPCWSTR PatchHeaderFileName
  239. );
  240. BOOL
  241. PATCHAPI
  242. ExtractPatchHeaderToFileByHandles(
  243. IN HANDLE PatchFileHandle,
  244. OUT HANDLE PatchHeaderFileHandle
  245. );
  246. //
  247. // The following prototypes are interface for creating new file from old file
  248. // and patch file. Note that it is possible for the TestApply API to succeed
  249. // but the actual Apply to fail since the TestApply only verifies that the
  250. // old file has the correct CRC without actually applying the patch. The
  251. // TestApply API only requires the patch header portion of the patch file,
  252. // but its CRC must be fixed up.
  253. //
  254. BOOL
  255. PATCHAPI
  256. TestApplyPatchToFileA(
  257. IN LPCSTR PatchFileName,
  258. IN LPCSTR OldFileName,
  259. IN ULONG ApplyOptionFlags
  260. );
  261. BOOL
  262. PATCHAPI
  263. TestApplyPatchToFileW(
  264. IN LPCWSTR PatchFileName,
  265. IN LPCWSTR OldFileName,
  266. IN ULONG ApplyOptionFlags
  267. );
  268. BOOL
  269. PATCHAPI
  270. TestApplyPatchToFileByHandles(
  271. IN HANDLE PatchFileHandle, // requires GENERIC_READ access
  272. IN HANDLE OldFileHandle, // requires GENERIC_READ access
  273. IN ULONG ApplyOptionFlags
  274. );
  275. BOOL
  276. PATCHAPI
  277. ApplyPatchToFileA(
  278. IN LPCSTR PatchFileName,
  279. IN LPCSTR OldFileName,
  280. OUT LPCSTR NewFileName,
  281. IN ULONG ApplyOptionFlags
  282. );
  283. BOOL
  284. PATCHAPI
  285. ApplyPatchToFileW(
  286. IN LPCWSTR PatchFileName,
  287. IN LPCWSTR OldFileName,
  288. OUT LPCWSTR NewFileName,
  289. IN ULONG ApplyOptionFlags
  290. );
  291. BOOL
  292. PATCHAPI
  293. ApplyPatchToFileByHandles(
  294. IN HANDLE PatchFileHandle, // requires GENERIC_READ access
  295. IN HANDLE OldFileHandle, // requires GENERIC_READ access
  296. OUT HANDLE NewFileHandle, // requires GENERIC_READ | GENERIC_WRITE
  297. IN ULONG ApplyOptionFlags
  298. );
  299. BOOL
  300. PATCHAPI
  301. ApplyPatchToFileExA(
  302. IN LPCSTR PatchFileName,
  303. IN LPCSTR OldFileName,
  304. OUT LPCSTR NewFileName,
  305. IN ULONG ApplyOptionFlags,
  306. IN PPATCH_PROGRESS_CALLBACK ProgressCallback,
  307. IN PVOID CallbackContext
  308. );
  309. BOOL
  310. PATCHAPI
  311. ApplyPatchToFileExW(
  312. IN LPCWSTR PatchFileName,
  313. IN LPCWSTR OldFileName,
  314. OUT LPCWSTR NewFileName,
  315. IN ULONG ApplyOptionFlags,
  316. IN PPATCH_PROGRESS_CALLBACK ProgressCallback,
  317. IN PVOID CallbackContext
  318. );
  319. BOOL
  320. PATCHAPI
  321. ApplyPatchToFileByHandlesEx(
  322. IN HANDLE PatchFileHandle,
  323. IN HANDLE OldFileHandle,
  324. OUT HANDLE NewFileHandle,
  325. IN ULONG ApplyOptionFlags,
  326. IN PPATCH_PROGRESS_CALLBACK ProgressCallback,
  327. IN PVOID CallbackContext
  328. );
  329. //
  330. // The following prototypes provide a unique patch "signature" for a given
  331. // file. Consider the case where you have a new foo.dll and the machines
  332. // to be updated with the new foo.dll may have one of three different old
  333. // foo.dll files. Rather than creating a single large patch file that can
  334. // update any of the three older foo.dll files, three separate smaller patch
  335. // files can be created and "named" according to the patch signature of the
  336. // old file. Then the patch applyer application can determine at runtime
  337. // which of the three foo.dll patch files is necessary given the specific
  338. // foo.dll to be updated. If patch files are being downloaded over a slow
  339. // network connection (Internet over a modem), this signature scheme provides
  340. // a mechanism for choosing the correct single patch file to download at
  341. // application time thus decreasing total bytes necessary to download.
  342. //
  343. BOOL
  344. PATCHAPI
  345. GetFilePatchSignatureA(
  346. IN LPCSTR FileName,
  347. IN ULONG OptionFlags,
  348. IN PVOID OptionData,
  349. IN ULONG IgnoreRangeCount,
  350. IN PPATCH_IGNORE_RANGE IgnoreRangeArray,
  351. IN ULONG RetainRangeCount,
  352. IN PPATCH_RETAIN_RANGE RetainRangeArray,
  353. IN ULONG SignatureBufferSize,
  354. OUT PVOID SignatureBuffer
  355. );
  356. BOOL
  357. PATCHAPI
  358. GetFilePatchSignatureW(
  359. IN LPCWSTR FileName,
  360. IN ULONG OptionFlags,
  361. IN PVOID OptionData,
  362. IN ULONG IgnoreRangeCount,
  363. IN PPATCH_IGNORE_RANGE IgnoreRangeArray,
  364. IN ULONG RetainRangeCount,
  365. IN PPATCH_RETAIN_RANGE RetainRangeArray,
  366. IN ULONG SignatureBufferSizeInBytes,
  367. OUT PVOID SignatureBuffer
  368. );
  369. BOOL
  370. PATCHAPI
  371. GetFilePatchSignatureByHandle(
  372. IN HANDLE FileHandle,
  373. IN ULONG OptionFlags,
  374. IN PVOID OptionData,
  375. IN ULONG IgnoreRangeCount,
  376. IN PPATCH_IGNORE_RANGE IgnoreRangeArray,
  377. IN ULONG RetainRangeCount,
  378. IN PPATCH_RETAIN_RANGE RetainRangeArray,
  379. IN ULONG SignatureBufferSize,
  380. OUT PVOID SignatureBuffer
  381. );
  382. //
  383. // Depending on whether UNICODE is defined, map the generic API names to the
  384. // appropriate Unicode or Ansi APIs.
  385. //
  386. #ifdef UNICODE
  387. #define CreatePatchFile CreatePatchFileW
  388. #define CreatePatchFileEx CreatePatchFileExW
  389. #define TestApplyPatchToFile TestApplyPatchToFileW
  390. #define ApplyPatchToFile ApplyPatchToFileW
  391. #define ApplyPatchToFileEx ApplyPatchToFileExW
  392. #define ExtractPatchHeaderToFile ExtractPatchHeaderToFileW
  393. #define GetFilePatchSignature GetFilePatchSignatureW
  394. #else
  395. #define CreatePatchFile CreatePatchFileA
  396. #define CreatePatchFileEx CreatePatchFileExA
  397. #define TestApplyPatchToFile TestApplyPatchToFileA
  398. #define ApplyPatchToFile ApplyPatchToFileA
  399. #define ApplyPatchToFileEx ApplyPatchToFileExA
  400. #define ExtractPatchHeaderToFile ExtractPatchHeaderToFileA
  401. #define GetFilePatchSignature GetFilePatchSignatureA
  402. #endif // UNICODE
  403. #ifdef __cplusplus
  404. }
  405. #endif
  406. #endif // _PATCHAPI_H_