snyk-docker-plugin
Version:
Snyk CLI docker plugin
51 lines (50 loc) • 1.92 kB
TypeScript
import * as depGraph from "@snyk/dep-graph";
import { GoModule } from "./go-module";
import { Elf } from "./types";
/**
* GoBinary: Parser for Go compiled binaries
*
* This class extracts dependency information from Go binaries by reading ELF sections.
* It implements two scanning strategies depending on binary characteristics:
* - If .gopclntab exists: Extract source files → Map to packages → Report packages
* - If .gopclntab missing: Extract modules from .go.buildinfo → Report all modules
*
* Binary Types:
*
* 1. Normal Go Binaries (with .gopclntab):
* - Built with standard flags
* - Contains .gopclntab (Go Program Counter Line Table) section
* - .gopclntab maps program counter addresses to source files
*
* 2. Stripped Go Binaries (without .gopclntab):
* - Built with -ldflags='-s -w' flag
* - Removes debug symbols, symbol tables (.symtab, .strtab), and .gopclntab
*
* 3. CGo Go Binaries:
* - Built with CGO_ENABLED=1 (calls C code)
* - May or may not contain .gopclntab depending on build configuration
*
* ELF Sections Used:
* - .go.buildinfo: Module names, versions, and build information (always present)
* - .gopclntab: Source file to package mapping (missing in stripped/some CGo binaries)
*
*/
export declare class GoBinary {
name: string;
modules: GoModule[];
private hasPclnTab;
constructor(goElfBinary: Elf);
depGraph(): Promise<depGraph.DepGraph>;
matchFilesToModules(files: string[]): void;
}
export declare function extractModuleInformation(binary: Elf): [name: string, deps: GoModule[]];
/**
* Function finds and returns the Go version and
* module version information in the executable binary
* @param binary
*/
export declare function readRawBuildInfo(binary: Elf): string;
export declare function determinePaths(modules: GoModule[], files: string[]): {
modCachePath: string;
vendorPath: string;
};