Improve MSVC detection and demangling ##bin

* Fix language type detection logic in r_bin_load_languages()
* Set language as msvc when an import library that has "msvcp" is found
* Demangle symbols that have a dll name such as sym.imp.*.dll_*
This commit is contained in:
Iru Cai (vimacs) 2018-11-05 18:42:23 +08:00 committed by radare
parent 3b8161039e
commit 17b24cf4e3
2 changed files with 27 additions and 16 deletions

View File

@ -76,6 +76,10 @@ R_API int r_bin_load_languages(RBinFile *binfile) {
bool isElf = strstr (ft, "elf");
bool isPe = strstr (ft, "pe");
if (unknownType || !(isMacho || isElf || isPe)) {
return R_BIN_NM_NONE;
}
r_list_foreach (o->symbols, iter, sym) {
char *lib;
if (!cantbe.rust) {
@ -86,10 +90,6 @@ R_API int r_bin_load_languages(RBinFile *binfile) {
}
if (!cantbe.swift) {
bool hasswift = false;
if (unknownType || !(isMacho || isElf)) {
cantbe.swift = false;
continue;
}
if (!swiftIsChecked) {
r_list_foreach (o->libs, iter2, lib) {
if (strstr (lib, "swift")) {
@ -106,10 +106,6 @@ R_API int r_bin_load_languages(RBinFile *binfile) {
}
if (!cantbe.cxx) {
bool hascxx = false;
if (unknownType || !(isMacho || isElf)) {
cantbe.swift = false;
continue;
}
if (!cxxIsChecked) {
r_list_foreach (o->libs, iter2, lib) {
if (strstr (lib, "stdc++") ||
@ -117,6 +113,10 @@ R_API int r_bin_load_languages(RBinFile *binfile) {
hascxx = true;
break;
}
if (strstr (lib, "msvcp")) {
info->lang = "msvc";
return R_BIN_NM_MSVC;
}
}
cxxIsChecked = true;
}
@ -126,10 +126,6 @@ R_API int r_bin_load_languages(RBinFile *binfile) {
}
}
if (!cantbe.objc) {
if (unknownType || !(isMacho || isElf)) {
cantbe.objc = true;
continue;
}
if (check_objc (sym)) {
info->lang = "objc";
return R_BIN_NM_OBJC;
@ -137,10 +133,6 @@ R_API int r_bin_load_languages(RBinFile *binfile) {
}
if (!cantbe.dlang) {
bool hasdlang = false;
if (unknownType && !(isMacho || isElf || isPe)) {
cantbe.dlang = true;
continue;
}
if (!phobosIsChecked) {
r_list_foreach (o->libs, iter2, lib) {
if (strstr (lib, "phobos")) {

View File

@ -89,12 +89,30 @@ R_API char *r_bin_demangle(RBinFile *binfile, const char *def, const char *str,
return NULL;
}
RBin *bin = binfile? binfile->rbin: NULL;
RBinObject *o = binfile? binfile->o: NULL;
RListIter *iter;
const char *lib;
if (!strncmp (str, "reloc.", 6)) {
str += 6;
}
if (!strncmp (str, "sym.", 4)) {
str += 4;
}
if (!strncmp (str, "imp.", 4)) {
str += 4;
}
if (o) {
r_list_foreach (o->libs, iter, lib) {
size_t len = strlen (lib);
if (!r_str_ncasecmp (str, lib, len)) {
str += len;
if (*str == '_') {
str++;
}
break;
}
}
}
if (!strncmp (str, "__", 2)) {
if (str[2] == 'T') {
type = R_BIN_NM_SWIFT;
@ -116,6 +134,7 @@ R_API char *r_bin_demangle(RBinFile *binfile, const char *def, const char *str,
case R_BIN_NM_OBJC: return r_bin_demangle_objc (NULL, str);
case R_BIN_NM_SWIFT: return r_bin_demangle_swift (str, bin? bin->demanglercmd: false);
case R_BIN_NM_CXX: return r_bin_demangle_cxx (binfile, str, vaddr);
case R_BIN_NM_MSVC: return r_bin_demangle_msvc (str);
case R_BIN_NM_DLANG: return r_bin_demangle_plugin (bin, "dlang", str);
}
return NULL;