diff --git a/src/RizinPrintC.cpp b/src/RizinPrintC.cpp index 74e98ec0..d8cde082 100644 --- a/src/RizinPrintC.cpp +++ b/src/RizinPrintC.cpp @@ -2,10 +2,15 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "RizinPrintC.h" +#include "RizinArchitecture.h" #include #include +#include + +#include "RizinUtils.h" + using namespace ghidra; // Constructing this registers the capability @@ -42,3 +47,27 @@ void RizinPrintC::pushUnnamedLocation(const Address &addr, const Varnode *vn, co PrintC::pushUnnamedLocation(addr,vn, op); } } + +std::string RizinPrintC::genericFunctionName(const ghidra::Address &addr) +{ + auto arch = dynamic_cast(glb); + if (arch) { + RzCoreLock core(arch->getCore()); + const RzList *flags = rz_flag_get_list(core->flags, addr.getOffset()); + if(flags) + { + RzListIter *iter; + void *pos; + rz_list_foreach(flags, iter, pos) + { + auto flag = reinterpret_cast(pos); + if(flag->space && flag->space->name && !strcmp(flag->space->name, RZ_FLAGS_FS_SECTIONS)) + continue; + if(core->flags->realnames && flag->realname) + return flag->realname; + return flag->name; + } + } + } + return PrintC::genericFunctionName(addr); +} diff --git a/src/RizinPrintC.h b/src/RizinPrintC.h index 6f280a9a..afaf607f 100644 --- a/src/RizinPrintC.h +++ b/src/RizinPrintC.h @@ -10,6 +10,7 @@ class RizinPrintC : public ghidra::PrintC { protected: void pushUnnamedLocation(const ghidra::Address &addr, const ghidra::Varnode *vn,const ghidra::PcodeOp *op) override; + std::string genericFunctionName(const ghidra::Address &addr) override; public: explicit RizinPrintC(ghidra::Architecture *g, const std::string &nm = "c-language"); diff --git a/test/db/extras/ghidra b/test/db/extras/ghidra index a7e52ce2..bb3c1877 100644 --- a/test/db/extras/ghidra +++ b/test/db/extras/ghidra @@ -1129,7 +1129,7 @@ NAME=constant variable annotation FILE=bins/dectest32 EXPECT=<