-
Notifications
You must be signed in to change notification settings - Fork 4
/
static.go
42 lines (37 loc) · 1 KB
/
static.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 ainur
import (
"debug/elf"
"errors"
)
// Static checks that PT_DYNAMIC is not in one of the program headers of the ELF file
func Static(f *elf.File) bool {
for _, prog := range f.Progs {
progType := prog.ProgHeader.Type
if progType == elf.PT_DYNAMIC {
return false
}
}
return true
}
// ExamineStatic opens the given filename and checks that it is an ELF file.
// It then calls Static to confirm that PT_DYNAMIC is not present in the program headers.
func ExamineStatic(filename string) (bool, error) {
f, err := elf.Open(filename)
if err != nil {
if _, isFormatError := err.(*elf.FormatError); isFormatError {
return false, errors.New(filename + ": Not an ELF")
}
return false, err
}
defer f.Close()
// This is where the actual
return Static(f), nil
}
// MustExamineStatic does the same as ExamineStatic, but panics instead of returning an error
func MustExamineStatic(filename string) bool {
static, err := ExamineStatic(filename)
if err != nil {
panic(err)
}
return static
}