elf

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Class

func Class(p *ast.Parser) (*ast.Node, error)

func Data

func Data(p *ast.Parser) (*ast.Node, error)
func Header(p *ast.Parser) (*ast.Node, error)

func Indent

func Indent(p *ast.Parser) (*ast.Node, error)

func MagicNumber

func MagicNumber(p *ast.Parser) (*ast.Node, error)

func NewELFParser

func NewELFParser(input []byte) (*ast.Parser, error)

func Parse

func Parse(input []byte) (*ast.Node, error)
Example
package main

import (
	"fmt"
	"github.com/di-wu/parser/examples/elf"
)

func main() {
	header, _ := elf.Parse([]byte{
		// magic, 32-bit, msb, version, padding
		0x7f, 0x45, 0x4c, 0x46, 0x01, 0x02, 0x01, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		// executable file
		0x00, 0x02,
	})
	fmt.Println(header.Type)

	var (
		children = header.Children()

		indent    = children[0]
		iChildren = indent.Children()
		class     = iChildren[0]
		data      = iChildren[0]

		typ = children[1]
	)
	fmt.Println(indent.Type)
	fmt.Printf("\t%x\n", class.Value)
	fmt.Printf("\t%x\n", data.Value)
	fmt.Println(typ.Type)
	fmt.Printf("\t%x\n", typ.Value)
}
Output:

1
2
	01
	01
5
	0002
Example (Invalid)
package main

import (
	"fmt"
	"github.com/di-wu/parser"
	"github.com/di-wu/parser/ast"
	"github.com/di-wu/parser/examples/elf"
)

func main() {
	p, _ := ast.New([]byte{
		// magic, 32-bit, msb, version, padding
		0x7f, 0x45, 0x4c, 0x46, 0x01, 0x02, 0x01, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		// some type
		0xff, 0xff,
	})
	// This will fail since ast uses utf8.DecodeRune to decode runes.
	_, err := elf.Header(p)
	fmt.Printf("0x%x", err.(*parser.ExpectedParseError).String)
}
Output:

0xffff

func Type

func Type(p *ast.Parser) (*ast.Node, error)

func Version

func Version(p *ast.Parser) (*ast.Node, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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