Categorygithub.com/goretk/gore
modulepackage
0.13.8
Repository: https://github.com/goretk/gore.git
Documentation: pkg.go.dev

# README

Build Status GitHub tag (latest SemVer) codecov Go Report Card Go Reference

GoRE - Package gore is a library for analyzing Go binaries

How to use

  1. Use go get to download the library.
  2. Import it into your project.
  3. Write a new cool tool.

For an example use case, please check out redress.

Sample code

Extract the main package, child packages, and sibling packages:

f, err := gore.Open(fileStr)
pkgs, err := f.GetPackages()

Extract all the types in the binary:

f, err := gore.Open(fileStr)
typs, err := f.GetTypes()

Update get new Go release information

Instead of downloading new release of the library to get detection for new Go releases, it is possible to do a local pull.

Run go generate and new compiler releases will be generated from the git tags.

Functionality

Go compiler

The library has functionality for guessing the compiler version used. It searches the binary for the identifiable string left by the compiler. It is not perfect, so functionality for assuming a specific version is also provided. The version strings used are identical to the identifiers. For example version "1.10.1" is represented as "go1.10.1" and version "1.10" is represented as "go1.10"

Function recovery

Function information is recovered from the pclntab. Information that is recovered includes: function start and end location in the text section, source file. The library also tries to estimate the first and last line number in the source file for the function. The methods recovered includes the receiver. All functions and methods belong to a package. The library tries to classify the type of package. If it is a standard library package, 3rd-party package, or part of the main application. If it unable to classify the package, it is classified as unknown.

Type recovery

The types in the binary are parsed from the "typelink" list. Not all versions of Go are supported equally. Versions 1.7 and later are fully supported. Versions 1.5 and 1.6 are partially supported. Version prior to 1.5 are not supported at all at the moment.

# Packages

Package extern Copied from src/go/version.
No description provided by the author

# Functions

GoVersionCompare compares two version strings.
InterfaceDef reconstructs the type definition code for the interface.
IsStandardLibrary returns true if the package is from the standard library.
MethodDef constructs a string summary of all methods for the type.
NewModPackageClassifier creates a new mod based package classifier.
NewPathPackageClassifier constructs a new classifier based on the main package's filepath.
Open opens a file and returns a handler to the file.
OpenReader opens a reader and returns a handler to the file.
ResolveGoVersion tries to return the GoVersion for the given tag.
StructDef reconstructs the type definition code for the struct.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ChanBoth is a send and receive chan (chan).
ChanRecv is a receive only chan (<-chan).
ChanSend is a send only chan (chan<-).
ClassGenerated are used for packages generated by the compiler.
ClassMain is used for the main package and its subpackages.
ClassSTD is used for packages that are part of the standard library.
ClassUnknown is used for packages that could not be classified.
ClassVendor is used for vendor packages.

# Variables

ErrInvalidGoVersion is returned if the go version set for the file is either invalid or does not match a known version by the library.
ErrNoBuildInfo is returned if the file has no build information available.
ErrNoGoRootFound is returned if no goroot was found in the binary.
ErrNoGoVersionFound is returned if no goversion was found in the binary.
ErrNoPCLNTab is returned if no PCLN table can be located.
ErrNotEnoughBytesRead is returned if read call returned less bytes than what is needed.
ErrSectionDoesNotExist is returned when accessing a section that does not exist.
No description provided by the author
ErrUnsupportedFile is returned if the file process is unsupported.

# Structs

BuildInfo that was extracted from the file.
FileEntry is a representation of an entry in a source code file.
FileInfo holds information about the file.
Function is a representation of a Go function.
GoFile is a structure representing a go binary file.
GoType is a representation of all types in Go.
GoVersion holds information about the compiler version.
Method is a representation of a Go method.
ModPackageClassifier uses the mod info extracted from the binary to classify packages.
ModuleDataSection is a section defined in the Moduledata structure.
Package is a representation of a Go package.
PathPackageClassifier can classify the class of a go package.
SourceFile is a representation of a source code file.
Symbol A generic representation of [debug/elf.Symbol], [debug/pe.Symbol], and [github.com/blacktop/go-macho.Symbol].
TypeMethod is description of a method owned by the GoType.

# Interfaces

Moduledata holds information about the layout of the executable image in memory.
PackageClassifier classifies a package to the correct class type.

# Type aliases

ChanDir is a channel direction.
PackageClass is a type used to indicate the package kind.