Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions librz/bin/bobj_process_symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_bin.h>
#include "i/private.h"
#include <rz_core.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sl4y3r-07 RzBin should not have dependency on RzCore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have fixed that. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the line is still here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant I have fixed it locally, will push it with other changes.


static void process_objc_symbol(RzBinObject *o, RzBinSymbol *symbol) {
if (!symbol->classname) {
Expand Down Expand Up @@ -85,6 +86,33 @@ static void process_handle_symbol(RzBinSymbol *symbol, RzBinObject *o, const RzD
// methods and fields.
language_cb(o, symbol);
}
RZ_API RzBinSymbol *rz_core_bin_get_symbol_by_name(RZ_NONNULL const RzCore *core, const char *name) {
rz_return_val_if_fail(core && name, NULL);
RzBinObject *obj = rz_bin_cur_object(core->bin);
if (!obj || !obj->symbols) {
return NULL;
}
void **it;
RzBinSymbol *element;
rz_pvector_foreach (obj->symbols, it) {
element = *it;
if (RZ_STR_EQ(element->name, name)) {
return element;
}
}
return NULL;
}

RZ_IPI void rz_bin_normalize_symbol(RzBinSymbol *symbol) {
rz_return_if_fail(symbol);
if (RZ_STR_ISEMPTY(symbol->name)) {
symbol->name = (symbol->vaddr && symbol->vaddr != UT64_MAX) ? rz_str_newf("unknown_0x%" PFMT64x, symbol->vaddr) : rz_str_newf("unknown_%d", symbol->ordinal);
symbol->is_auto_generated = true;
} else {
symbol->is_auto_generated = false;
}
return;
}

RZ_IPI void rz_bin_process_symbols(RzBinFile *bf, RzBinObject *o, const RzDemanglerPlugin *demangler, RzDemanglerFlag flags) {
if (rz_pvector_len(o->symbols) < 1) {
Expand All @@ -100,6 +128,7 @@ RZ_IPI void rz_bin_process_symbols(RzBinFile *bf, RzBinObject *o, const RzDemang
RzBinSymbol *element;
rz_pvector_foreach (o->symbols, it) {
element = *it;
rz_bin_normalize_symbol(element);
process_handle_symbol(element, o, demangler, flags, language_cb);
}
}
Expand Down
6 changes: 1 addition & 5 deletions librz/bin/format/elf/elf_relocs_conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ RZ_OWN RzBinSymbol *Elf_(rz_bin_elf_convert_symbol)(RZ_NONNULL ELFOBJ *bin, RZ_N

result->paddr = elf_symbol->paddr;
result->vaddr = elf_symbol->vaddr;
if (RZ_STR_ISNOTEMPTY(elf_symbol->name)) {
result->name = rz_str_dup(elf_symbol->name);
} else {
result->name = rz_str_newf("unknown_%u", elf_symbol->ordinal);
}
result->name = rz_str_dup(elf_symbol->name);
result->forwarder = "NONE";
result->bind = elf_symbol->bind;
result->type = elf_symbol->type;
Expand Down
5 changes: 5 additions & 0 deletions librz/core/cmd/cmd_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,11 @@ static const char *core_cmd_default_table_color(const char *value, const char *c
} else if (table_value_is_flags(column)) {
return ctx->pal.flag;
} else if (table_value_is_name(column)) {
RzBinSymbol *sym = rz_core_bin_get_symbol_by_name(core, value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would prefer to use rz_str_startswith

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this since we discussed for a better approach instead of direct string comparison. So it fetches the symbol and check whether is_auto_generated true. If rz_str_startswith is to be used, then initial change is good enough ig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I continue with this change?

if (value && sym && sym->is_auto_generated) {
return ctx->pal.diff_unknown;
}
free(sym);
return ctx->pal.fname;
} else if (table_value_is_meta(column)) {
return ctx->pal.meta;
Expand Down
1 change: 1 addition & 0 deletions librz/include/rz_bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ typedef struct rz_bin_symbol_t {
/* see RZ_BIN_METH_* constants */
ut64 method_flags;
int dup_count;
bool is_auto_generated;
} RzBinSymbol;

typedef struct rz_bin_import_t {
Expand Down
1 change: 1 addition & 0 deletions librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ RZ_API void rz_core_bin_print_source_line_sample(RzCore *core, const RzBinSource
RZ_API void rz_core_bin_print_source_line_info(RzCore *core, const RzBinSourceLineInfo *li, RzCmdStateOutput *state);

RZ_API bool rz_core_sym_is_export(RZ_NONNULL RzBinSymbol *s);
RZ_API RzBinSymbol *rz_core_bin_get_symbol_by_name(RZ_NONNULL const RzCore *core, const char *name);

RZ_API void rz_core_sysenv_begin(RzCore *core);
RZ_API void rz_core_sysenv_end(RzCore *core);
Expand Down
Loading