2011-04-27 19:21:31 +02:00
|
|
|
;
|
2024-01-29 19:59:16 +01:00
|
|
|
; Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
|
2011-04-27 19:21:31 +02:00
|
|
|
; Copyright (c) 2011, Hewlett-Packard Company. All rights reserved.<BR>
|
|
|
|
;
|
2019-04-04 01:03:38 +02:00
|
|
|
; SPDX-License-Identifier: BSD-2-Clause-Patent
|
2011-04-27 19:21:31 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
LOCAL &imgstart &filehdrstart &debugdirentryrva &debugtype &debugrva &dwarfsig &baseofcode &baseofdata &elfbase &elfpath &pathoffset
|
|
|
|
ENTRY &imgstart
|
|
|
|
|
|
|
|
&imgstart=&imgstart
|
|
|
|
print "PE32 image found at &imgstart"
|
|
|
|
|
2024-01-29 19:59:16 +01:00
|
|
|
; offset from dos hdr to PE file hdr (i.e. 'PE\0\0' signature)
|
2011-04-27 19:21:31 +02:00
|
|
|
&filehdrstart=&imgstart+Data.Long(c:&imgstart+0x3C)
|
|
|
|
|
|
|
|
; offset to debug dir in PE hdrs
|
2024-01-29 19:59:16 +01:00
|
|
|
&debugdirentryrva=Data.Long(c:&imgstart+0xf10)
|
2011-04-27 19:21:31 +02:00
|
|
|
if &debugdirentryrva==0
|
|
|
|
(
|
|
|
|
print "no debug dir for image at &imgstart"
|
|
|
|
enddo
|
|
|
|
)
|
|
|
|
|
|
|
|
&debugtype=Data.Long(c:&imgstart+&debugdirentryrva+0xc)
|
|
|
|
if (&debugtype!=0xdf)&&(&debugtype!=0x02)
|
|
|
|
(
|
|
|
|
print "debug type is not dwarf for image at &imgstart, it's &debugtype"
|
|
|
|
enddo
|
|
|
|
)
|
|
|
|
|
|
|
|
&debugrva=Data.Long(c:&imgstart+&debugdirentryrva+0x14)
|
|
|
|
&dwarfsig=Data.Long(c:&imgstart+&debugrva)
|
|
|
|
|
|
|
|
if &dwarfsig==0x66727764
|
|
|
|
(
|
|
|
|
&pathoffset=0xc
|
|
|
|
)
|
|
|
|
else
|
|
|
|
(
|
|
|
|
if &dwarfsig==0x3031424E
|
|
|
|
(
|
|
|
|
&pathoffset=0x10
|
|
|
|
)
|
|
|
|
else
|
|
|
|
(
|
|
|
|
print "debug signature not found for image at &imgstart, its &dwarfsig"
|
|
|
|
enddo
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
&elfpath=Data.String(c:&imgstart+&debugrva+&pathoffset)
|
|
|
|
|
|
|
|
&baseofcode=&imgstart+Data.Long(c:&filehdrstart+0x28)
|
|
|
|
&baseofdata=&imgstart+Data.Long(c:&filehdrstart+0x2c)
|
|
|
|
|
|
|
|
if (&baseofcode<&baseofdata)&&(&baseofcode!=0)
|
|
|
|
(
|
|
|
|
&elfbase=&baseofcode;
|
|
|
|
)
|
|
|
|
else
|
|
|
|
(
|
|
|
|
&elfbase=&baseofdata;
|
|
|
|
)
|
|
|
|
|
2024-01-29 19:59:16 +01:00
|
|
|
print "found path &elfpath with address &elfbase"
|
2011-04-27 19:21:31 +02:00
|
|
|
ON ERROR GOSUB
|
|
|
|
return
|
|
|
|
data.load.elf &elfpath &elfbase /NOCODE /NOCLEAR
|
|
|
|
ON error
|
|
|
|
|
|
|
|
enddo
|