zig*_*zig 4 delphi delphi-7 delphi-5
我正在尝试将DDetours
lib 移植到Delphi 5/7.不会编译的行具有以下模式:
procedure Decode_J(PInst: PInstruction; Size: Byte);
var
Value: Int64;
VA: PByte;
begin
...
VA := PInst^.VirtualAddr + (PInst^.NextInst - PInst^.Addr) // <- compiler error
Run Code Online (Sandbox Code Playgroud)
编译错误:
[Error] InstDecode.pas(882):运算符不适用于此操作数类型
PInst^.VirtualAddr, PInst^.NextInst, PInst^.Addr
都被声明为PByte
(PByte = ^Byte
)
我该怎么做才能解决这个问题?
编辑:
PInstruction
定义为:
TInstruction = record
Archi: Byte; { CPUX32 or CPUX64 ! }
AddrMode: Byte; { Address Mode }
Addr: PByte;
VirtualAddr: PByte;
NextInst: PByte; { Pointer to the Next Instruction }
OpCode: Byte; { OpCode Value }
OpType: Byte;
OpKind: Byte;
OpTable: Byte; { tbOneByte,tbTwoByte,... }
OperandFlags: Byte;
Prefixes: Word; { Sets of Prf_xxx }
ModRm: TModRM;
Sib: TSib;
Disp: TDisplacement;
Imm: TImmediat; { Primary Immediat }
ImmEx: TImmediat; { Secondary Immediat if used ! }
Branch: TBranch; { JMP & CALL }
SegReg: Byte; { Segment Register }
Rex: TRex;
Vex: TVex;
LID: TInternalData; { Internal Data }
Errors: Byte;
InstSize: Byte;
Options: Byte;
UserTag: UInt64;
end;
PInstruction = ^TInstruction;
Run Code Online (Sandbox Code Playgroud)
在较新的Delphi版本中,PByte
可以用于指针算术.在此之前,唯一可以做到这一点的类型是PChar
(PAnsiChar
或PWideChar
).在Delphi 5中,PChar
是一个PAnsiChar
.
现在我知道记录的结构并知道你想要实现的目标,我认为你应该做以下事情.
你可以改变所有PBytes
的TInstruction
到PAnsiChar
(或者PChar
,如果你只关心D5),并且也都PBytes
在每一个程序.然后你得到:
PInstruction = ^TInstruction;
TInstruction = record
Archi: Byte; { CPUX32 or CPUX64 ! }
AddrMode: Byte; { Address Mode }
Addr: PAnsiChar;
VirtualAddr: PAnsiChar;
NextInst: PAnsiChar; { Pointer to the Next Instruction }
...
end;
...
procedure Decode_J(PInst: PInstruction; Size: Byte);
var
Value: Int64;
VA: PAnsiChar;
begin
...
VA := PInst^.VirtualAddr + (PInst^.NextInst - PInst^.Addr);
...
Run Code Online (Sandbox Code Playgroud)
但请注意,如果您想使用这些读取或写入字节PAnsiChars
,则必须将它们转换为PByte
.
归档时间: |
|
查看次数: |
621 次 |
最近记录: |