Skip to content

Commit

Permalink
Added linker version to rz-bin -I (#4632)
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar3q34 committed Sep 17, 2024
1 parent a13438b commit 7cb8b39
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
16 changes: 12 additions & 4 deletions librz/bin/bobj_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,20 @@ RZ_API bool rz_bin_object_process_plugin_data(RZ_NONNULL RzBinFile *bf, RZ_NONNU

// we need to detect the language of the binary
// one way can be based on the compiler.
if (o->info && RZ_STR_ISEMPTY(o->info->compiler)) {
free(o->info->compiler);
o->info->compiler = rz_bin_file_golang_compiler(bf);
if (o->info->compiler) {
if (o->info) {
char *go_compiler = rz_bin_file_golang_compiler(bf);
if (go_compiler) {
o->info->lang = "go";
o->lang = RZ_BIN_LANGUAGE_GO;
if (RZ_STR_ISNOTEMPTY(o->info->compiler)) {
char *merge = rz_str_newf("%s %s", go_compiler, o->info->compiler);
free(o->info->compiler);
free(go_compiler);
o->info->compiler = merge;
} else {
free(o->info->compiler);
o->info->compiler = go_compiler;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions librz/bin/format/pe/pe.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ struct rz_bin_pe_import_t *PE_(rz_bin_pe_get_imports)(RzBinPEObj *bin);
// pe_info.c
char *PE_(rz_bin_pe_get_arch)(RzBinPEObj *bin);
char *PE_(rz_bin_pe_get_cc)(RzBinPEObj *bin);
char *PE_(rz_bin_pe_get_compiler)(RzBinPEObj *bin);
char *PE_(rz_bin_pe_get_machine)(RzBinPEObj *bin);
char *PE_(rz_bin_pe_get_os)(RzBinPEObj *bin);
char *PE_(rz_bin_pe_get_class)(RzBinPEObj *bin);
Expand Down
12 changes: 12 additions & 0 deletions librz/bin/format/pe/pe_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ char *PE_(rz_bin_pe_get_cc)(RzBinPEObj *bin) {
return NULL;
}

char *PE_(rz_bin_pe_get_compiler)(RzBinPEObj *bin) {
if (!bin || !bin->nt_headers) {
return NULL;
}
int major = (int)bin->nt_headers->optional_header.MajorLinkerVersion;
int minor = (int)bin->nt_headers->optional_header.MinorLinkerVersion;
if (major || minor) {
return rz_str_newf("Linker %02d.%02d", major, minor);
}
return NULL;
}

int PE_(bin_pe_get_claimed_checksum)(RzBinPEObj *bin) {
if (!bin || !bin->optional_header) {
return 0;
Expand Down
1 change: 1 addition & 0 deletions librz/bin/p/bin_pe.inc
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ static RzBinInfo *info(RzBinFile *bf) {
ret->machine = PE_(rz_bin_pe_get_machine)(bf->o->bin_obj);
ret->subsystem = PE_(rz_bin_pe_get_subsystem)(bf->o->bin_obj);
ret->default_cc = PE_(rz_bin_pe_get_cc)(bf->o->bin_obj);
ret->compiler = PE_(rz_bin_pe_get_compiler)(bf->o->bin_obj);

RzPVector *libs = PE_(rz_bin_pe_get_libs)(bf->o->bin_obj);
if (libs && rz_pvector_find(libs, "mscoree.dll", compare_strings, NULL)) {
Expand Down
2 changes: 1 addition & 1 deletion test/db/analysis/golang
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ EXPECT=<<EOF
1788
0x004a699b str.hello__hacktivity
9222
compiler go1.15
compiler go1.15 Linker 03.00
errors
fmt
go
Expand Down
2 changes: 1 addition & 1 deletion test/db/cmd/cmd_pipe
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Copied bins/mach0/mach0_2-x86_64 succesfully
-------------
Shared buffer size 0x10e8
-------------
{'arch': 'x86', 'baddr': 4294967296, 'binsz': 4328, 'bintype': 'mach0', 'bits': 64, 'class': 'MACH064', 'endian': 'LE', 'intrp': '/usr/lib/dyld', 'laddr': 0, 'lang': 'c', 'machine': 'x86 64 all', 'maxopsz': 16, 'minopsz': 1, 'os': 'darwin', 'pcalign': 0, 'subsys': 'macOS', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': False, 'lsyms': False, 'canary': False, 'PIE': True, 'RELROCS': False, 'NX': False}
{'arch': 'x86', 'baddr': 4294967296, 'binsz': 4328, 'bintype': 'mach0', 'bits': 64, 'class': 'MACH064', 'compiler': '', 'endian': 'LE', 'intrp': '/usr/lib/dyld', 'laddr': 0, 'lang': 'c', 'machine': 'x86 64 all', 'maxopsz': 16, 'minopsz': 1, 'os': 'darwin', 'pcalign': 0, 'subsys': 'macOS', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': False, 'lsyms': False, 'canary': False, 'PIE': True, 'RELROCS': False, 'NX': False}
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x100000f70 5548 89e5 4883 ec10 c745 fc00 0000 0089 UH..H....E......

Expand Down
2 changes: 1 addition & 1 deletion test/db/formats/pe/arm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ retguard false
class PE32
cmp.csum 0x0000584b
compiled Thu Aug 12 03:57:16 2021 UTC
compiler N/A
compiler Linker 14.29
dbg_file N/A
endian LE
hdr.csum 0x00000000
Expand Down

0 comments on commit 7cb8b39

Please sign in to comment.