2018-05-29 15:01:51 +00:00
|
|
|
package linutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-03-10 16:34:40 +00:00
|
|
|
_AT_NULL = 0
|
|
|
|
_AT_ENTRY = 9
|
2018-05-29 15:01:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// EntryPointFromAuxv searches the elf auxiliary vector for the entry point
|
|
|
|
// address.
|
|
|
|
// For a description of the auxiliary vector (auxv) format see:
|
|
|
|
// System V Application Binary Interface, AMD64 Architecture Processor
|
2020-03-10 16:34:40 +00:00
|
|
|
// Supplement, section 3.4.3.
|
|
|
|
// System V Application Binary Interface, Intel386 Architecture Processor
|
|
|
|
// Supplement (fourth edition), section 3-28.
|
|
|
|
func EntryPointFromAuxv(auxv []byte, ptrSize int) uint64 {
|
2018-05-29 15:01:51 +00:00
|
|
|
rd := bytes.NewBuffer(auxv)
|
|
|
|
|
|
|
|
for {
|
2020-03-10 16:34:40 +00:00
|
|
|
tag, err := readUintRaw(rd, binary.LittleEndian, ptrSize)
|
2018-05-29 15:01:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
2020-03-10 16:34:40 +00:00
|
|
|
val, err := readUintRaw(rd, binary.LittleEndian, ptrSize)
|
2018-05-29 15:01:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
switch tag {
|
2020-03-10 16:34:40 +00:00
|
|
|
case _AT_NULL:
|
2018-05-29 15:01:51 +00:00
|
|
|
return 0
|
2020-03-10 16:34:40 +00:00
|
|
|
case _AT_ENTRY:
|
2018-05-29 15:01:51 +00:00
|
|
|
return val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|