-
Notifications
You must be signed in to change notification settings - Fork 7
/
dyntag.go
42 lines (36 loc) · 1.04 KB
/
dyntag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"debug/elf"
"encoding/binary"
"io"
)
func haveDynTag(file *elf.File, tag elf.DynTag) bool {
if section := file.Section(".dynamic"); section != nil {
reader := io.NewSectionReader(section, 0, int64(section.Size))
switch file.Machine {
case elf.EM_X86_64:
for {
var entry elf.Dyn64
if err := binary.Read(reader, binary.LittleEndian, &entry); err != io.EOF {
if elf.DynTag(entry.Tag) == tag {
return true
}
} else {
break
}
}
case elf.EM_386:
for {
var entry elf.Dyn32
if err := binary.Read(reader, binary.LittleEndian, &entry); err != io.EOF {
if elf.DynTag(entry.Tag) == tag {
return true
}
} else {
break
}
}
}
}
return false
}