2016-09-22 02:02:09 +08:00
|
|
|
unit formCodeGenerator;
|
2016-08-23 22:11:42 +08:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
2016-09-13 11:26:55 +08:00
|
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.ImageList, Vcl.ImgList, cxGraphics, Vcl.StdCtrls,
|
|
|
|
Vcl.ComCtrls, Zydis.InstructionEditor;
|
2016-08-23 22:11:42 +08:00
|
|
|
|
|
|
|
type
|
2016-09-22 02:02:09 +08:00
|
|
|
TfrmCodeGenerator = class(TForm)
|
2016-08-23 22:11:42 +08:00
|
|
|
GroupBox: TGroupBox;
|
|
|
|
btnClose: TButton;
|
|
|
|
btnGenerate: TButton;
|
|
|
|
imgIcons16: TcxImageList;
|
2016-09-13 11:26:55 +08:00
|
|
|
PageControl1: TPageControl;
|
|
|
|
TabSheet1: TTabSheet;
|
|
|
|
GroupBox1: TGroupBox;
|
|
|
|
pbTotalProgress: TProgressBar;
|
|
|
|
Label1: TLabel;
|
|
|
|
pbCurrentOperation: TProgressBar;
|
|
|
|
Label2: TLabel;
|
|
|
|
lblOperationName: TLabel;
|
2016-08-23 22:11:42 +08:00
|
|
|
procedure btnCloseClick(Sender: TObject);
|
|
|
|
procedure btnGenerateClick(Sender: TObject);
|
|
|
|
strict private
|
|
|
|
FEditor: TInstructionEditor;
|
|
|
|
strict private
|
2016-09-13 11:26:55 +08:00
|
|
|
procedure GeneratorWorkStart(Sender: TObject; const OperationName: String;
|
|
|
|
OperationCount, OperationNumber: Integer; MinWorkCount, MaxWorkCount: Integer);
|
2016-08-23 22:11:42 +08:00
|
|
|
procedure GeneratorWork(Sender: TObject; WorkCount: Integer);
|
|
|
|
procedure GeneratorWorkEnd(Sender: TObject);
|
|
|
|
public
|
|
|
|
property Editor: TInstructionEditor read FEditor write FEditor;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2016-09-22 02:02:09 +08:00
|
|
|
frmCodeGenerator: TfrmCodeGenerator;
|
2016-08-23 22:11:42 +08:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2016-09-13 11:26:55 +08:00
|
|
|
Zydis.CodeGenerator, untHelperClasses;
|
2016-08-23 22:11:42 +08:00
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
{ TfrmGenerator }
|
|
|
|
|
2016-09-22 02:02:09 +08:00
|
|
|
procedure TfrmCodeGenerator.btnCloseClick(Sender: TObject);
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
2016-09-22 02:02:09 +08:00
|
|
|
procedure TfrmCodeGenerator.btnGenerateClick(Sender: TObject);
|
2016-08-23 22:11:42 +08:00
|
|
|
var
|
2016-09-13 11:26:55 +08:00
|
|
|
Generator: TCodeGenerator;
|
|
|
|
Statistics: TCodeGeneratorStatistics;
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
2016-09-13 11:26:55 +08:00
|
|
|
pbTotalProgress.Min := 0;
|
|
|
|
pbTotalProgress.Max := 0;
|
|
|
|
pbTotalProgress.Position := 0;
|
|
|
|
Generator := TCodeGenerator.Create;
|
2016-08-23 22:11:42 +08:00
|
|
|
try
|
|
|
|
Generator.OnWorkStart := GeneratorWorkStart;
|
|
|
|
Generator.OnWork := GeneratorWork;
|
|
|
|
Generator.OnWorkEnd := GeneratorWorkEnd;
|
2016-11-12 05:03:26 +08:00
|
|
|
Generator.GenerateCode(FEditor, 'F:\Development\GitHub\zyan-disassembler-engine\', Statistics);
|
2016-09-13 11:26:55 +08:00
|
|
|
// TODO: Display statistics
|
2016-08-23 22:11:42 +08:00
|
|
|
finally
|
|
|
|
Generator.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-09-22 02:02:09 +08:00
|
|
|
procedure TfrmCodeGenerator.GeneratorWork(Sender: TObject; WorkCount: Integer);
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
2016-09-13 11:26:55 +08:00
|
|
|
pbTotalProgress.Position := pbTotalProgress.Max - pbCurrentOperation.Max + WorkCount;
|
|
|
|
pbCurrentOperation.Position := WorkCount;
|
|
|
|
if ((WorkCount mod pbCurrentOperation.Tag) = 0) then
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
|
|
|
Application.ProcessMessages;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-09-22 02:02:09 +08:00
|
|
|
procedure TfrmCodeGenerator.GeneratorWorkEnd(Sender: TObject);
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
2016-09-13 11:26:55 +08:00
|
|
|
lblOperationName.Caption := '';
|
|
|
|
pbTotalProgress.Position := pbTotalProgress.Max;
|
|
|
|
pbCurrentOperation.Position := pbCurrentOperation.Max;
|
|
|
|
Application.ProcessMessages;
|
2016-08-23 22:11:42 +08:00
|
|
|
end;
|
|
|
|
|
2016-09-22 02:02:09 +08:00
|
|
|
procedure TfrmCodeGenerator.GeneratorWorkStart(Sender: TObject; const OperationName: String;
|
2016-09-13 11:26:55 +08:00
|
|
|
OperationCount, OperationNumber: Integer; MinWorkCount, MaxWorkCount: Integer);
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
2016-09-13 11:26:55 +08:00
|
|
|
lblOperationName.Caption := OperationName;
|
|
|
|
pbTotalProgress.Position := pbTotalProgress.Max;
|
|
|
|
pbTotalProgress.Min := pbTotalProgress.Min + MinWorkCount;
|
|
|
|
pbTotalProgress.Max := pbTotalProgress.Max + MaxWorkCount;
|
|
|
|
pbCurrentOperation.Position := MinWorkCount;
|
|
|
|
pbCurrentOperation.Min := MinWorkCount;
|
|
|
|
pbCurrentOperation.Max := MaxWorkCount;
|
|
|
|
if ((MaxWorkCount - MinWorkCount) > 1000) then
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
2016-09-13 11:26:55 +08:00
|
|
|
pbCurrentOperation.Tag := 100;
|
|
|
|
end else if ((MaxWorkCount - MinWorkCount) > 100) then
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
2016-09-13 11:26:55 +08:00
|
|
|
pbCurrentOperation.Tag := 10;
|
|
|
|
end else
|
2016-08-23 22:11:42 +08:00
|
|
|
begin
|
2016-09-13 11:26:55 +08:00
|
|
|
pbCurrentOperation.Tag := 1;
|
2016-08-23 22:11:42 +08:00
|
|
|
end;
|
2016-09-13 11:26:55 +08:00
|
|
|
Application.ProcessMessages;
|
2016-08-23 22:11:42 +08:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|