一
一伊
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,TypInfo,IntfInfo;
type
{$M+}
ITestInterface=Interface
['{F3338FF9-C31C-43D8-8C39-754E7A39DBDD}']
function SayHello(s:String): String;stdcall;
function SayHello2(s:String;v:Integer;var sv:String):String;stdcall;
end;
{$M-}
TInvokerTest=Class(TInterfacedObject,ITestInterface)
private
FStr: String;
public
function SayHello(s: String):String;stdcall;
function SayHello2(s: String;v:Integer;var sv:String):String;stdcall;
end;
TMainForm = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure Invoker;stdcall;
function GetCallPointer(vObj: TObject;MethodName: String)ointer;
end;
var
MainForm: TMainForm;
CallSelf: Pointer;
CallAddr: Pointer;
Params: array of Pointer;
RetParam: Integer;
InterfaceInfo: PTypeInfo;
procedure ptRegisterInvokableInterface(AInterfaceInfo: PTypeInfo);
implementation
{$R *.dfm}
procedure ptRegisterInvokableInterface(AInterfaceInfo: PTypeInfo);
begin
InterfaceInfo:=AInterfaceInfo;
end;
function TMainForm.GetCallPointer(vObj: TObject;MethodName: String)ointer;
function GetMethodIndex: Integer;
Var
IntfData: TIntfMetaData;
I,MethodIndex: Integer;
begin
GetIntfMetaData(InterfaceInfo,IntfData);
MethodIndex:=-1;
for I:=0 to High(IntfData.MDA)do
begin
if IntfData.MDA.Name=MethodName then
begin
MethodIndex:=I;
break;
end;
end;
Result:=MethodIndex;
end;
Var
MethodIndex: Integer;
TypeData: PTypeData;
pIntf: Pointer;
begin
MethodIndex:=GetMethodIndex;
if MethodIndex=-1 then
Result:=nil;
TypeData:=GetTypeData(InterfaceInfo);
if Supports(vObj,TypeData.Guid,pIntf) then
Result:=PPointer(Integer(Pointer(pIntf)^)+12+(MethodIndex*4))^;
end;
//////////////////////////////////////////////
//蓝色开始位置!
//////////////////////////////////////////////
[blue]procedure TMainForm.Invoker;
Var
I,Max: Integer;
ExBp: Integer;
asm
mov eax,[Params];
Call System.@DynArrayHigh;
test eax,eax;
jl @L2;
inc eax;
mov [Max],eax;
mov ,$00000000;
@L1:
mov eax,[Params];
mov edx,;
mov eax,[eax+edx*4];
push [eax];
inc dword ptr ;
dec dword ptr[Max];
jnz @L1;
@L2:
push CallSelf;
push [RetParam];
Call [CallAddr];
@L3:
end;
[/blue]
//////////////////////////////////////////////
//蓝色结束位置! 谢谢了
//////////////////////////////////////////////
function TInvokerTest.SayHello(s:String):string;
begin
FStr:=s;
ShowMessage(s);
Result:='Hello! I am Return';
end;
function TInvokerTest.SayHello2(s:string;v:Integer;var sv:string):string;
begin
ShowMessage(s);
Result:='test';
end;
procedure TMainForm.Button2Click(Sender: TObject);
Var
s,s1: String;
vCall: Pointer;
vObj: TInvokerTest;
p2: Pointer;
begin
s:='Hello Param';
s1:='ddsfjk';
SetLength(Params,1);
Params[0]:=@s;
RetParam:=Integer(@s1);
vObj:=TInvokerTest.Create;
CallAddr:=GetCallPointer(vObj,'SayHello');
CallSelf:=Pointer(Integer(Pointer(vObj))+16);
Invoker;
Showmessage(Pchar(Pointer(RetParam)^));
end;
Initialization
ptRegisterInvokableInterface(TypeInfo(ITestInterface));
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,TypInfo,IntfInfo;
type
{$M+}
ITestInterface=Interface
['{F3338FF9-C31C-43D8-8C39-754E7A39DBDD}']
function SayHello(s:String): String;stdcall;
function SayHello2(s:String;v:Integer;var sv:String):String;stdcall;
end;
{$M-}
TInvokerTest=Class(TInterfacedObject,ITestInterface)
private
FStr: String;
public
function SayHello(s: String):String;stdcall;
function SayHello2(s: String;v:Integer;var sv:String):String;stdcall;
end;
TMainForm = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure Invoker;stdcall;
function GetCallPointer(vObj: TObject;MethodName: String)ointer;
end;
var
MainForm: TMainForm;
CallSelf: Pointer;
CallAddr: Pointer;
Params: array of Pointer;
RetParam: Integer;
InterfaceInfo: PTypeInfo;
procedure ptRegisterInvokableInterface(AInterfaceInfo: PTypeInfo);
implementation
{$R *.dfm}
procedure ptRegisterInvokableInterface(AInterfaceInfo: PTypeInfo);
begin
InterfaceInfo:=AInterfaceInfo;
end;
function TMainForm.GetCallPointer(vObj: TObject;MethodName: String)ointer;
function GetMethodIndex: Integer;
Var
IntfData: TIntfMetaData;
I,MethodIndex: Integer;
begin
GetIntfMetaData(InterfaceInfo,IntfData);
MethodIndex:=-1;
for I:=0 to High(IntfData.MDA)do
begin
if IntfData.MDA.Name=MethodName then
begin
MethodIndex:=I;
break;
end;
end;
Result:=MethodIndex;
end;
Var
MethodIndex: Integer;
TypeData: PTypeData;
pIntf: Pointer;
begin
MethodIndex:=GetMethodIndex;
if MethodIndex=-1 then
Result:=nil;
TypeData:=GetTypeData(InterfaceInfo);
if Supports(vObj,TypeData.Guid,pIntf) then
Result:=PPointer(Integer(Pointer(pIntf)^)+12+(MethodIndex*4))^;
end;
//////////////////////////////////////////////
//蓝色开始位置!
//////////////////////////////////////////////
[blue]procedure TMainForm.Invoker;
Var
I,Max: Integer;
ExBp: Integer;
asm
mov eax,[Params];
Call System.@DynArrayHigh;
test eax,eax;
jl @L2;
inc eax;
mov [Max],eax;
mov ,$00000000;
@L1:
mov eax,[Params];
mov edx,;
mov eax,[eax+edx*4];
push [eax];
inc dword ptr ;
dec dword ptr[Max];
jnz @L1;
@L2:
push CallSelf;
push [RetParam];
Call [CallAddr];
@L3:
end;
[/blue]
//////////////////////////////////////////////
//蓝色结束位置! 谢谢了
//////////////////////////////////////////////
function TInvokerTest.SayHello(s:String):string;
begin
FStr:=s;
ShowMessage(s);
Result:='Hello! I am Return';
end;
function TInvokerTest.SayHello2(s:string;v:Integer;var sv:string):string;
begin
ShowMessage(s);
Result:='test';
end;
procedure TMainForm.Button2Click(Sender: TObject);
Var
s,s1: String;
vCall: Pointer;
vObj: TInvokerTest;
p2: Pointer;
begin
s:='Hello Param';
s1:='ddsfjk';
SetLength(Params,1);
Params[0]:=@s;
RetParam:=Integer(@s1);
vObj:=TInvokerTest.Create;
CallAddr:=GetCallPointer(vObj,'SayHello');
CallSelf:=Pointer(Integer(Pointer(vObj))+16);
Invoker;
Showmessage(Pchar(Pointer(RetParam)^));
end;
Initialization
ptRegisterInvokableInterface(TypeInfo(ITestInterface));
end.