Refactor cpp symbols detection. (#11699)

This commit is contained in:
David CARLIER 2018-10-01 14:32:38 +01:00 committed by radare
parent d57b7423af
commit 046d840520
3 changed files with 18 additions and 19 deletions

View File

@ -12,11 +12,23 @@ static bool is_cxx_symbol (const char *name) {
return false;
}
bool r_bin_is_cxx (RBinFile *binfile) {
RListIter *iter;
RBinImport *import;
RBinObject *o = binfile->o;
r_list_foreach (o->imports, iter, import) {
if (is_cxx_symbol (import->name)) {
return true;
}
}
return false;
}
R_API bool r_bin_lang_cxx(RBinFile *binfile) {
RBinObject *o = binfile ? binfile->o : NULL;
RBinInfo *info = o ? o->info : NULL;
RBinSymbol *sym;
RListIter *iter;
RBinSymbol *sym;
bool hascxx = false;
const char *lib;
@ -24,12 +36,14 @@ R_API bool r_bin_lang_cxx(RBinFile *binfile) {
return false;
}
r_list_foreach (o->libs, iter, lib) {
if (strstr (lib, "stdc++")) {
if (strstr (lib, "stdc++") ||
strstr (lib, "c++")) {
hascxx = true;
break;
}
}
if (!hascxx) {
hascxx = r_bin_is_cxx (binfile);
r_list_foreach (o->symbols, iter, sym) {
if (is_cxx_symbol (sym->name)) {
hascxx = true;

View File

@ -1078,22 +1078,6 @@ static bool has_sanitizers(RBinFile *bf) {
return ret;
}
static bool is_cpp(RBinFile *binfile) {
bool ret = false;
RList* imports_list = imports (binfile);
RListIter *iter;
RBinImport *import;
r_list_foreach (imports_list, iter, import) {
if (strncmp (import->name, "_ZS", 3) == 0 ||
strncmp (import->name, "_ZN", 3) == 0) {
ret = true;
break;
}
}
r_list_free (imports_list);
return ret;
}
static bool is_golang(RBinFile *binfile) {
bool ret = false;
RList* section_list = sections (binfile);
@ -1118,7 +1102,7 @@ static RBinInfo* info(RBinFile *bf) {
if (!(ret = R_NEW0 (RBinInfo))) {
return NULL;
}
ret->lang = is_cpp (bf) ? "c++" : "c";
ret->lang = r_bin_is_cxx (bf) ? "cxx" : "c";
ret->file = bf->file
? strdup (bf->file)
: NULL;

View File

@ -820,6 +820,7 @@ R_API void r_bin_filter_sections (RList *list);
R_API void r_bin_filter_classes (RList *list);
R_API bool r_bin_strpurge(RBin *bin, const char *str, ut64 addr);
R_API bool r_bin_string_filter(RBin *bin, const char *str, ut64 addr);
R_API bool r_bin_is_cxx(RBinFile *binfile);
/* plugin pointers */
extern RBinPlugin r_bin_plugin_any;