gpt4 book ai didi

delphi - 如何处理 D5/D7 中的 PByte 指针操作(运算符不适用于该操作数类型)

转载 作者:行者123 更新时间:2023-12-03 15:24:51 24 4
gpt4 key购买 nike

我正在尝试移植 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

编译器错误:

[Error] InstDecode.pas(882): Operator not applicable to this operand type

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;

最佳答案

在较新的 Delphi 版本中,PByte 可用于指针算术。在此之前,唯一可以做到这一点的类型是 PChar(PAnsiCharPWideChar)。在 Delphi 5 中,PCharPAnsiChar

更新

现在我知道了记录的结构并知道你想要实现什么,我认为你应该执行以下操作。

您可以将 TInstruction 中的所有 PBytes 更改为 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);
...

但请注意,如果您想使用这些 PAnsiChars 读取或写入字节,则必须将它们转换为 PByte

关于delphi - 如何处理 D5/D7 中的 PByte 指针操作(运算符不适用于该操作数类型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38371432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com