home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / patchapi.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  15.2 KB  |  452 lines

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