elfwriter

package
v0.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package elfwriter is a package to write ELF files without having their entire contents in memory at any one time.

Original work started from https://github.com/go-delve/delve/blob/master/pkg/elfwriter/writer.go and additional functionality added on top.

This package does not provide completeness guarantees. Some of the missing features: - Consistency and soundness of relocations - Consistency and preservation of linked sections (when target removed (sh_link)) - partially supported - Consistency and existence of overlapping segments when a section removed (offset, range check)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCompressionHeaderFromSource added in v0.27.0

func NewCompressionHeaderFromSource(fhdr *elf.FileHeader, src io.ReaderAt, offset int64) (*compressionHeader, error)

Types

type Extractor added in v0.26.0

type Extractor struct {
	// contains filtered or unexported fields
}

Extractor extracts debug information from a binary.

func NewExtractor added in v0.26.0

func NewExtractor(logger log.Logger, tracer trace.Tracer, opts ...Option) *Extractor

NewExtractor creates a new Extractor.

func (*Extractor) ExtractAll added in v0.26.0

func (e *Extractor) ExtractAll(ctx context.Context, srcDsts map[string]io.WriteSeeker) error

ExtractAll extracts debug information from the given executables. It consumes a map of file sources to extract and a destination io.Writer.

func (*Extractor) OnlyKeepDebug added in v0.27.0

func (e *Extractor) OnlyKeepDebug(ctx context.Context, dst io.WriteSeeker, src io.ReaderAt) error

OnlyKeepDebug nullifies all the sections except debug information from the given executable. Mimics `objcopy --only-keep-debug`.

func (*Extractor) StripDebug added in v0.27.0

func (e *Extractor) StripDebug(ctx context.Context, dst io.WriteSeeker, src io.ReaderAt) error

StripDebug extracts debug information from the given executable. Cleaning up the temporary directory and the interim file is the caller's responsibility. Mimics `objcopy --strip-debug`.

type FilteringWriter

type FilteringWriter struct {
	Writer
	// contains filtered or unexported fields
}

FilteringWriter is a wrapper around Writer that allows to filter out sections, and programs from the source. Then write them to underlying io.WriteSeeker.

func NewFilteringWriter added in v0.27.0

func NewFilteringWriter(dst io.WriteSeeker, src io.ReaderAt, opts ...Option) (*FilteringWriter, error)

NewFilteringWriter creates a new Writer using given source.

func (*FilteringWriter) FilterHeaderOnlySections

func (w *FilteringWriter) FilterHeaderOnlySections(predicates ...func(*elf.Section) bool)

FilterHeaderOnlySections filters out header only sections from the source.

func (*FilteringWriter) FilterPrograms

func (w *FilteringWriter) FilterPrograms(predicates ...func(*elf.Prog) bool)

FilterPrograms filters out programs from the source.

func (*FilteringWriter) FilterSections

func (w *FilteringWriter) FilterSections(predicates ...func(*elf.Section) bool)

FilterSections filters out sections from the source. If sections have links to other sections, the referred sections are also be carried over to the destination.

func (*FilteringWriter) Flush

func (w *FilteringWriter) Flush() error

type Note

type Note struct {
	Type elf.NType
	Name string
	Data []byte
}

type NullifyingWriter added in v0.27.0

type NullifyingWriter struct {
	Writer
	// contains filtered or unexported fields
}

NullifyingWriter is a wrapper around another Writer that nullifies all the sections except the whitelisted ones.

func NewNullifyingWriter added in v0.27.0

func NewNullifyingWriter(dst io.WriteSeeker, src io.ReaderAt, opts ...Option) (*NullifyingWriter, error)

NewNullifyingWriter creates a new NullifyingWriter.

func (*NullifyingWriter) FilterPrograms added in v0.27.0

func (w *NullifyingWriter) FilterPrograms(predicates ...func(*elf.Prog) bool)

FilterPrograms filters out programs from the source.

func (*NullifyingWriter) Flush added in v0.27.0

func (w *NullifyingWriter) Flush() error

func (*NullifyingWriter) KeepSections added in v0.27.0

func (w *NullifyingWriter) KeepSections(predicates ...func(*elf.Section) bool)

KeepSections keeps only the sections that match the predicates. If no predicates are given, all sections are nullified.

type Option

type Option func(w *Writer)

func WithCompressDWARFSections added in v0.27.0

func WithCompressDWARFSections() Option

WithCompressDWARFSections compresses DWARF sections.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer writes ELF files.

func (*Writer) AddNotes

func (w *Writer) AddNotes(additionalNotes ...Note)

AddNotes adds additional notes to write to in the underlying io.WriterSeeker.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes any buffered data to the underlying io.WriterSeeker.

func (*Writer) Reset

func (w *Writer) Reset(ws io.WriteSeeker)

Reset discards any unflushed buffered data, clears any error, and resets data to write its output to dst.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL