ainur

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-3-Clause Imports: 8 Imported by: 5

README

Ainur

GoDoc License Go Report Card

Go package for figuring out which compiler and compiler version was used for compiling an executable file for Linux (in the ELF format).

Utilities that uses Ainur
Features and limitations
  • Supports detection of compiler name and version if an executable was built with one of these compilers:
    • GCC
    • Clang
    • FPC
    • OCaml
    • Go
    • TCC (compiler name only, TCC does not store the version number in the executables)
    • Rust (for stripped executables, only the compiler name and GCC version used for linking)
    • GHC
  • Works even with stripped executables.
  • Should work for recent versions of all of the above compilers. Executables produced with old versions of the compilers may need more testing.
General info

Documentation

Overview

Package ainur provides functions for examining ELF files

Index

Constants

This section is empty.

Variables

View Source
var (
	// GHCVersionRegex is a regexp for matching Glasgow Haskell Compiler version strings
	GHCVersionRegex = regexp.MustCompile(`GHC\ (\d{1,4}\.)(\d+\.)?(\d+)`)

	// GoVersionRegex is a regexp for matching Go version strings
	GoVersionRegex = regexp.MustCompile(`go(\d+\.)(\d+\.)?(\*|\d+)`)

	// PasVersionRegex is a regexp for matching Free Pascal Compiler version strings
	PasVersionRegex = regexp.MustCompile(`FPC\ (\d+\.)?(\d+\.)?(\*|\d+)`)

	// OcamlVersionRegex is a regexp for matching OCaml version strings
	OcamlVersionRegex = regexp.MustCompile(`(\d+\.)(\d+\.)?(\*|\d+)`)

	// GCCVersionRegex0 is another regexp for matching GCC version strings
	GCCVersionRegex0 = regexp.MustCompile(`(\d+\.)(\d+\.)?(\*|\d+)\ `)

	// GCCVersionRegex1 is another regexp for matching GCC version strings
	GCCVersionRegex1 = regexp.MustCompile(`\) (\d{1,4}\.)(\d+\.)?(\*|\d+)\ `)

	// GCCVersionRegex2 is another regexp for matching GCC version strings
	GCCVersionRegex2 = regexp.MustCompile(` (\d{1,4}\.)(\d+\.)?(\*|\d+)`)

	// GCCVersionRegex3 is another regexp for matching GCC version strings
	GCCVersionRegex3 = regexp.MustCompile(`(\d{1,4}\.)(\d+\.)?(\*|\d+)`)

	// GCCVersionRegex4 is another regexp for matching GCC version strings
	GCCVersionRegex4 = regexp.MustCompile(`\) (\d{1,4}\.)(\d+\.)?(\*|\d+).(\d+)`)
)

Functions

func Compiler

func Compiler(f *elf.File) string

Compiler takes an *elf.File and tries to find which compiler and version it was compiled with, by probing for known locations, strings and patterns.

func DVer added in v1.0.3

func DVer(f *elf.File) (ver string)

DVer returns "DMD" if it is detected Example output: "DMD"

func Describe added in v1.0.1

func Describe(m elf.Machine) string

Describe returns a descriptive string for a given elf.Machine

func Examine

func Examine(filename string) (string, error)

Examine tries to discover which compiler and compiler version the given file was compiled with.

func ExamineStatic added in v1.2.0

func ExamineStatic(filename string) (bool, error)

ExamineStatic opens the given filename and checks that it is an ELF file. It then calls Static to confirm that PT_DYNAMIC is not present in the program headers.

func FirstIsGreater

func FirstIsGreater(a, b string) bool

FirstIsGreater checks if the first version number is greater than the second one. It uses a relatively simple algorithm, where all non-numbers counts as less than "0".

func GCCVer

func GCCVer(f *elf.File) (ver string)

GCCVer returns the GCC compiler version or an empty string example output: "GCC 6.3.1" Also handles clang.

func GHCVer added in v1.1.0

func GHCVer(f *elf.File) (ver string)

GHCVer returns the GHC compiler version or an empty string example output: "GHC 8.6.2"

func GoVer

func GoVer(f *elf.File) (ver string)

GoVer returns the Go compiler version or an empty string example output: "Go 1.8.3"

func MustExamine

func MustExamine(filename string) string

MustExamine does the same as examine, but panics instead of returning an error

func MustExamineStatic added in v1.2.0

func MustExamineStatic(filename string) bool

MustExamineStatic does the same as ExamineStatic, but panics instead of returning an error

func OCamlVer

func OCamlVer(f *elf.File) (ver string)

OCamlVer returns the OCaml compiler version or an empty string example output: "OCaml 4.05.0"

func PasVer

func PasVer(f *elf.File) (ver string)

PasVer returns the FPC compiler version or an empty string example output: "FPC 3.0.2"

func RustVerStripped

func RustVerStripped(f *elf.File) (ver string)

RustVerStripped returns the Rust compiler version or an empty string, from a stripped Rust executable. Does not contain the Rust version number. Example output: "Rust (GCC 8.1.0)"

func RustVerUnstripped

func RustVerUnstripped(f *elf.File) (ver string)

RustVerUnstripped returns the Rust compiler version or an empty string example output: "Rust 1.27.0"

func Static added in v1.2.0

func Static(f *elf.File) bool

Static checks that PT_DYNAMIC is not in one of the program headers of the ELF file

func Stripped added in v1.0.2

func Stripped(f *elf.File) bool

Stripped returns true if symbols can not be retrieved from the given ELF file

func TCCVer

func TCCVer(f *elf.File) (ver string)

TCCVer returns "TCC" or an empty string TCC has no version number, but it does have some signature sections.

Types

type StreamReader added in v1.3.2

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

StreamReader is intended to be used to search in a streaming manner.

func NewStreamReader added in v1.3.2

func NewStreamReader(r io.Reader, bufferSize int) (*StreamReader, error)

NewStreamReader creates a new StreamReader.

func (*StreamReader) Next added in v1.3.2

func (r *StreamReader) Next() ([]byte, error)

Next reads the next half byte buffer from the stream. The reason for reading half is so that we can build something like:

tail my-file | grep "something"

Where "something" may be between two reads.

Jump to

Keyboard shortcuts

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