How to handle PByte pointer operations in D5 / D7 (operator does not apply to this type of operand)

I am trying to pass DDetourslib in Delphi 5/7. Lines that do not compile have the following pattern:

procedure Decode_J(PInst: PInstruction; Size: Byte);
var
  Value: Int64;
  VA: PByte;
begin
  ...
  VA := PInst^.VirtualAddr + (PInst^.NextInst - PInst^.Addr) // <- compiler error

with compiler error:

[Error] InstDecode.pas (882): the operator is not applicable to this operand Type

PInst^.VirtualAddr, PInst^.NextInst, PInst^.Addrare declared as PByte( PByte = ^Byte)

What can I do to solve this problem?


EDIT:

PInstruction defined as:

  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;
+4
source share
2 answers

Delphi PByte . , , PChar (PAnsiChar PWideChar). Delphi 5, PChar PAnsiChar.

Update

, , , , , .

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);
  ...

, , PAnsiChars, PByte.

+6

Delphi 5 :

procedure Decode_J(PInst: PInstruction; Size: Byte);
var
  Value: Int64;
  VA: PByte;
begin
  ...
  VA := PByte(integer(PInst^.VirtualAddr) + (integer(PInst^.NextInst) - integer(PInst^.Addr))); 

integer() typecasting . 32- .

0

All Articles