home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 February
/
Chip_2000-02_cd.bin
/
zkuste
/
Delphi
/
navody
/
tt
/
objvm.exe
/
UNITS
/
Decomps.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-06-26
|
6KB
|
157 lines
unit Decomps;
interface
uses
Code,OpCodes,SysUtils,ObjList;
type
{TOpDecomp provides interface to decompile operation}
TOpDecomp=class
public
{Code of operation}
OpCode:TOpCode;
{AsString returns string representation of op}
{in given code. C is code, Pos is position of}
{operation being decompiling}
function AsString(c:TCode;Pos:integer):string;virtual;abstract;
{Length returns length of current operation in bytes.}
{Meanings of parameters are same as in AsString function}
function Length(c:TCode;Pos:integer):integer;virtual;abstract;
end;
type TOpCodeDecomp=class(TOpDecomp)
Name:string;
constructor Create(anOpCode:TOpCode;const aName:string);
function AsString(c:TCode;Pos:integer):string;override;
function Length(c:TCode;Pos:integer):integer;override;
end;
type TIntDecomp=class(TOpCodeDecomp)
function AsString(c:TCode;Pos:integer):string;override;
function Length(c:TCode;Pos:integer):integer;override;
end;
type TStrDecomp=class(TOpCodeDecomp)
function AsString(c:TCode;Pos:integer):string;override;
function Length(c:TCode;Pos:integer):integer;override;
end;
type TFloatDecomp=class(TOpCodeDecomp)
function AsString(c:TCode;Pos:integer):string;override;
function Length(c:TCode;Pos:integer):integer;override;
end;
type TBoolDecomp=class(TOpCodeDecomp)
function AsString(c:TCode;Pos:integer):string;override;
function Length(c:TCode;Pos:integer):integer;override;
end;
procedure Register(o:TObjList);
implementation
constructor TOpCodeDecomp.Create;
begin
Inherited Create;
Name:=aName;
OpCode:=anOpCode;
end;
function TOpCodeDecomp.AsString;
begin
Result:=Name;
end;
function TOpCodeDecomp.Length;
begin
Result:=SizeOf(TOpCode);
end;
function TIntDecomp.AsString;
begin
Result:=Inherited AsString(c,Pos)+' '+
IntToStr(c.Int[Pos+inherited Length(c,Pos)]);
end;
function TIntDecomp.Length;
begin
Result:=Inherited Length(c,Pos)+SizeOf(Integer);
end;
function TStrDecomp.AsString;
begin
Result:=Inherited AsString(c,Pos)+''''+
c.Str[Pos+inherited Length(c,Pos)]+'''';
end;
function TStrDecomp.Length;
begin
Result:=Inherited Length(c,Pos)+System.Length(c.Str[Pos+inherited Length(c,Pos)])+1;
end;
function TFloatDecomp.AsString;
begin
Result:=Inherited AsString(c,Pos)+' '+
FloatToStr(c.Num[Pos+inherited Length(c,Pos)]);
end;
function TFloatDecomp.Length;
begin
Result:=Inherited Length(c,Pos)+SizeOf(Extended);
end;
function TBoolDecomp.AsString;
begin
Result:=Inherited AsString(c,Pos);
if c.Int[Pos+inherited Length(c,Pos)]=0 then
Result:=Result+' FALSE'
else
Result:=Result+' TRUE';
end;
function TBoolDecomp.Length;
begin
Result:=Inherited Length(c,Pos)+SizeOf(Integer);
end;
procedure Register(o:TObjList);
begin
With o do
begin
{ Arithmetic operations }
Add(TOpCodeDecomp.Create(ocAdd,'+'));
Add(TOpCodeDecomp.Create(ocSub,'-'));
Add(TOpCodeDecomp.Create(ocMul,'*'));
Add(TOpCodeDecomp.Create(ocDiv,'/'));
Add(TOpCodeDecomp.Create(ocNegate,'NEGATE'));
{ Boolean operations }
Add(TOpCodeDecomp.Create(ocAnd,'AND'));
Add(TOpCodeDecomp.Create(ocOr,'OR'));
Add(TOpCodeDecomp.Create(ocNot,'NOT'));
{Comparison ops}
Add(TOpCodeDecomp.Create(ocEqu,'='));
Add(TOpCodeDecomp.Create(ocNE,'<>'));
Add(TOpCodeDecomp.Create(ocG,'>'));
Add(TOpCodeDecomp.Create(ocL,'<'));
Add(TOpCodeDecomp.Create(ocLE,'<='));
Add(TOpCodeDecomp.Create(ocGE,'>='));
{Value operations }
Add(TOpCodeDecomp.Create(ocGet,'@'));
Add(TOpCodeDecomp.Create(ocSet,'!'));
Add(TOpCodeDecomp.Create(ocExec,'EXEC'));
Add(TOpCodeDecomp.Create(ocEval,'EVAL'));
Add(TOpCodeDecomp.Create(ocGetElem,'[]'));
Add(TOpCodeDecomp.Create(ocRoot,'ROOT'));
{Constant operations }
Add(TStrDecomp.Create(ocStr,'STR#'));
Add(TFloatDecomp.Create(ocFloat,'F#'));
Add(TIntDecomp.Create(ocInt,'#'));
Add(TBoolDecomp.Create(ocBool,'B#'));
{Execution flow operations }
Add(TOpCodeDecomp.Create(ocNop,'NOP'));
Add(TOpCodeDecomp.Create(ocHalt,';'));
Add(TIntDecomp.Create(ocJZ,'JZ'));
Add(TIntDecomp.Create(ocJNZ,'JNZ'));
Add(TIntDecomp.Create(ocJMP,'JMP'));
{Jump if top of Return stack is Zero}
Add(TIntDecomp.Create(ocJRZ,'JRZ'));
{DeCRement top of return stack}
Add(TOpCodeDecomp.Create(ocDCRR,'DCRR'));
{Moves value to return stack}
Add(TOpCodeDecomp.Create(ocToR,'>R'));
{Moves value from return stack to data stack}
Add(TOpCodeDecomp.Create(ocFromR,'R>'));
{Drops value from reaturn stack}
Add(TOpCodeDecomp.Create(ocRDROP,'RDROP'));
end;
end;
end.