home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Tools / Ostatní / aPLib v0.26b / examples / delphi / aplib.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-12-15  |  2.7 KB  |  113 lines

  1. (*
  2.  * aPLib compression library  -  the smaller the better :)
  3.  *
  4.  * Delphi interface to aPLib Delphi objects
  5.  *
  6.  * Copyright (c) 1998-2000 by Joergen Ibsen / Jibz
  7.  * All Rights Reserved
  8.  *
  9.  * -> Delphi by Solodovnikov Alexey 21.03.1999 (alenka@mail.line.ru)
  10.  *)
  11.  
  12. unit aPLib;
  13.  
  14. interface
  15.  
  16. uses
  17.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  18.  
  19.  
  20. const
  21.   aP_pack_break    : DWORD = 0;
  22.   aP_pack_continue : DWORD = 1;
  23.  
  24. type
  25.  
  26.  TaPack_Status = function(w1, w2 : DWORD) : DWORD;cdecl;
  27.  TWorkMem      = array[0..640*1024-1] of byte;
  28.  
  29.   TaPLib = class(TComponent)
  30.   private
  31.     FWorkMem      : ^TWorkMem;
  32.     FLength       : DWORD;
  33.     FSource       : Pointer;
  34.     FDestination  : Pointer;
  35.  
  36.   protected
  37.  
  38.   public
  39.  
  40.     CallBack      : TaPack_Status;
  41.  
  42.     procedure Pack;
  43.     procedure DePack;
  44.  
  45.     property  Source      : Pointer  read FSource       write FSource;
  46.     property  Destination : Pointer  read FDestination  write FDestination;
  47.     property  Length      : DWORD    read FLength       write FLength;
  48.  
  49.   published
  50.  
  51.   end;
  52.  
  53.   function _aP_pack(var Source;
  54.                     var Destination;
  55.                     Length : DWORD;
  56.                     var Workmem : TWorkMem;
  57.                     Callback : TaPack_Status) : DWORD;cdecl;
  58.   function _aP_workmem_size(Length : DWORD) : DWORD;cdecl;
  59.   function _aP_depack_asm(var Source, Destination) : DWORD;cdecl;
  60.   function _aP_depack_asm_fast(var Source, Destination) : DWORD;cdecl;
  61.  
  62.   procedure Register;
  63.  
  64. implementation
  65.  
  66.   function _aP_pack(var Source;
  67.                     var Destination;
  68.                     Length      : DWORD;
  69.                     var WorkMem : TWorkMem;
  70.                     CallBack    : TaPack_Status) : DWORD;external;
  71.  
  72.   function _aP_workmem_size(Length : DWORD) : DWORD;external;
  73.  
  74.   function _aP_depack_asm(var Source, Destination) : DWORD;external;
  75.  
  76.   function _aP_depack_asm_fast(var Source, Destination) : DWORD;external;
  77.  
  78. {$L depack.obj}
  79. {$L depackf.obj}
  80. {$L aplib.obj}
  81.  
  82. procedure Register;
  83. begin
  84.   RegisterComponents('Samples', [TaPLib]);
  85. end;
  86.  
  87. procedure TaPLib.Pack;
  88. begin
  89.   if FDestination <> nil then
  90.   begin
  91.      FreeMem(FDestination);
  92.      FDestination := nil;
  93.   end;
  94.  
  95.   GetMem(FDestination,((FLength * 9) div 8) + 16);
  96.   if FDestination = nil then raise Exception.Create('Out of memory');
  97.  
  98.   New(FWorkMem);
  99.   if FWorkMem = nil then raise Exception.Create('Out of memory');
  100.  
  101.   FLength := _ap_pack(FSource^, FDestination^, FLength, FWorkMem^, CallBack);
  102.   Dispose(FWorkMem);
  103. end;
  104.  
  105. procedure TaPLib.DePack;
  106. begin
  107.   if FDestination <> nil then FreeMem(FDestination);
  108.   Getmem(FDestination, 20 * FLength);  // ???
  109.   FLength := _ap_depack_asm_fast(FSource^, FDestination^);
  110. end;
  111.  
  112. end.
  113.