|
@@ -728,6 +728,16 @@ type
|
|
sh_addralign : longword;
|
|
sh_addralign : longword;
|
|
sh_entsize : longword;
|
|
sh_entsize : longword;
|
|
end;
|
|
end;
|
|
|
|
+ telfproghdr=packed record
|
|
|
|
+ p_type : longword;
|
|
|
|
+ p_offset : longword;
|
|
|
|
+ p_vaddr : longword;
|
|
|
|
+ p_paddr : longword;
|
|
|
|
+ p_filesz : longword;
|
|
|
|
+ p_memsz : longword;
|
|
|
|
+ p_flags : longword;
|
|
|
|
+ p_align : longword;
|
|
|
|
+ end;
|
|
{$endif ELF32 or BEOS}
|
|
{$endif ELF32 or BEOS}
|
|
{$ifdef ELF64}
|
|
{$ifdef ELF64}
|
|
type
|
|
type
|
|
@@ -764,6 +774,17 @@ type
|
|
sh_addralign : int64;
|
|
sh_addralign : int64;
|
|
sh_entsize : int64;
|
|
sh_entsize : int64;
|
|
end;
|
|
end;
|
|
|
|
+
|
|
|
|
+ telfproghdr=packed record
|
|
|
|
+ p_type : longword;
|
|
|
|
+ p_flags : longword;
|
|
|
|
+ p_offset : qword;
|
|
|
|
+ p_vaddr : qword;
|
|
|
|
+ p_paddr : qword;
|
|
|
|
+ p_filesz : qword;
|
|
|
|
+ p_memsz : qword;
|
|
|
|
+ p_align : qword;
|
|
|
|
+ end;
|
|
{$endif ELF64}
|
|
{$endif ELF64}
|
|
|
|
|
|
|
|
|
|
@@ -772,6 +793,8 @@ function OpenElf(var e:TExeFile):boolean;
|
|
var
|
|
var
|
|
elfheader : telfheader;
|
|
elfheader : telfheader;
|
|
elfsec : telfsechdr;
|
|
elfsec : telfsechdr;
|
|
|
|
+ phdr : telfproghdr;
|
|
|
|
+ i : longint;
|
|
begin
|
|
begin
|
|
OpenElf:=false;
|
|
OpenElf:=false;
|
|
{ read and check header }
|
|
{ read and check header }
|
|
@@ -788,6 +811,20 @@ begin
|
|
e.secstrofs:=elfsec.sh_offset;
|
|
e.secstrofs:=elfsec.sh_offset;
|
|
e.sechdrofs:=elfheader.e_shoff;
|
|
e.sechdrofs:=elfheader.e_shoff;
|
|
e.nsects:=elfheader.e_shnum;
|
|
e.nsects:=elfheader.e_shnum;
|
|
|
|
+
|
|
|
|
+ { scan program headers to find the image base address }
|
|
|
|
+ e.processaddress:=High(e.processaddress);
|
|
|
|
+ seek(e.f,elfheader.e_phoff);
|
|
|
|
+ for i:=1 to elfheader.e_phnum do
|
|
|
|
+ begin
|
|
|
|
+ blockread(e.f,phdr,sizeof(phdr));
|
|
|
|
+ if (phdr.p_type = 1 {PT_LOAD}) and (ptruint(phdr.p_vaddr) < e.processaddress) then
|
|
|
|
+ e.processaddress:=phdr.p_vaddr;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ if e.processaddress = High(e.processaddress) then
|
|
|
|
+ e.processaddress:=0;
|
|
|
|
+
|
|
OpenElf:=true;
|
|
OpenElf:=true;
|
|
end;
|
|
end;
|
|
|
|
|