Page 1 of 1

TIntelRecord and TVMProcedure Usage?

Posted: Tue Sep 30, 2008 6:22 pm
by lostpotential
Hi...

I was looking over the script documentation and two of the objects/classes looked interesting but i'm not sure what they do.

TIntelRecord and TVMProcedure... what are these and how are they used? Can you give us more information about what these classes are and what they their methods can do?

Thanks!

Posted: Wed Oct 01, 2008 3:08 am
by Admin
All properties and methods of this classes is specified in help file on page "VMProtect classes". How you can use this classes - see examples in folder "Examples\Scripts".

Code from "Examples\Scripts\VMClasses\Project1.vms":

Code: Select all

procedure OnBeforeCompilation;
var I,J,K: Integer;
    FileName,S: String;
    P: TVMProcedure;
    Lines: TStringList;
begin 
  Lines:=TStringList.Create;
  try
   for K:=0 to VMProtector.Count-1 do
    begin
     P:=VMProtector.Procedures[K];
     Lines.Add('//');
     Lines.Add('// procedure '+P.Name);

     if P.IncludedInCompilation then S:='True'
                                else S:='False';
     Lines.Add('// IncludedInCompilation = '+S);
     
     case P.CompilationType of
      ctMutation: S:='Mutation';
      ctVirtualization: S:='Virtualization';
      ctUltra: S:='Ultra';
     else
      S:='Unknown';
     end; 
     Lines.Add('// CompilationType = '+S);
     
     case P.CodeType of
      otCode: S:='Code';
      otMarker: S:='Marker';
      otString: S:='String';
     else
      S:='Unknown';
     end; 
     Lines.Add('// CodeType = '+S);
     Lines.Add('//');
     
     for I:=0 to P.Count-1 do
      with P.Records[I] do
       begin
        S:='';
        for J:=0 to DumpLength-1 do
         S:=S+Format('%.2x',[Dump[J]]);
        while Length(S)<24 do
         S:=S+'  '; 
        Lines.Add(Format('%.8x %s %s',[Address,S,CommandText]));
       end;
    end;   
                 
   FileName:=ChangeFileExt(VMProtector.InputFileName,'.txt');  
   Lines.SaveToFile(FileName);
  finally    
   Lines.Free;
  end;  
  
  MsgBox('Functions are saved in file:'#13+FileName,'VMProtect Script',MB_OK or MB_ICONINFORMATION);
end;

Posted: Wed Oct 01, 2008 4:46 am
by lostpotential
What about TIntelRecord.ReadFromFile... how exactly does this work and what does it do? I didnt see a description for it in the help file, only the entry in the class.

Thanks for the example above. That explains most of the class really well.

Posted: Wed Oct 01, 2008 7:36 am
by Admin
lostpotential wrote:What about TIntelRecord.ReadFromFile... how exactly does this work and what does it do?
Code from "Examples\Scripts\UseExtMarkers\Project1.vms":

Code: Select all

procedure OnBeforeCompilation;
var R:TIntelRecord;
    CompilationType:TCompilationType;
    Ptr:Int64;
    I:Integer;
    S:String;
begin
  R:=TIntelRecord.Create(nil);
  with VMProtector do
   for I:=0 to InputFile.MapRecords.Count-1 do
    with InputFile.MapRecords.Items[I] do
     if CodeType=otMarker then
      begin
       Ptr:=Address+$12; // $12 - size of VMProtectBegin
       R.ReadFromFile(InputFile,Ptr);
       S:=R.CommandText;
       if S='lea eax, [eax]' then
        CompilationType:=ctMutation
       else
       if S='lea ebx, [ebx]' then
        CompilationType:=ctUltra
       else
        CompilationType:=ctVirtualization;
       AddByAddress(Address,CompilationType,True);
      end;
  R.Free;
end;