Rizin
unix-like reverse engineering framework and cli tools
|
#include <rz_bin.h>
Go to the source code of this file.
Classes | |
struct | golang_build_info_t |
struct | scan_go_info_s |
Macros | |
#define | GOLANG_MAX_UVARIANT 10 |
#define | GOLANG_MAX_STRING_BUF 0x1000 |
#define | GOLANG_MOD_START "\x30\x77\xaf\x0c\x92\x74\x08\x02\x41\xe1\xc1\x07\xe6\xd6\x18\xe6" |
Typedefs | |
typedef struct golang_build_info_t | GoBuildInfo |
Functions | |
static ut64 | go_uvariant (ut8 *buffer, size_t size, ut32 *read) |
static ut64 | go_string (ut8 *buffer, size_t size, char **output) |
static st64 | io_read_va_at (RzBinFile *bf, ut64 vaddr, ut8 *buffer, ut64 size) |
static char * | go_string_from_table (RzBinFile *bf, ut32 ptr_size, ut64 offset, bool big_endian, ut32 *str_size) |
static void | parse_go_build_info (RzBinFile *bf, GoBuildInfo *go_info, ut64 bi_paddr) |
static bool | is_go_build_info (const ut8 *magic) |
static ut64 | scan_go_build_info (const ut8 *buf, ut64 len, void *user) |
static void | find_go_build_info (RzBinFile *bf, GoBuildInfo *go_info, RzBinSection *section) |
RZ_IPI RZ_OWN char * | rz_bin_file_golang_compiler (RZ_NONNULL RzBinFile *bf) |
Returns the golang compiler info if buildinfo struct is found. More... | |
This is a parser for parsing the buildinfo structure which provides access to information embedded in a Go binary about how it was built. This includes the Go toolchain version, and the set of modules used (for binaries built in module mode).
This structure always starts with a magic "\xff Go buildinf:", followed by pointer size and version (the version also describes the endianness).
This structure contains then the compiler/go version and the cmd arguments/settings provided at compilation time.
Starting from go1.18 the settings area is guarded by two magic numbers:
3077af0c9274080241e1c107e6d618e6
i.e. beginning of the settingsf932433186182072008242104116d8f2
i.e. ending of the settings On earlier versions this section is actually pointing to some string structures which contains the virt address and size of the string to parse.Example of the structure from a go1.18 binary.
ff20 476f 2062 7569 6c64 696e 663a 0802 . Go buildinf:.. 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0667 6f31 2e31 38d5 0130 77af 0c92 7408 .go1.18..0w...t. 0241 e1c1 07e6 d618 e670 6174 6809 636f .A.......path.co 6d6d 616e 642d 6c69 6e65 2d61 7267 756d mmand-line-argum 656e 7473 0a62 7569 6c64 092d 636f 6d70 ents.build.-comp 696c 6572 3d67 630a 6275 696c 6409 4347 iler=gc.build.CG 4f5f 454e 4142 4c45 443d 310a 6275 696c O_ENABLED=1.buil 6409 4347 4f5f 4346 4c41 4753 3d0a 6275 d.CGO_CFLAGS=.bu 696c 6409 4347 4f5f 4350 5046 4c41 4753 ild.CGO_CPPFLAGS 3d0a 6275 696c 6409 4347 4f5f 4358 5846 =.build.CGO_CXXF 4c41 4753 3d0a 6275 696c 6409 4347 4f5f LAGS=.build.CGO_ 4c44 464c 4147 533d 0a62 7569 6c64 0947 LDFLAGS=.build.G 4f41 5243 483d 6172 6d36 340a 6275 696c OARCH=arm64.buil 6409 474f 4f53 3d64 6172 7769 6e0a f932 d.GOOS=darwin..2 4331 8618 2072 0082 4210 4116 d8f2 0000 C1.. r..B.A.....
Example from go version -m mybinary
:
devel go1.18-2d1d548 Tue Dec 21 03:55:43 2021 +0000 path github.com/username/repository mod github.com/username/repository (devel) dep golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff h1:XmKBi9R6duxOB3lfc72wyrwiOY7X2Jl1wuI+RFOyMDE= path command-line-arguments build -compiler=gc build CGO_ENABLED=1 build CGO_CFLAGS= build CGO_CPPFLAGS= build CGO_CXXFLAGS= build CGO_LDFLAGS= build GOARCH=amd64 build GOOS=linux build GOAMD64=v1 build vcs=git build vcs.revision=4bd670890aee5a14e36be1a72d19ca8573f2433b build vcs.time=2021-12-06T17:40:21Z build vcs.modified=true
Reference:
Definition in file golang.c.
#define GOLANG_MOD_START "\x30\x77\xaf\x0c\x92\x74\x08\x02\x41\xe1\xc1\x07\xe6\xd6\x18\xe6" |
typedef struct golang_build_info_t GoBuildInfo |
|
static |
Definition at line 253 of file golang.c.
References scan_go_info_s::bf, rz_bin_file_t::buf, scan_go_info_s::go_info, rz_buf_fwd_scan(), scan_go_build_info(), and section::size.
Referenced by rz_bin_file_golang_compiler().
Definition at line 105 of file golang.c.
References go_uvariant(), GOLANG_MOD_START, malloc(), memcpy(), n, NULL, output, read(), and ut64().
Referenced by parse_go_build_info().
|
static |
Definition at line 135 of file golang.c.
References free(), GOLANG_MAX_STRING_BUF, io_read_va_at(), malloc(), NULL, rz_read_ble32(), rz_read_ble64(), cmd_descs_generate::str, and ut64().
Referenced by parse_go_build_info().
Definition at line 80 of file golang.c.
References b, GOLANG_MAX_UVARIANT, i, read(), s, ut64(), and x.
Referenced by go_string().
Definition at line 127 of file golang.c.
References rz_bin_file_t::buf, rz_bin_file_t::o, rz_bin_object_v2p(), rz_buf_read_at(), ut64(), and UT64_MAX.
Referenced by go_string_from_table().
Definition at line 228 of file golang.c.
Referenced by scan_go_build_info().
|
static |
Definition at line 170 of file golang.c.
References rz_bin_file_t::buf, free(), go_string(), go_string_from_table(), GOLANG_MAX_STRING_BUF, i, malloc(), NULL, PFMT64x, read(), rz_buf_read_at(), RZ_LOG_ERROR, rz_read_ble32(), rz_read_ble64(), rz_str_replace(), golang_build_info_t::settings, cmd_descs_generate::str, ut64(), and golang_build_info_t::version.
Referenced by rz_bin_file_golang_compiler(), and scan_go_build_info().
RZ_IPI RZ_OWN char* rz_bin_file_golang_compiler | ( | RZ_NONNULL RzBinFile * | bf | ) |
Returns the golang compiler info if buildinfo struct is found.
RzBinFile | The RzBinFile to use for the search |
Definition at line 265 of file golang.c.
References scan_go_info_s::bf, find_go_build_info(), free(), scan_go_info_s::go_info, rz_bin_plugin_t::name, NULL, rz_bin_file_t::o, parse_go_build_info(), rz_bin_object_t::plugin, rz_bin_object_get_sections(), rz_list_free(), RZ_LOG_INFO, rz_return_val_if_fail, rz_str_newf(), sections(), golang_build_info_t::settings, section::size, and golang_build_info_t::version.
Referenced by rz_bin_object_set_items().
Definition at line 238 of file golang.c.
References is_go_build_info(), len, parse_go_build_info(), pos, and ut64().
Referenced by find_go_build_info().