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.

458 lines
15 KiB

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