-
Notifications
You must be signed in to change notification settings - Fork 3
/
elf.go
43 lines (33 loc) · 984 Bytes
/
elf.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
43
package dash
import (
"io"
"regexp"
"github.com/itchio/spellbook"
"github.com/itchio/wizardry/wizardry/wizutil"
)
var libraryPattern = regexp.MustCompile(`\.so(\.[0-9]+)*$`)
func sniffELF(r io.ReadSeeker, name string, size int64) (*Candidate, error) {
if libraryPattern.MatchString(name) {
// libraries (.so files) are not launch candidates
return nil, nil
}
sr := wizutil.NewSliceReader(&readerAtFromSeeker{r}, 0, size)
spell := spellbook.Identify(sr, 0)
if !spellHas(spell, "ELF") {
// looked like ELF but isn't? weird
return nil, nil
}
// some objects are marked as 'executable', others are marked
// as 'shared objects', but it doesn't matter since executables
// can be marked as shared objects as well (node-webkit) for example.
result := &Candidate{
Flavor: FlavorNativeLinux,
Spell: spell,
}
if spellHas(spell, "32-bit") {
result.Arch = Arch386
} else if spellHas(spell, "64-bit") {
result.Arch = ArchAmd64
}
return result, nil
}