#include "sleela/decompiler/decompiler.hpp" #include #include #include #include namespace sleela::decompiler { ControlFlowGraph Analyzer::build_cfg(const std::vector& ins) const { ControlFlowGraph g;if(ins.empty())return g; std::unordered_set starts{ins.front().address};std::unordered_map by; for(std::size_t i=0;i b;for(std::size_t i=0;i block; for(const auto& x:g.blocks)if(!x.instructions.empty())block[x.instructions.front().address]=x.id; for(std::size_t n=0;n Analyzer::recover_function_candidates(const ControlFlowGraph& g) const { // A function candidate is an entry point, not merely a basic-block leader. We promote // (1) the first block of the window and (2) any block that is the target of a call -- a // far stronger signal of a function boundary than an intra-procedural branch target. // This avoids reporting every fall-through / branch-target block as a separate function. std::vector out;std::unordered_set seen; std::unordered_set call_targets; for(const auto& b:g.blocks) for(const auto& i:b.instructions) if(i.is_call) for(auto t:i.branch_targets) call_targets.insert(t); auto hex=[](std::uint64_t v){std::ostringstream s;s< Analyzer::recover_function_candidates(const Artifact& a,const ControlFlowGraph& g) const { auto out=recover_function_candidates(g);std::unordered_set seen;for(const auto& s:out)seen.insert(s.address); for(const auto& s:a.interfaces().symbols)if(!s.external&&s.address&&seen.insert(s.address).second)out.push_back(s); for(const auto& e:a.interfaces().exports)if(e.address&&seen.insert(e.address).second)out.push_back({e.name,e.address,false,{0,e.address,"stage4-export",0.90}}); std::sort(out.begin(),out.end(),[](const Symbol& x,const Symbol& y){return x.address