mirror of
https://github.com/wader/fq.git
synced 2024-11-24 11:16:09 +03:00
elf: Use correct offset to dynamic linking string table
String table used for "needed" tags (the string seen with ldd etc) was using address as offset which seem to work as it's usually the same as correct offset. But this is not true for some ELFs. Then we have to look up offset by finding the section by address and then use its offset for the string table. Hope this is the correct way. Not sure how to produce a small test for this.
This commit is contained in:
parent
d4fe00d65c
commit
f66a359c39
@ -431,9 +431,11 @@ func elfDecodeGNUHash(d *decode.D, ec elfContext, size int64, strTab string) {
|
||||
}
|
||||
|
||||
type dynamicContext struct {
|
||||
entries int
|
||||
strTab string
|
||||
symEnt int64
|
||||
entries int
|
||||
strTabPtr int64
|
||||
strSzVal int64
|
||||
strTab string
|
||||
symEnt int64
|
||||
}
|
||||
|
||||
func elfReadDynamicTags(d *decode.D, ec *elfContext) dynamicContext {
|
||||
@ -461,9 +463,10 @@ func elfReadDynamicTags(d *decode.D, ec *elfContext) dynamicContext {
|
||||
}
|
||||
|
||||
return dynamicContext{
|
||||
entries: entries,
|
||||
strTab: string(d.BytesRange(strTabPtr, int(strSzVal/8))),
|
||||
symEnt: symEnt,
|
||||
entries: entries,
|
||||
strTabPtr: strTabPtr,
|
||||
strSzVal: strSzVal,
|
||||
symEnt: symEnt,
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,6 +562,19 @@ func elfReadSectionHeaders(d *decode.D, ec *elfContext) {
|
||||
ec.sections = append(ec.sections, sh)
|
||||
}
|
||||
|
||||
// for dynamic linking sections find offset to string table by looking up
|
||||
// section by address using string stable address
|
||||
for i := range ec.sections {
|
||||
sh := &ec.sections[i]
|
||||
if sh.typ != SHT_DYNAMIC {
|
||||
continue
|
||||
}
|
||||
if i, ok := ec.sectionIndexByAddr(sh.dc.strTabPtr); ok {
|
||||
strTabSh := ec.sections[i]
|
||||
sh.dc.strTab = string(d.BytesRange(strTabSh.offset, int(sh.dc.strSzVal/8)))
|
||||
}
|
||||
}
|
||||
|
||||
ec.strTabMap = map[string]string{}
|
||||
var shStrTab string
|
||||
if ec.shStrNdx >= len(ec.sections) {
|
||||
|
Loading…
Reference in New Issue
Block a user