同函数内的变量赋值正常。一赋值给全局变量就出错了type
PProcedure = ^TProcedure;
var
g1: TProcedure;
function .........
var
t1: TProcedure;
p1: PProcedure;
begin
.....
t1 := p1^;//不出错 g1 := p1^;//出错
end; ---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 005A0408 in module 'Project1.exe'. Read of address 00000020'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
PProcedure = ^TProcedure;
var
g1: TProcedure;
function .........
var
t1: TProcedure;
p1: PProcedure;
begin
.....
t1 := p1^;//不出错 g1 := p1^;//出错
end; ---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 005A0408 in module 'Project1.exe'. Read of address 00000020'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
PProcedure = ^Tprocedure;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure TestProcedure;
public
{ Public declarations }
end;var
Form1: TForm1;
gp: TProcedure;
implementation{$R *.dfm}{ TForm1 }procedure TForm1.TestProcedure;
begin
ShowMessage('ok');
end;procedure TForm1.Button1Click(Sender: TObject);
var
p: TProcedure;
pPro: PProcedure;
begin
pPro := PProcedure(@TForm1.TestProcedure);
p := TProcedure(pPro);
p;
gp := TProcedure(pPro);
gp;
end;end.这样做没有任何问题!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
PProcedure = ^Tprocedure;
TTestProcedure = procedure(Par:string); TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
{ Public declarations }
end; procedure TestProcedure(Par: string);var
Form1: TForm1;
gp: TProcedure;
implementation{$R *.dfm}{ TForm1 }procedure TestProcedure(Par: string);
begin
ShowMessage('ok' + Par);
end;procedure TForm1.Button1Click(Sender: TObject);
var
pPro: PProcedure;
begin
pPro := PProcedure(@TestProcedure);
gp := pPro^;
TTestProcedure(gp)('11');
end;end.
if VirtualProtect(pPro, sizeof(PProcedure), PAGE_READWRITE, lpflOldProtect) then showmessage('ok');//修改不成功
WriteProcessMemory(GetCurrentProcess(), pPro, PProcedure(@NewpPro), sizeof(PProcedure), dwSize);这样又成功HOOK到了,执行已经转到新函数了。
真头疼。其实问题就一个,pPro指向的函数地址值怎么保存到全局变量