Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x86 code generator framework for Delphi

Has anyone come across a framework or library for Delphi to simplify the generation of x86 code? I am not looking for an assembler, but rather a framework that abstracts the code generation process above the low level bits and bytes. Ideally I would like to build on top of an existing library or framework rather than hardcode the logic on a case by case basis.

The initial usage will be to generate small code stubs at runtime similar to the way Delphi dispatches SOAP requests. If I cannot find something I will likely roll my own, but I would hate to reinvent the wheel. Something in "C" might me interesting provided the license will permit translation and use in commercial and open source projects.

Update:

Here is some more context: What I am working toward is runtime implementation of interfaces and/or classes as part of a persistence framework. Something sort of like Java annotation driven persistence (JPA/EJB3) except with a distinctly Delphi flavor. The invocation target is a modular/extensible framework which will implement a generalized persistence model. I need to dispatch and hook method calls based on RTTI and an annotation/attribute model (something similar to InstantObjects metadata) in a very dynamic and fluid manner.

Thanks, David

like image 541
David Taylor Avatar asked Jan 23 '23 13:01

David Taylor


2 Answers

The more I have thought about your question. I am not sure if all you trying to just do Dynamic Method Invocation. Even though your asking about generating x86 code. There are several techiniques that do this.

If you know the signature of the method in question you can do it easily by using a TMethod and setting the method address and data.

procedure TForm8.Button1Click(Sender: TObject);
begin
  Showmessage('Hello1');
end;

procedure TForm8.Button2Click(Sender: TObject);
var
 M : TMethod;
begin
  M.Code := MethodAddress('Button1Click');
  M.Data := Self;
  TNotifyEvent(M)(self);
end;

If you don't know the method signature you can write the class with {$METHODINFO ON} Then use the functionality in ObjAuto.pas to invoke the method.

I have an example in my RTTI Presentation code from DelphiLive on how to do that.

like image 149
Robert Love Avatar answered Jan 29 '23 08:01

Robert Love


According to features of PaxCompiler, you can create stand alone executable files.

like image 41
ErvinS Avatar answered Jan 29 '23 08:01

ErvinS