如何在编译时获取汇编指令的机器代码?

Jos*_*ine 5 delphi assembly basm shellcode

我希望能够将单行ASM转换为shellcode.IE:

CALL EBX
Run Code Online (Sandbox Code Playgroud)

我该怎么做,并且能够正确转换这个shellcode,以便我可以将它存储在delphi应用程序的变量中.IE:

var ShellCodeArray:  array[0..3] of Byte = ($55,$8B,$EC,$81);
Run Code Online (Sandbox Code Playgroud)

klu*_*udg 5

如果我说得对,你想CALL EBX使用Delphi内置汇编程序获得单个汇编程序指令的机器代码.

function CodeSize: Integer;
asm
    lea EAX, @@end
    lea EDX, @@start
    sub EAX, EDX
    JMP @@end
@@start:
    call EBX
@@end:
end;

procedure Code;
asm
    call EBX
end;

function CodeToBytes: TBytes;
var
  I, N: Integer;
  P: PByte;

begin
  N:= CodeSize;
  SetLength(Result, N);
  P:= @Code;
  for I:= 0 to N - 1 do begin
    Result[I]:= P^;
    Inc(P);
  end;
end;
Run Code Online (Sandbox Code Playgroud)