// Read creates a new BinFile from an io.ReaderAt.
Read creates a new BinFile from an io.ReaderAt.
// Read creates a new BinFile from an io . ReaderAt .
func Read(r io.ReaderAt, name string) (*BinFile, error) {
	f, err := elf.NewFile(r)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	b := &BinFile{
		pie:     false,
		funcs:   nil,
		lines:   nil,
		inlined: nil,
		name:    name,
	}
	if f.Type == elf.ET_DYN {
		b.pie = true
	} else if f.Type != elf.ET_EXEC {
		return nil, ErrInvalidElfType
	}
	var vaddr uint64
	if b.pie {
		for _, p := range f.Progs {
			if p.Type == elf.PT_LOAD {
				vaddr = p.Vaddr
				break
			}
		}
	}
	b.buildFuncCache(f, vaddr)
	b.buildInlinedFuncCache(f, vaddr)
	b.buildLineCache(f, vaddr)
	return b, nil
}
func Read ( r io . ReaderAt , name string ) ( * BinFile , error ) { f , err := elf . NewFile ( r ) if err != nil { return nil , err } defer f . Close ( ) b := & BinFile { pie : false , funcs : nil , lines : nil , inlined : nil , name : name , } if f . Type == elf . ET_DYN { b . pie = true } else if f . Type != elf . ET_EXEC { return nil , ErrInvalidElfType } var vaddr uint64 if b . pie { for _ , p := range f . Progs { if p . Type == elf . PT_LOAD { vaddr = p . Vaddr break } } } b . buildFuncCache ( f , vaddr ) b . buildInlinedFuncCache ( f , vaddr ) b . buildLineCache ( f , vaddr ) return b , nil }
Read creates a new BinFile from an io.ReaderAt.
Read creates a new BinFile from an io . ReaderAt .
// Get the vaddr of the first loadable segment. I'm not sure if this is the // right way to find the vaddr offset but it seems to work and I couldn't // find any documentation about this.