JwaPatchApi.pas
上传用户:davidchvip
上传日期:2009-07-28
资源大小:1749k
文件大小:36k
源码类别:

Windows编程

开发平台:

Delphi

  1. {******************************************************************************}
  2. {                                                                       }
  3. { Creating and applying patches to filesAPI interface Unit for Object Pascal   }
  4. {                                                                       }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft          }
  6. { Corporation. All Rights Reserved.                                            }
  7. {                 }
  8. { The original file is: patchapi.h, released August 2001. The original Pascal  }
  9. { code is: PatchApi.pas, released December 2001. The initial developer of the  }
  10. { Pascal code is Marcel van Brakel (brakelm@chello.nl).                        }
  11. {                                                                              }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001            }
  13. { Marcel van Brakel. All Rights Reserved.                                      }
  14. {                 }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        }
  16. {                }
  17. { You may retrieve the latest version of this file at the Project JEDI home    }
  18. { page, located at http://delphi-jedi.org or my personal homepage located at   }
  19. { http://members.chello.nl/m.vanbrakel2                                        }
  20. {                }
  21. { The contents of this file are used with permission, subject to the Mozilla   }
  22. { Public License Version 1.1 (the "License"); you may not use this file except }
  23. { in compliance with the License. You may obtain a copy of the License at      }
  24. { http://www.mozilla.org/MPL/MPL-1.1.html                                      }
  25. {                                                                              }
  26. { Software distributed under the License is distributed on an "AS IS" basis,   }
  27. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  28. { the specific language governing rights and limitations under the License.    }
  29. {                                                                              }
  30. { Alternatively, the contents of this file may be used under the terms of the  }
  31. { GNU Lesser General Public License (the  "LGPL License"), in which case the   }
  32. { provisions of the LGPL License are applicable instead of those above.        }
  33. { If you wish to allow use of your version of this file only under the terms   }
  34. { of the LGPL License and not to allow others to use your version of this file }
  35. { under the MPL, indicate your decision by deleting  the provisions above and  }
  36. { replace  them with the notice and other provisions required by the LGPL      }
  37. { License.  If you do not delete the provisions above, a recipient may use     }
  38. { your version of this file under either the MPL or the LGPL License.          }
  39. {                 }
  40. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  41. {                 }
  42. {******************************************************************************}
  43. unit JwaPatchApi;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "patchapi.h"'}
  47. {$HPPEMIT ''}
  48. {$I WINDEFINES.INC}
  49. interface
  50. uses
  51.   JwaWinType;
  52. //
  53. //  The following constants can be combined and used as the OptionFlags
  54. //  parameter in the patch creation apis.
  55. //
  56. const
  57.   PATCH_OPTION_USE_BEST = $00000000; // auto choose best (slower)
  58.   {$EXTERNALSYM PATCH_OPTION_USE_BEST}
  59.   PATCH_OPTION_USE_LZX_BEST  = $00000003; // auto choose best of LZX
  60.   {$EXTERNALSYM PATCH_OPTION_USE_LZX_BEST}
  61.   PATCH_OPTION_USE_LZX_A     = $00000001; // normal
  62.   {$EXTERNALSYM PATCH_OPTION_USE_LZX_A}
  63.   PATCH_OPTION_USE_LZX_B     = $00000002; // better on some x86 binaries
  64.   {$EXTERNALSYM PATCH_OPTION_USE_LZX_B}
  65.   PATCH_OPTION_USE_LZX_LARGE = $00000004; // better support for files >8MB
  66.   {$EXTERNALSYM PATCH_OPTION_USE_LZX_LARGE}
  67.   PATCH_OPTION_NO_BINDFIX        = $00010000; // PE bound imports
  68.   {$EXTERNALSYM PATCH_OPTION_NO_BINDFIX}
  69.   PATCH_OPTION_NO_LOCKFIX        = $00020000; // PE smashed locks
  70.   {$EXTERNALSYM PATCH_OPTION_NO_LOCKFIX}
  71.   PATCH_OPTION_NO_REBASE         = $00040000; // PE rebased image
  72.   {$EXTERNALSYM PATCH_OPTION_NO_REBASE}
  73.   PATCH_OPTION_FAIL_IF_SAME_FILE = $00080000; // don't create if same
  74.   {$EXTERNALSYM PATCH_OPTION_FAIL_IF_SAME_FILE}
  75.   PATCH_OPTION_FAIL_IF_BIGGER    = $00100000; // fail if patch is larger than simply compressing new file (slower)
  76.   {$EXTERNALSYM PATCH_OPTION_FAIL_IF_BIGGER}
  77.   PATCH_OPTION_NO_CHECKSUM       = $00200000; // PE checksum zero
  78.   {$EXTERNALSYM PATCH_OPTION_NO_CHECKSUM}
  79.   PATCH_OPTION_NO_RESTIMEFIX     = $00400000; // PE resource timestamps
  80.   {$EXTERNALSYM PATCH_OPTION_NO_RESTIMEFIX}
  81.   PATCH_OPTION_NO_TIMESTAMP      = $00800000; // don't store new file timestamp in patch
  82.   {$EXTERNALSYM PATCH_OPTION_NO_TIMESTAMP}
  83.   PATCH_OPTION_SIGNATURE_MD5     = $01000000; // use MD5 instead of CRC32
  84.   {$EXTERNALSYM PATCH_OPTION_SIGNATURE_MD5}
  85.   PATCH_OPTION_RESERVED1         = DWORD($80000000); // (used internally)
  86.   {$EXTERNALSYM PATCH_OPTION_RESERVED1}
  87.   PATCH_OPTION_VALID_FLAGS = DWORD($80FF0007);
  88.   {$EXTERNALSYM PATCH_OPTION_VALID_FLAGS}
  89.   PATCH_SYMBOL_NO_IMAGEHLP     = $00000001; // don't use imagehlp.dll
  90.   {$EXTERNALSYM PATCH_SYMBOL_NO_IMAGEHLP}
  91.   PATCH_SYMBOL_NO_FAILURES     = $00000002; // don't fail patch due to imagehlp failures
  92.   {$EXTERNALSYM PATCH_SYMBOL_NO_FAILURES}
  93.   PATCH_SYMBOL_UNDECORATED_TOO = $00000004; // after matching decorated symbols, try to match remaining by undecorated names
  94.   {$EXTERNALSYM PATCH_SYMBOL_UNDECORATED_TOO}
  95.   PATCH_SYMBOL_RESERVED1       = DWORD($80000000); // (used internally)
  96.   {$EXTERNALSYM PATCH_SYMBOL_RESERVED1}
  97. //
  98. //  The following constants can be combined and used as the ApplyOptionFlags
  99. //  parameter in the patch apply and test apis.
  100. //
  101.   APPLY_OPTION_FAIL_IF_EXACT = $00000001; // don't copy new file
  102.   {$EXTERNALSYM APPLY_OPTION_FAIL_IF_EXACT}
  103.   APPLY_OPTION_FAIL_IF_CLOSE = $00000002; // differ by rebase, bind
  104.   {$EXTERNALSYM APPLY_OPTION_FAIL_IF_CLOSE}
  105.   APPLY_OPTION_TEST_ONLY     = $00000004; // don't create new file
  106.   {$EXTERNALSYM APPLY_OPTION_TEST_ONLY}
  107.   APPLY_OPTION_VALID_FLAGS   = $00000007;
  108.   {$EXTERNALSYM APPLY_OPTION_VALID_FLAGS}
  109. //
  110. //  In addition to standard Win32 error codes, the following error codes may
  111. //  be returned via GetLastError() when one of the patch APIs fails.
  112. //
  113.   ERROR_PATCH_ENCODE_FAILURE         = DWORD($C00E3101); // create
  114.   {$EXTERNALSYM ERROR_PATCH_ENCODE_FAILURE}
  115.   ERROR_PATCH_INVALID_OPTIONS        = DWORD($C00E3102); // create
  116.   {$EXTERNALSYM ERROR_PATCH_INVALID_OPTIONS}
  117.   ERROR_PATCH_SAME_FILE              = DWORD($C00E3103); // create
  118.   {$EXTERNALSYM ERROR_PATCH_SAME_FILE}
  119.   ERROR_PATCH_RETAIN_RANGES_DIFFER   = DWORD($C00E3104); // create
  120.   {$EXTERNALSYM ERROR_PATCH_RETAIN_RANGES_DIFFER}
  121.   ERROR_PATCH_BIGGER_THAN_COMPRESSED = DWORD($C00E3105); // create
  122.   {$EXTERNALSYM ERROR_PATCH_BIGGER_THAN_COMPRESSED}
  123.   ERROR_PATCH_IMAGEHLP_FAILURE       = DWORD($C00E3106); // create
  124.   {$EXTERNALSYM ERROR_PATCH_IMAGEHLP_FAILURE}
  125.   ERROR_PATCH_DECODE_FAILURE = DWORD($C00E4101); // apply
  126.   {$EXTERNALSYM ERROR_PATCH_DECODE_FAILURE}
  127.   ERROR_PATCH_CORRUPT        = DWORD($C00E4102); // apply
  128.   {$EXTERNALSYM ERROR_PATCH_CORRUPT}
  129.   ERROR_PATCH_NEWER_FORMAT   = DWORD($C00E4103); // apply
  130.   {$EXTERNALSYM ERROR_PATCH_NEWER_FORMAT}
  131.   ERROR_PATCH_WRONG_FILE     = DWORD($C00E4104); // apply
  132.   {$EXTERNALSYM ERROR_PATCH_WRONG_FILE}
  133.   ERROR_PATCH_NOT_NECESSARY  = DWORD($C00E4105); // apply
  134.   {$EXTERNALSYM ERROR_PATCH_NOT_NECESSARY}
  135.   ERROR_PATCH_NOT_AVAILABLE  = DWORD($C00E4106); // apply
  136.   {$EXTERNALSYM ERROR_PATCH_NOT_AVAILABLE}
  137. type
  138.   PATCH_PROGRESS_CALLBACK = function (CallbackContext: PVOID; CurrentPosition, MaximumPosition: ULONG): BOOL; stdcall;
  139.   {$EXTERNALSYM PATCH_PROGRESS_CALLBACK}
  140.   TPatchProgressCallback = PATCH_PROGRESS_CALLBACK;
  141.   PPATCH_PROGRESS_CALLBACK = ^PATCH_PROGRESS_CALLBACK;
  142.   {$EXTERNALSYM PPATCH_PROGRESS_CALLBACK}
  143.   PPatchProgressCallback = PPATCH_PROGRESS_CALLBACK;
  144.   PATCH_SYMLOAD_CALLBACK = function (WhichFile: ULONG; SymbolFileName: LPCSTR; SymType, SymbolFileCheckSum,
  145.     SymbolFileTimeDate, ImageFileCheckSum, ImageFileTimeDate: ULONG; CallbackContext: PVOID): BOOL; stdcall;
  146.   {$EXTERNALSYM PATCH_SYMLOAD_CALLBACK}
  147.   TPatchSymLoadCallback = PATCH_SYMLOAD_CALLBACK;
  148.   PPATCH_SYMLOAD_CALLBACK = ^PATCH_SYMLOAD_CALLBACK;
  149.   {$EXTERNALSYM PPATCH_SYMLOAD_CALLBACK}
  150.   PPatchSymLoadCallback = PPATCH_SYMLOAD_CALLBACK;
  151.   PPATCH_IGNORE_RANGE = ^PATCH_IGNORE_RANGE;
  152.   {$EXTERNALSYM PPATCH_IGNORE_RANGE}
  153.   _PATCH_IGNORE_RANGE = record
  154.     OffsetInOldFile: ULONG;
  155.     LengthInBytes: ULONG;
  156.   end;
  157.   {$EXTERNALSYM _PATCH_IGNORE_RANGE}
  158.   PATCH_IGNORE_RANGE = _PATCH_IGNORE_RANGE;
  159.   {$EXTERNALSYM PATCH_IGNORE_RANGE}
  160.   TPatchIgnoreRange = PATCH_IGNORE_RANGE;
  161.   PPatchIgnoreRange = PPATCH_IGNORE_RANGE;
  162.   PPATCH_RETAIN_RANGE = ^PATCH_RETAIN_RANGE;
  163.   {$EXTERNALSYM PPATCH_RETAIN_RANGE}
  164.   _PATCH_RETAIN_RANGE = record
  165.     OffsetInOldFile: ULONG;
  166.     LengthInBytes: ULONG;
  167.     OffsetInNewFile: ULONG;
  168.   end;
  169.   {$EXTERNALSYM _PATCH_RETAIN_RANGE}
  170.   PATCH_RETAIN_RANGE = _PATCH_RETAIN_RANGE;
  171.   {$EXTERNALSYM PATCH_RETAIN_RANGE}
  172.   TPatchRetainRange = PATCH_RETAIN_RANGE;
  173.   PPatchRetainRange = PPATCH_RETAIN_RANGE;
  174.   PPATCH_OLD_FILE_INFO_A = ^PATCH_OLD_FILE_INFO_A;
  175.   {$EXTERNALSYM PPATCH_OLD_FILE_INFO_A}
  176.   _PATCH_OLD_FILE_INFO_A = record
  177.     SizeOfThisStruct: ULONG;
  178.     OldFileName: LPCSTR;
  179.     IgnoreRangeCount: ULONG; // maximum 255
  180.     IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  181.     RetainRangeCount: ULONG; // maximum 255
  182.     RetainRangeArray: PPATCH_RETAIN_RANGE;
  183.   end;
  184.   {$EXTERNALSYM _PATCH_OLD_FILE_INFO_A}
  185.   PATCH_OLD_FILE_INFO_A = _PATCH_OLD_FILE_INFO_A;
  186.   {$EXTERNALSYM PATCH_OLD_FILE_INFO_A}
  187.   TPatchOldFileInfoA = PATCH_OLD_FILE_INFO_A;
  188.   PPatchOldFileInfoA = PPATCH_OLD_FILE_INFO_A;
  189.   PPATCH_OLD_FILE_INFO_W = ^PATCH_OLD_FILE_INFO_W;
  190.   {$EXTERNALSYM PPATCH_OLD_FILE_INFO_W}
  191.   _PATCH_OLD_FILE_INFO_W = record
  192.     SizeOfThisStruct: ULONG;
  193.     OldFileName: LPCWSTR;
  194.     IgnoreRangeCount: ULONG; // maximum 255
  195.     IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  196.     RetainRangeCount: ULONG; // maximum 255
  197.     RetainRangeArray: PPATCH_RETAIN_RANGE;
  198.   end;
  199.   {$EXTERNALSYM _PATCH_OLD_FILE_INFO_W}
  200.   PATCH_OLD_FILE_INFO_W = _PATCH_OLD_FILE_INFO_W;
  201.   {$EXTERNALSYM PATCH_OLD_FILE_INFO_W}
  202.   TPatchOldFileInfoW = PATCH_OLD_FILE_INFO_W;
  203.   PPatchOldFileInfoW = PPATCH_OLD_FILE_INFO_W;
  204.   PPATCH_OLD_FILE_INFO_H = ^PATCH_OLD_FILE_INFO_H;
  205.   {$EXTERNALSYM PPATCH_OLD_FILE_INFO_H}
  206.   _PATCH_OLD_FILE_INFO_H = record
  207.     SizeOfThisStruct: ULONG;
  208.     OldFileHandle: HANDLE;
  209.     IgnoreRangeCount: ULONG; // maximum 255
  210.     IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  211.     RetainRangeCount: ULONG; // maximum 255
  212.     RetainRangeArray: PPATCH_RETAIN_RANGE;
  213.   end;
  214.   {$EXTERNALSYM _PATCH_OLD_FILE_INFO_H}
  215.   PATCH_OLD_FILE_INFO_H = _PATCH_OLD_FILE_INFO_H;
  216.   {$EXTERNALSYM PATCH_OLD_FILE_INFO_H}
  217.   TPatchOldFileInfoH = PATCH_OLD_FILE_INFO_H;
  218.   PPatchOldFileInfoH = PPATCH_OLD_FILE_INFO_H;
  219.   PPATCH_OLD_FILE_INFO = ^PATCH_OLD_FILE_INFO;
  220.   {$EXTERNALSYM PPATCH_OLD_FILE_INFO}
  221.   _PATCH_OLD_FILE_INFO = record
  222.     SizeOfThisStruct: ULONG;
  223.     Union: record
  224.     case Integer of
  225.       0: (OldFileNameA: LPCSTR);
  226.       1: (OldFileNameW: LPCWSTR);
  227.       2: (OldFileHandle: HANDLE);
  228.     end;
  229.     IgnoreRangeCount: ULONG; // maximum 255
  230.     IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  231.     RetainRangeCount: ULONG; // maximum 255
  232.     RetainRangeArray: PPATCH_RETAIN_RANGE;
  233.   end;
  234.   {$EXTERNALSYM _PATCH_OLD_FILE_INFO}
  235.   PATCH_OLD_FILE_INFO = _PATCH_OLD_FILE_INFO;
  236.   {$EXTERNALSYM PATCH_OLD_FILE_INFO}
  237.   TPatchOldFileInfo = PATCH_OLD_FILE_INFO;
  238.   PPatchOldFileInfo = PPATCH_OLD_FILE_INFO;
  239.   PPATCH_OPTION_DATA = ^PATCH_OPTION_DATA;
  240.   {$EXTERNALSYM PPATCH_OPTION_DATA}
  241.   _PATCH_OPTION_DATA = record
  242.     SizeOfThisStruct: ULONG;
  243.     SymbolOptionFlags: ULONG; // PATCH_SYMBOL_xxx flags
  244.     NewFileSymbolPath: LPCSTR; // always ANSI, never Unicode
  245.     OldFileSymbolPathArray: ^LPCSTR; // array[ OldFileCount ]
  246.     ExtendedOptionFlags: ULONG;
  247.     SymLoadCallback: PATCH_SYMLOAD_CALLBACK;
  248.     SymLoadContext: PVOID;
  249.   end;
  250.   {$EXTERNALSYM _PATCH_OPTION_DATA}
  251.   PATCH_OPTION_DATA = _PATCH_OPTION_DATA;
  252.   {$EXTERNALSYM PATCH_OPTION_DATA}
  253.   TPatchOptionData = PATCH_OPTION_DATA;
  254.   PPatchOptionData = PPATCH_OPTION_DATA;
  255. //
  256. //  Note that PATCH_OPTION_DATA contains LPCSTR paths, and no LPCWSTR (Unicode)
  257. //  path argument is available, even when used with one of the Unicode APIs
  258. //  such as CreatePatchFileW.  This is because the underlying system services
  259. //  for symbol file handling (IMAGEHLP.DLL) only support ANSI file/path names.
  260. //
  261. //
  262. //  A note about PATCH_RETAIN_RANGE specifiers with multiple old files:
  263. //
  264. //  Each old version file must have the same RetainRangeCount, and the same
  265. //  retain range LengthInBytes and OffsetInNewFile values in the same order.
  266. //  Only the OffsetInOldFile values can differ between old files for retain
  267. //  ranges.
  268. //
  269. //
  270. //  The following prototypes are interface for creating patches from files.
  271. //
  272. function CreatePatchFileA(OldFileName: LPCSTR; NewFileName: LPCSTR; PatchFileName: LPCSTR; OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA): BOOL; stdcall;
  273. {$EXTERNALSYM CreatePatchFileA}
  274. function CreatePatchFileW(OldFileName: LPCWSTR; NewFileName: LPCWSTR; PatchFileName: LPCWSTR; OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA): BOOL; stdcall;
  275. {$EXTERNALSYM CreatePatchFileW}
  276. function CreatePatchFileByHandles(OldFileHandle: HANDLE; NewFileHandle: HANDLE; PatchFileHandle: HANDLE; OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA): BOOL; stdcall;
  277. {$EXTERNALSYM CreatePatchFileByHandles}
  278. function CreatePatchFileExA(OldFileCount: ULONG; OldFileInfoArray: PPATCH_OLD_FILE_INFO_A; NewFileName: LPCSTR; PatchFileName: LPCSTR;
  279.   OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  280. {$EXTERNALSYM CreatePatchFileExA}
  281. function CreatePatchFileExW(OldFileCount: ULONG; OldFileInfoArray: PPATCH_OLD_FILE_INFO_W; NewFileName: LPCWSTR; PatchFileName: LPCWSTR;
  282.   OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  283. {$EXTERNALSYM CreatePatchFileExW}
  284. function CreatePatchFileByHandlesEx(OldFileCount: ULONG; OldFileInfoArray: PPATCH_OLD_FILE_INFO_H; NewFileHandle: HANDLE;
  285.   PatchFileHandle: HANDLE; OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  286. {$EXTERNALSYM CreatePatchFileByHandlesEx}
  287. function ExtractPatchHeaderToFileA(PatchFileName: LPCSTR; PatchHeaderFileName: LPCSTR): BOOL; stdcall;
  288. {$EXTERNALSYM ExtractPatchHeaderToFileA}
  289. function ExtractPatchHeaderToFileW(PatchFileName: LPCWSTR; PatchHeaderFileName: LPCWSTR): BOOL; stdcall;
  290. {$EXTERNALSYM ExtractPatchHeaderToFileW}
  291. function ExtractPatchHeaderToFileByHandles(PatchFileHandle: HANDLE; PatchHeaderFileHandle: HANDLE): BOOL; stdcall;
  292. {$EXTERNALSYM ExtractPatchHeaderToFileByHandles}
  293. //
  294. //  The following prototypes are interface for creating new file from old file
  295. //  and patch file.  Note that it is possible for the TestApply API to succeed
  296. //  but the actual Apply to fail since the TestApply only verifies that the
  297. //  old file has the correct CRC without actually applying the patch.  The
  298. //  TestApply API only requires the patch header portion of the patch file,
  299. //  but its CRC must be fixed up.
  300. //
  301. function TestApplyPatchToFileA(PatchFileName: LPCSTR; OldFileName: LPCSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  302. {$EXTERNALSYM TestApplyPatchToFileA}
  303. function TestApplyPatchToFileW(PatchFileName: LPCWSTR; OldFileName: LPCWSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  304. {$EXTERNALSYM TestApplyPatchToFileW}
  305. function TestApplyPatchToFileByHandles(PatchFileHandle: HANDLE; OldFileHandle: HANDLE; ApplyOptionFlags: ULONG): BOOL; stdcall;
  306. {$EXTERNALSYM TestApplyPatchToFileByHandles}
  307. function ApplyPatchToFileA(PatchFileName: LPCSTR; OldFileName: LPCSTR; NewFileName: LPCSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  308. {$EXTERNALSYM ApplyPatchToFileA}
  309. function ApplyPatchToFileW(PatchFileName: LPCWSTR; OldFileName: LPCWSTR; NewFileName: LPCWSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  310. {$EXTERNALSYM ApplyPatchToFileW}
  311. function ApplyPatchToFileByHandles(PatchFileHandle: HANDLE; OldFileHandle: HANDLE; NewFileHandle: HANDLE; ApplyOptionFlags: ULONG): BOOL; stdcall;
  312. {$EXTERNALSYM ApplyPatchToFileByHandles}
  313. function ApplyPatchToFileExA(PatchFileName: LPCSTR; OldFileName: LPCSTR; NewFileName: LPCSTR; ApplyOptionFlags: ULONG;
  314.   ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  315. {$EXTERNALSYM ApplyPatchToFileExA}
  316. function ApplyPatchToFileExW(PatchFileName: LPCWSTR; OldFileName: LPCWSTR; NewFileName: LPCWSTR; ApplyOptionFlags: ULONG;
  317.   ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  318. {$EXTERNALSYM ApplyPatchToFileExW}
  319. function ApplyPatchToFileByHandlesEx(PatchFileHandle: HANDLE; OldFileHandle: HANDLE; NewFileHandle: HANDLE;
  320.   ApplyOptionFlags: ULONG; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  321. {$EXTERNALSYM ApplyPatchToFileByHandlesEx}
  322. //
  323. //  The following prototypes provide a unique patch "signature" for a given
  324. //  file.  Consider the case where you have a new foo.dll and the machines
  325. //  to be updated with the new foo.dll may have one of three different old
  326. //  foo.dll files.  Rather than creating a single large patch file that can
  327. //  update any of the three older foo.dll files, three separate smaller patch
  328. //  files can be created and "named" according to the patch signature of the
  329. //  old file.  Then the patch applyer application can determine at runtime
  330. //  which of the three foo.dll patch files is necessary given the specific
  331. //  foo.dll to be updated.  If patch files are being downloaded over a slow
  332. //  network connection (Internet over a modem), this signature scheme provides
  333. //  a mechanism for choosing the correct single patch file to download at
  334. //  application time thus decreasing total bytes necessary to download.
  335. //
  336. function GetFilePatchSignatureA(FileName: LPCSTR; OptionFlags: ULONG; OptionData: PVOID; IgnoreRangeCount: ULONG; IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  337.   RetainRangeCount: ULONG; RetainRangeArray: PPATCH_RETAIN_RANGE; SignatureBufferSize: ULONG; SignatureBuffer: PVOID): BOOL; stdcall;
  338. {$EXTERNALSYM GetFilePatchSignatureA}
  339. function GetFilePatchSignatureW(FileName: LPCWSTR; OptionFlags: ULONG; OptionData: PVOID; IgnoreRangeCount: ULONG; IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  340.   RetainRangeCount: ULONG; RetainRangeArray: PPATCH_RETAIN_RANGE; SignatureBufferSizeInBytes: ULONG; SignatureBuffer: PVOID): BOOL; stdcall;
  341. {$EXTERNALSYM GetFilePatchSignatureW}
  342. function GetFilePatchSignatureByHandle(FileHandle: HANDLE; OptionFlags: ULONG; OptionData: PVOID; IgnoreRangeCount: ULONG; IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  343.   RetainRangeCount: ULONG; RetainRangeArray: PPATCH_RETAIN_RANGE; SignatureBufferSize: ULONG; SignatureBuffer: PVOID): BOOL; stdcall;
  344. {$EXTERNALSYM GetFilePatchSignatureByHandle}
  345. //
  346. //  Depending on whether UNICODE is defined, map the generic API names to the
  347. //  appropriate Unicode or Ansi APIs.
  348. //
  349. {$IFDEF UNICODE}
  350. function CreatePatchFile(OldFileName: LPCWSTR; NewFileName: LPCWSTR; PatchFileName: LPCWSTR; OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA): BOOL; stdcall;
  351. {$EXTERNALSYM CreatePatchFile}
  352. function CreatePatchFileEx(OldFileCount: ULONG; OldFileInfoArray: PPATCH_OLD_FILE_INFO_W; NewFileName: LPCWSTR; PatchFileName: LPCWSTR;
  353.   OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  354. {$EXTERNALSYM CreatePatchFileEx}
  355. function ExtractPatchHeaderToFile(PatchFileName: LPCWSTR; PatchHeaderFileName: LPCWSTR): BOOL; stdcall;
  356. {$EXTERNALSYM ExtractPatchHeaderToFile}
  357. function TestApplyPatchToFile(PatchFileName: LPCWSTR; OldFileName: LPCWSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  358. {$EXTERNALSYM TestApplyPatchToFile}
  359. function ApplyPatchToFile(PatchFileName: LPCWSTR; OldFileName: LPCWSTR; NewFileName: LPCWSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  360. {$EXTERNALSYM ApplyPatchToFile}
  361. function ApplyPatchToFileEx(PatchFileName: LPCWSTR; OldFileName: LPCWSTR; NewFileName: LPCWSTR; ApplyOptionFlags: ULONG; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  362. {$EXTERNALSYM ApplyPatchToFileEx}
  363. function GetFilePatchSignature(FileName: LPCWSTR; OptionFlags: ULONG; OptionData: PVOID; IgnoreRangeCount: ULONG; IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  364.   RetainRangeCount: ULONG; RetainRangeArray: PPATCH_RETAIN_RANGE; SignatureBufferSizeInBytes: ULONG; SignatureBuffer: PVOID): BOOL; stdcall;
  365. {$EXTERNALSYM GetFilePatchSignature}
  366. {$ELSE}
  367. function CreatePatchFile(OldFileName: LPCSTR; NewFileName: LPCSTR; PatchFileName: LPCSTR; OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA): BOOL; stdcall;
  368. {$EXTERNALSYM CreatePatchFile}
  369. function CreatePatchFileEx(OldFileCount: ULONG; OldFileInfoArray: PPATCH_OLD_FILE_INFO_A; NewFileName: LPCSTR; PatchFileName: LPCSTR;
  370.   OptionFlags: ULONG; OptionData: PPATCH_OPTION_DATA; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  371. {$EXTERNALSYM CreatePatchFileEx}
  372. function ExtractPatchHeaderToFile(PatchFileName: LPCSTR; PatchHeaderFileName: LPCSTR): BOOL; stdcall;
  373. {$EXTERNALSYM ExtractPatchHeaderToFile}
  374. function TestApplyPatchToFile(PatchFileName: LPCSTR; OldFileName: LPCSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  375. {$EXTERNALSYM TestApplyPatchToFile}
  376. function ApplyPatchToFile(PatchFileName: LPCSTR; OldFileName: LPCSTR; NewFileName: LPCSTR; ApplyOptionFlags: ULONG): BOOL; stdcall;
  377. {$EXTERNALSYM ApplyPatchToFile}
  378. function ApplyPatchToFileEx(PatchFileName: LPCSTR; OldFileName: LPCSTR; NewFileName: LPCSTR; ApplyOptionFlags: ULONG; ProgressCallback: PATCH_PROGRESS_CALLBACK; CallbackContext: PVOID): BOOL; stdcall;
  379. {$EXTERNALSYM ApplyPatchToFileEx}
  380. function GetFilePatchSignature(FileName: LPCSTR; OptionFlags: ULONG; OptionData: PVOID; IgnoreRangeCount: ULONG; IgnoreRangeArray: PPATCH_IGNORE_RANGE;
  381.   RetainRangeCount: ULONG; RetainRangeArray: PPATCH_RETAIN_RANGE; SignatureBufferSize: ULONG; SignatureBuffer: PVOID): BOOL; stdcall;
  382. {$EXTERNALSYM GetFilePatchSignature}
  383. {$ENDIF}
  384. implementation
  385. const
  386.   patchapi = 'patchapi.dll'; // todo verify
  387. {$IFDEF DYNAMIC_LINK}
  388. var
  389.   _CreatePatchFileA: Pointer;
  390. function CreatePatchFileA;
  391. begin
  392.   GetProcedureAddress(_CreatePatchFileA, patchapi, 'CreatePatchFileA');
  393.   asm
  394.     mov esp, ebp
  395.     pop ebp
  396.     jmp [_CreatePatchFileA]
  397.   end;
  398. end;
  399. {$ELSE}
  400. function CreatePatchFileA; external patchapi name 'CreatePatchFileA';
  401. {$ENDIF DYNAMIC_LINK}
  402. {$IFDEF DYNAMIC_LINK}
  403. var
  404.   _CreatePatchFileW: Pointer;
  405. function CreatePatchFileW;
  406. begin
  407.   GetProcedureAddress(_CreatePatchFileW, patchapi, 'CreatePatchFileW');
  408.   asm
  409.     mov esp, ebp
  410.     pop ebp
  411.     jmp [_CreatePatchFileW]
  412.   end;
  413. end;
  414. {$ELSE}
  415. function CreatePatchFileW; external patchapi name 'CreatePatchFileW';
  416. {$ENDIF DYNAMIC_LINK}
  417. {$IFDEF DYNAMIC_LINK}
  418. var
  419.   _CreatePatchFileByHandles: Pointer;
  420. function CreatePatchFileByHandles;
  421. begin
  422.   GetProcedureAddress(_CreatePatchFileByHandles, patchapi, 'CreatePatchFileByHandles');
  423.   asm
  424.     mov esp, ebp
  425.     pop ebp
  426.     jmp [_CreatePatchFileByHandles]
  427.   end;
  428. end;
  429. {$ELSE}
  430. function CreatePatchFileByHandles; external patchapi name 'CreatePatchFileByHandles';
  431. {$ENDIF DYNAMIC_LINK}
  432. {$IFDEF DYNAMIC_LINK}
  433. var
  434.   _CreatePatchFileExA: Pointer;
  435. function CreatePatchFileExA;
  436. begin
  437.   GetProcedureAddress(_CreatePatchFileExA, patchapi, 'CreatePatchFileExA');
  438.   asm
  439.     mov esp, ebp
  440.     pop ebp
  441.     jmp [_CreatePatchFileExA]
  442.   end;
  443. end;
  444. {$ELSE}
  445. function CreatePatchFileExA; external patchapi name 'CreatePatchFileExA';
  446. {$ENDIF DYNAMIC_LINK}
  447. {$IFDEF DYNAMIC_LINK}
  448. var
  449.   _CreatePatchFileExW: Pointer;
  450. function CreatePatchFileExW;
  451. begin
  452.   GetProcedureAddress(_CreatePatchFileExW, patchapi, 'CreatePatchFileExW');
  453.   asm
  454.     mov esp, ebp
  455.     pop ebp
  456.     jmp [_CreatePatchFileExW]
  457.   end;
  458. end;
  459. {$ELSE}
  460. function CreatePatchFileExW; external patchapi name 'CreatePatchFileExW';
  461. {$ENDIF DYNAMIC_LINK}
  462. {$IFDEF DYNAMIC_LINK}
  463. var
  464.   _CreatePatchFileByHandlesEx: Pointer;
  465. function CreatePatchFileByHandlesEx;
  466. begin
  467.   GetProcedureAddress(_CreatePatchFileByHandlesEx, patchapi, 'CreatePatchFileByHandlesEx');
  468.   asm
  469.     mov esp, ebp
  470.     pop ebp
  471.     jmp [_CreatePatchFileByHandlesEx]
  472.   end;
  473. end;
  474. {$ELSE}
  475. function CreatePatchFileByHandlesEx; external patchapi name 'CreatePatchFileByHandlesEx';
  476. {$ENDIF DYNAMIC_LINK}
  477. {$IFDEF DYNAMIC_LINK}
  478. var
  479.   _ExtractPatchHeaderToFileA: Pointer;
  480. function ExtractPatchHeaderToFileA;
  481. begin
  482.   GetProcedureAddress(_ExtractPatchHeaderToFileA, patchapi, 'ExtractPatchHeaderToFileA');
  483.   asm
  484.     mov esp, ebp
  485.     pop ebp
  486.     jmp [_ExtractPatchHeaderToFileA]
  487.   end;
  488. end;
  489. {$ELSE}
  490. function ExtractPatchHeaderToFileA; external patchapi name 'ExtractPatchHeaderToFileA';
  491. {$ENDIF DYNAMIC_LINK}
  492. {$IFDEF DYNAMIC_LINK}
  493. var
  494.   _ExtractPatchHeaderToFileW: Pointer;
  495. function ExtractPatchHeaderToFileW;
  496. begin
  497.   GetProcedureAddress(_ExtractPatchHeaderToFileW, patchapi, 'ExtractPatchHeaderToFileW');
  498.   asm
  499.     mov esp, ebp
  500.     pop ebp
  501.     jmp [_ExtractPatchHeaderToFileW]
  502.   end;
  503. end;
  504. {$ELSE}
  505. function ExtractPatchHeaderToFileW; external patchapi name 'ExtractPatchHeaderToFileW';
  506. {$ENDIF DYNAMIC_LINK}
  507. {$IFDEF DYNAMIC_LINK}
  508. var
  509.   _ExtrPatchHdrToFileByHandles: Pointer;
  510. function ExtractPatchHeaderToFileByHandles;
  511. begin
  512.   GetProcedureAddress(_ExtrPatchHdrToFileByHandles, patchapi, 'ExtractPatchHeaderToFileByHandles');
  513.   asm
  514.     mov esp, ebp
  515.     pop ebp
  516.     jmp [_ExtrPatchHdrToFileByHandles]
  517.   end;
  518. end;
  519. {$ELSE}
  520. function ExtractPatchHeaderToFileByHandles; external patchapi name 'ExtractPatchHeaderToFileByHandles';
  521. {$ENDIF DYNAMIC_LINK}
  522. {$IFDEF DYNAMIC_LINK}
  523. var
  524.   _TestApplyPatchToFileA: Pointer;
  525. function TestApplyPatchToFileA;
  526. begin
  527.   GetProcedureAddress(_TestApplyPatchToFileA, patchapi, 'TestApplyPatchToFileA');
  528.   asm
  529.     mov esp, ebp
  530.     pop ebp
  531.     jmp [_TestApplyPatchToFileA]
  532.   end;
  533. end;
  534. {$ELSE}
  535. function TestApplyPatchToFileA; external patchapi name 'TestApplyPatchToFileA';
  536. {$ENDIF DYNAMIC_LINK}
  537. {$IFDEF DYNAMIC_LINK}
  538. var
  539.   _TestApplyPatchToFileW: Pointer;
  540. function TestApplyPatchToFileW;
  541. begin
  542.   GetProcedureAddress(_TestApplyPatchToFileW, patchapi, 'TestApplyPatchToFileW');
  543.   asm
  544.     mov esp, ebp
  545.     pop ebp
  546.     jmp [_TestApplyPatchToFileW]
  547.   end;
  548. end;
  549. {$ELSE}
  550. function TestApplyPatchToFileW; external patchapi name 'TestApplyPatchToFileW';
  551. {$ENDIF DYNAMIC_LINK}
  552. {$IFDEF DYNAMIC_LINK}
  553. var
  554.   _TestApplyPatchToFileByHandles: Pointer;
  555. function TestApplyPatchToFileByHandles;
  556. begin
  557.   GetProcedureAddress(_TestApplyPatchToFileByHandles, patchapi, 'TestApplyPatchToFileByHandles');
  558.   asm
  559.     mov esp, ebp
  560.     pop ebp
  561.     jmp [_TestApplyPatchToFileByHandles]
  562.   end;
  563. end;
  564. {$ELSE}
  565. function TestApplyPatchToFileByHandles; external patchapi name 'TestApplyPatchToFileByHandles';
  566. {$ENDIF DYNAMIC_LINK}
  567. {$IFDEF DYNAMIC_LINK}
  568. var
  569.   _ApplyPatchToFileA: Pointer;
  570. function ApplyPatchToFileA;
  571. begin
  572.   GetProcedureAddress(_ApplyPatchToFileA, patchapi, 'ApplyPatchToFileA');
  573.   asm
  574.     mov esp, ebp
  575.     pop ebp
  576.     jmp [_ApplyPatchToFileA]
  577.   end;
  578. end;
  579. {$ELSE}
  580. function ApplyPatchToFileA; external patchapi name 'ApplyPatchToFileA';
  581. {$ENDIF DYNAMIC_LINK}
  582. {$IFDEF DYNAMIC_LINK}
  583. var
  584.   _ApplyPatchToFileW: Pointer;
  585. function ApplyPatchToFileW;
  586. begin
  587.   GetProcedureAddress(_ApplyPatchToFileW, patchapi, 'ApplyPatchToFileW');
  588.   asm
  589.     mov esp, ebp
  590.     pop ebp
  591.     jmp [_ApplyPatchToFileW]
  592.   end;
  593. end;
  594. {$ELSE}
  595. function ApplyPatchToFileW; external patchapi name 'ApplyPatchToFileW';
  596. {$ENDIF DYNAMIC_LINK}
  597. {$IFDEF DYNAMIC_LINK}
  598. var
  599.   _ApplyPatchToFileByHandles: Pointer;
  600. function ApplyPatchToFileByHandles;
  601. begin
  602.   GetProcedureAddress(_ApplyPatchToFileByHandles, patchapi, 'ApplyPatchToFileByHandles');
  603.   asm
  604.     mov esp, ebp
  605.     pop ebp
  606.     jmp [_ApplyPatchToFileByHandles]
  607.   end;
  608. end;
  609. {$ELSE}
  610. function ApplyPatchToFileByHandles; external patchapi name 'ApplyPatchToFileByHandles';
  611. {$ENDIF DYNAMIC_LINK}
  612. {$IFDEF DYNAMIC_LINK}
  613. var
  614.   _ApplyPatchToFileExA: Pointer;
  615. function ApplyPatchToFileExA;
  616. begin
  617.   GetProcedureAddress(_ApplyPatchToFileExA, patchapi, 'ApplyPatchToFileExA');
  618.   asm
  619.     mov esp, ebp
  620.     pop ebp
  621.     jmp [_ApplyPatchToFileExA]
  622.   end;
  623. end;
  624. {$ELSE}
  625. function ApplyPatchToFileExA; external patchapi name 'ApplyPatchToFileExA';
  626. {$ENDIF DYNAMIC_LINK}
  627. {$IFDEF DYNAMIC_LINK}
  628. var
  629.   _ApplyPatchToFileExW: Pointer;
  630. function ApplyPatchToFileExW;
  631. begin
  632.   GetProcedureAddress(_ApplyPatchToFileExW, patchapi, 'ApplyPatchToFileExW');
  633.   asm
  634.     mov esp, ebp
  635.     pop ebp
  636.     jmp [_ApplyPatchToFileExW]
  637.   end;
  638. end;
  639. {$ELSE}
  640. function ApplyPatchToFileExW; external patchapi name 'ApplyPatchToFileExW';
  641. {$ENDIF DYNAMIC_LINK}
  642. {$IFDEF DYNAMIC_LINK}
  643. var
  644.   _ApplyPatchToFileByHandlesEx: Pointer;
  645. function ApplyPatchToFileByHandlesEx;
  646. begin
  647.   GetProcedureAddress(_ApplyPatchToFileByHandlesEx, patchapi, 'ApplyPatchToFileByHandlesEx');
  648.   asm
  649.     mov esp, ebp
  650.     pop ebp
  651.     jmp [_ApplyPatchToFileByHandlesEx]
  652.   end;
  653. end;
  654. {$ELSE}
  655. function ApplyPatchToFileByHandlesEx; external patchapi name 'ApplyPatchToFileByHandlesEx';
  656. {$ENDIF DYNAMIC_LINK}
  657. {$IFDEF DYNAMIC_LINK}
  658. var
  659.   _GetFilePatchSignatureA: Pointer;
  660. function GetFilePatchSignatureA;
  661. begin
  662.   GetProcedureAddress(_GetFilePatchSignatureA, patchapi, 'GetFilePatchSignatureA');
  663.   asm
  664.     mov esp, ebp
  665.     pop ebp
  666.     jmp [_GetFilePatchSignatureA]
  667.   end;
  668. end;
  669. {$ELSE}
  670. function GetFilePatchSignatureA; external patchapi name 'GetFilePatchSignatureA';
  671. {$ENDIF DYNAMIC_LINK}
  672. {$IFDEF DYNAMIC_LINK}
  673. var
  674.   _GetFilePatchSignatureW: Pointer;
  675. function GetFilePatchSignatureW;
  676. begin
  677.   GetProcedureAddress(_GetFilePatchSignatureW, patchapi, 'GetFilePatchSignatureW');
  678.   asm
  679.     mov esp, ebp
  680.     pop ebp
  681.     jmp [_GetFilePatchSignatureW]
  682.   end;
  683. end;
  684. {$ELSE}
  685. function GetFilePatchSignatureW; external patchapi name 'GetFilePatchSignatureW';
  686. {$ENDIF DYNAMIC_LINK}
  687. {$IFDEF DYNAMIC_LINK}
  688. var
  689.   _GetFilePatchSignatureByHandle: Pointer;
  690. function GetFilePatchSignatureByHandle;
  691. begin
  692.   GetProcedureAddress(_GetFilePatchSignatureByHandle, patchapi, 'GetFilePatchSignatureByHandle');
  693.   asm
  694.     mov esp, ebp
  695.     pop ebp
  696.     jmp [_GetFilePatchSignatureByHandle]
  697.   end;
  698. end;
  699. {$ELSE}
  700. function GetFilePatchSignatureByHandle; external patchapi name 'GetFilePatchSignatureByHandle';
  701. {$ENDIF DYNAMIC_LINK}
  702. {$IFDEF UNICODE}
  703. {$IFDEF DYNAMIC_LINK}
  704. var
  705.   _CreatePatchFile: Pointer;
  706. function CreatePatchFile;
  707. begin
  708.   GetProcedureAddress(_CreatePatchFile, patchapi, 'CreatePatchFileW');
  709.   asm
  710.     mov esp, ebp
  711.     pop ebp
  712.     jmp [_CreatePatchFile]
  713.   end;
  714. end;
  715. {$ELSE}
  716. function CreatePatchFile; external patchapi name 'CreatePatchFileW';
  717. {$ENDIF DYNAMIC_LINK}
  718. {$IFDEF DYNAMIC_LINK}
  719. var
  720.   _CreatePatchFileEx: Pointer;
  721. function CreatePatchFileEx;
  722. begin
  723.   GetProcedureAddress(_CreatePatchFileEx, patchapi, 'CreatePatchFileExW');
  724.   asm
  725.     mov esp, ebp
  726.     pop ebp
  727.     jmp [_CreatePatchFileEx]
  728.   end;
  729. end;
  730. {$ELSE}
  731. function CreatePatchFileEx; external patchapi name 'CreatePatchFileExW';
  732. {$ENDIF DYNAMIC_LINK}
  733. {$IFDEF DYNAMIC_LINK}
  734. var
  735.   _ExtractPatchHeaderToFile: Pointer;
  736. function ExtractPatchHeaderToFile;
  737. begin
  738.   GetProcedureAddress(_ExtractPatchHeaderToFile, patchapi, 'ExtractPatchHeaderToFileW');
  739.   asm
  740.     mov esp, ebp
  741.     pop ebp
  742.     jmp [_ExtractPatchHeaderToFile]
  743.   end;
  744. end;
  745. {$ELSE}
  746. function ExtractPatchHeaderToFile; external patchapi name 'ExtractPatchHeaderToFileW';
  747. {$ENDIF DYNAMIC_LINK}
  748. {$IFDEF DYNAMIC_LINK}
  749. var
  750.   _TestApplyPatchToFile: Pointer;
  751. function TestApplyPatchToFile;
  752. begin
  753.   GetProcedureAddress(_TestApplyPatchToFile, patchapi, 'TestApplyPatchToFileW');
  754.   asm
  755.     mov esp, ebp
  756.     pop ebp
  757.     jmp [_TestApplyPatchToFile]
  758.   end;
  759. end;
  760. {$ELSE}
  761. function TestApplyPatchToFile; external patchapi name 'TestApplyPatchToFileW';
  762. {$ENDIF DYNAMIC_LINK}
  763. {$IFDEF DYNAMIC_LINK}
  764. var
  765.   _ApplyPatchToFile: Pointer;
  766. function ApplyPatchToFile;
  767. begin
  768.   GetProcedureAddress(_ApplyPatchToFile, patchapi, 'ApplyPatchToFileW');
  769.   asm
  770.     mov esp, ebp
  771.     pop ebp
  772.     jmp [_ApplyPatchToFile]
  773.   end;
  774. end;
  775. {$ELSE}
  776. function ApplyPatchToFile; external patchapi name 'ApplyPatchToFileW';
  777. {$ENDIF DYNAMIC_LINK}
  778. {$IFDEF DYNAMIC_LINK}
  779. var
  780.   _ApplyPatchToFileEx: Pointer;
  781. function ApplyPatchToFileEx;
  782. begin
  783.   GetProcedureAddress(_ApplyPatchToFileEx, patchapi, 'ApplyPatchToFileExW');
  784.   asm
  785.     mov esp, ebp
  786.     pop ebp
  787.     jmp [_ApplyPatchToFileEx]
  788.   end;
  789. end;
  790. {$ELSE}
  791. function ApplyPatchToFileEx; external patchapi name 'ApplyPatchToFileExW';
  792. {$ENDIF DYNAMIC_LINK}
  793. {$IFDEF DYNAMIC_LINK}
  794. var
  795.   _GetFilePatchSignature: Pointer;
  796. function GetFilePatchSignature;
  797. begin
  798.   GetProcedureAddress(_GetFilePatchSignature, patchapi, 'GetFilePatchSignatureW');
  799.   asm
  800.     mov esp, ebp
  801.     pop ebp
  802.     jmp [_GetFilePatchSignature]
  803.   end;
  804. end;
  805. {$ELSE}
  806. function GetFilePatchSignature; external patchapi name 'GetFilePatchSignatureW';
  807. {$ENDIF DYNAMIC_LINK}
  808. {$ELSE}
  809. {$IFDEF DYNAMIC_LINK}
  810. var
  811.   _CreatePatchFile: Pointer;
  812. function CreatePatchFile;
  813. begin
  814.   GetProcedureAddress(_CreatePatchFile, patchapi, 'CreatePatchFileA');
  815.   asm
  816.     mov esp, ebp
  817.     pop ebp
  818.     jmp [_CreatePatchFile]
  819.   end;
  820. end;
  821. {$ELSE}
  822. function CreatePatchFile; external patchapi name 'CreatePatchFileA';
  823. {$ENDIF DYNAMIC_LINK}
  824. {$IFDEF DYNAMIC_LINK}
  825. var
  826.   _CreatePatchFileEx: Pointer;
  827. function CreatePatchFileEx;
  828. begin
  829.   GetProcedureAddress(_CreatePatchFileEx, patchapi, 'CreatePatchFileExA');
  830.   asm
  831.     mov esp, ebp
  832.     pop ebp
  833.     jmp [_CreatePatchFileEx]
  834.   end;
  835. end;
  836. {$ELSE}
  837. function CreatePatchFileEx; external patchapi name 'CreatePatchFileExA';
  838. {$ENDIF DYNAMIC_LINK}
  839. {$IFDEF DYNAMIC_LINK}
  840. var
  841.   _ExtractPatchHeaderToFile: Pointer;
  842. function ExtractPatchHeaderToFile;
  843. begin
  844.   GetProcedureAddress(_ExtractPatchHeaderToFile, patchapi, 'ExtractPatchHeaderToFileA');
  845.   asm
  846.     mov esp, ebp
  847.     pop ebp
  848.     jmp [_ExtractPatchHeaderToFile]
  849.   end;
  850. end;
  851. {$ELSE}
  852. function ExtractPatchHeaderToFile; external patchapi name 'ExtractPatchHeaderToFileA';
  853. {$ENDIF DYNAMIC_LINK}
  854. {$IFDEF DYNAMIC_LINK}
  855. var
  856.   _TestApplyPatchToFile: Pointer;
  857. function TestApplyPatchToFile;
  858. begin
  859.   GetProcedureAddress(_TestApplyPatchToFile, patchapi, 'TestApplyPatchToFileA');
  860.   asm
  861.     mov esp, ebp
  862.     pop ebp
  863.     jmp [_TestApplyPatchToFile]
  864.   end;
  865. end;
  866. {$ELSE}
  867. function TestApplyPatchToFile; external patchapi name 'TestApplyPatchToFileA';
  868. {$ENDIF DYNAMIC_LINK}
  869. {$IFDEF DYNAMIC_LINK}
  870. var
  871.   _ApplyPatchToFile: Pointer;
  872. function ApplyPatchToFile;
  873. begin
  874.   GetProcedureAddress(_ApplyPatchToFile, patchapi, 'ApplyPatchToFileA');
  875.   asm
  876.     mov esp, ebp
  877.     pop ebp
  878.     jmp [_ApplyPatchToFile]
  879.   end;
  880. end;
  881. {$ELSE}
  882. function ApplyPatchToFile; external patchapi name 'ApplyPatchToFileA';
  883. {$ENDIF DYNAMIC_LINK}
  884. {$IFDEF DYNAMIC_LINK}
  885. var
  886.   _ApplyPatchToFileEx: Pointer;
  887. function ApplyPatchToFileEx;
  888. begin
  889.   GetProcedureAddress(_ApplyPatchToFileEx, patchapi, 'ApplyPatchToFileExA');
  890.   asm
  891.     mov esp, ebp
  892.     pop ebp
  893.     jmp [_ApplyPatchToFileEx]
  894.   end;
  895. end;
  896. {$ELSE}
  897. function ApplyPatchToFileEx; external patchapi name 'ApplyPatchToFileExA';
  898. {$ENDIF DYNAMIC_LINK}
  899. {$IFDEF DYNAMIC_LINK}
  900. var
  901.   _GetFilePatchSignature: Pointer;
  902. function GetFilePatchSignature;
  903. begin
  904.   GetProcedureAddress(_GetFilePatchSignature, patchapi, 'GetFilePatchSignatureA');
  905.   asm
  906.     mov esp, ebp
  907.     pop ebp
  908.     jmp [_GetFilePatchSignature]
  909.   end;
  910. end;
  911. {$ELSE}
  912. function GetFilePatchSignature; external patchapi name 'GetFilePatchSignatureA';
  913. {$ENDIF DYNAMIC_LINK}
  914. {$ENDIF}
  915. end.