本帖最后由 冥界3大法王 于 2020-2-27 11:37 编辑
懂了,加个判断就行了。
[Delphi] 纯文本查看 复制代码 unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
pFunction = function(): Integer;
var
Form1: TForm1;
function code(): Integer;
function codeEnd(): Integer;
implementation
{$R *.dfm}
function code(): Integer;
var
i, j, k: Integer;
begin
i := 10;
j := 50;
k := i + j;
result := k;
end;
function codeEnd(): Integer;
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
var
func1, func2, func3: pFunction;
myCode: array of char;
codeSize: Integer;
i: Integer;
begin
asm
PUSH EAX;
PUSH EBX;
LEA EAX, codeEnd; {获取codeEnd函数的地址}
LEA EBX, code; {获取code函数的地址}
SUB EAX, EBX; {用codeEnd函数的地址减code函数的地址则可得出code函数的}
{大小,因为codeEnd函数刚好位于codeEnd函数的下面。}
MOV codeSize, EAX; {把code函数的大小保存在变量codeSize中}
POP EBX;
POP EAX;
end;
SetLength(myCode, codeSize);
{下面这段如看不明白请参考我的另一篇文章}
{[url=http://www.cnblogs.com/JiangHuakey/archive/2010/09/25/1834378.html]http://www.cnblogs.com/JiangHuak ... /09/25/1834378.html[/url]}
asm
PUSH ESI;
PUSH EDI;
CLD;
LEA ESI, byte ptr[code];
MOV EDI, myCode;
MOV ECX, codeSize;
REP MOVSB;
POP EDI;
POP ESI;
end;
for i := 0 to HIGH(myCode) - 1 do
begin
// Memo1.Text := Memo1.Text + Format('$%x', [Integer(myCode[i])]);
if Length(Memo1.Text + Format('%x', [Integer(myCode[i])])) > 0 then
begin
// ShowMessage(Memo1.Text + Format('%x', [Integer(myCode[i])]));
if Length(Format('%x', [Integer(myCode[i])])) = 2 then
begin
Memo1.SelLength := 0;
Memo1.SelText := Format('%x ', [Integer(myCode[i])]);
end;
if Length(Format('%x', [Integer(myCode[i])])) = 1 then
begin
Memo1.SelLength := 0;
Memo1.SelText := Format('0%x ', [Integer(myCode[i])]);
end;
end;
end;
func3 := pFunction(myCode);
i := func3;
Edit1.Text := IntToStr(i);
end;
end.
|