Recent

Author Topic: The use of PInt64 to read integer from memory  (Read 1702 times)

yanes19

  • New Member
  • *
  • Posts: 36
The use of PInt64 to read integer from memory
« on: March 07, 2015, 07:38:54 pm »
Hi , pascal guys  :D ,
 I'm writing a unit to read/write to  Elf Object binary files , ok , I read the 64 bytes into an array of bytes lets call it "ElfHdr",
this is the situation :
Quote
7F 45 4C 46 02 01 01 03 00 00 00 00 00 00 00 00 02 00 3E 00 01 00 00 00 20 F6 59 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00
Now if the bytes from ElfHdr[24..32] should be interpreted as a 64bit  address , I guessed A pointer to an int64  could solve this ,I wrote :
Code: [Select]
function GetEntryPointAddr(ElfHdr : array of Byte):Int64;
var int64Ptr : PInt64;
begin

GetMem(int64Ptr,SizeOf(Int64));
  case ElfHdr[4] of 2 :
    begin
      int64Ptr^ := ElfHdr[24];
      result :=  int64Ptr^ ;
    end;
  end;
end;
   
Where is the wrong step here ? Is there a better way to do ?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12345
  • Debugger - SynEdit - and more
    • wiki
Re: The use of PInt64 to read integer from memory
« Reply #1 on: March 07, 2015, 07:46:01 pm »
Code: [Select]
int64Ptr := @ElfHdr[24];

or

Code: [Select]
  Result := PInt64(@ElfHdr[24])^

yanes19

  • New Member
  • *
  • Posts: 36
Re: The use of PInt64 to read integer from memory
« Reply #2 on: March 07, 2015, 11:39:30 pm »
for i := 0 to 100000000000000000  Do
   SayThankyou('Martin_fr' ,Now);
ShowMessage ('You saved me');

 :D :D :D :D :D :D :D

 

TinyPortal © 2005-2018