Skip to content

Commit

Permalink
Use flags for generating missing function names (#335)
Browse files Browse the repository at this point in the history
When there is no rizin function, but a flag and we need to generate some
function name there, we can use the flag name instead of the default
behavior, which is to call it "func_<addr>".
  • Loading branch information
thestr4ng3r authored Nov 19, 2023
1 parent 5a23b29 commit 10f0359
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 155 deletions.
29 changes: 29 additions & 0 deletions src/RizinPrintC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "RizinPrintC.h"
#include "RizinArchitecture.h"

#include <varnode.hh>
#include <architecture.hh>

#include <rz_core.h>

#include "RizinUtils.h"

using namespace ghidra;

// Constructing this registers the capability
Expand Down Expand Up @@ -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<RizinArchitecture *>(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<RzFlagItem *>(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);
}
1 change: 1 addition & 0 deletions src/RizinPrintC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading

0 comments on commit 10f0359

Please sign in to comment.