home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / Chip_2000-02_cd.bin / zkuste / Delphi / navody / tt / objvm.exe / UNITS / Decompiler.pas < prev    next >
Pascal/Delphi Source File  |  1998-06-26  |  989b  |  36 lines

  1. unit Decompiler;
  2.  
  3. interface
  4. uses
  5.      Code,Classes,Decomps,ObjList,OpCodes,SysUtils;
  6.   {Decompile code c and add string representation to s }
  7. procedure Decompile(c:TCode;s:TStrings);
  8. implementation
  9. procedure Decompile;
  10.           Var d:TObjList;
  11.               Pos:Integer;
  12.               i:Integer;
  13.               decomp:TOpDecomp;
  14.           begin
  15.             s.Clear;
  16.             d:=TObjList.Create;
  17.             Decomps.Register(d);
  18.             try
  19.               Pos:=0;
  20.               repeat
  21.                 for i:=0 to d.Count-1 do
  22.                 begin
  23.                   Decomp:=d.Obj[i] as TOpDecomp;
  24.                   if Decomp.OpCode=c.Int[Pos] then break;
  25.                 end;
  26.                 s.Add(IntToStr(Pos)+': '+Decomp.AsString(c,Pos));
  27.                 Pos:=Pos+Decomp.Length(c,Pos);
  28.               until c.Int[Pos]=ocHalt;
  29.               d.Free;
  30.             except
  31.               d.Free;
  32.               raise;
  33.             end;
  34.           end;
  35. end.
  36.