1 #ifndef ROSE_BinaryAnalysis_FunctionCall_H
2 #define ROSE_BinaryAnalysis_FunctionCall_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 #include "BinaryControlFlow.h"
26 : vertex_filter(NULL), edge_filter(NULL)
53 typedef boost::adjacency_list<boost::setS,
55 boost::bidirectionalS,
56 boost::property<boost::vertex_name_t, SgAsmFunction*>
112 return filter && !(*filter)(
this, func);
125 return filter && !(*filter)(
this, src, dst);
133 VertexFilter *vertex_filter;
134 EdgeFilter *edge_filter;
155 template<
class FunctionCallGraph>
174 template<
class FunctionCallGraph,
class ControlFlowGraph>
177 template<
class ControlFlowGraph,
class FunctionCallGraph>
208 template<
class FunctionCallGraph>
211 template<
class FunctionCallGraph>
225 template<
class FunctionCallGraph>
226 FunctionCallGraph
copy(
const FunctionCallGraph &src);
227 template<
class FunctionCallGraph>
228 void copy(
const FunctionCallGraph &src, FunctionCallGraph &dst);
237 template<
class FunctionCallGraph>
241 typename boost::graph_traits<FunctionCallGraph>::vertex_iterator vi, vi_end;
242 for (boost::tie(vi, vi_end)=boost::vertices(cg); vi!=vi_end; ++vi) {
245 func->set_cached_vertex(*vi);
249 template<
class ControlFlowGraph,
class FunctionCallGraph>
253 typedef typename boost::graph_traits<FunctionCallGraph>::vertex_descriptor CG_Vertex;
254 typedef typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor CFG_Vertex;
255 typedef std::map<SgAsmFunction*, CG_Vertex> FunctionVertexMap;
260 FunctionVertexMap fv_map;
261 typename boost::graph_traits<const ControlFlowGraph>::vertex_iterator vi, vi_end;
262 for (boost::tie(vi, vi_end)=boost::vertices(cfg); vi!=vi_end; ++vi) {
265 typename FunctionVertexMap::iterator fi=fv_map.find(func);
266 if (func && fi==fv_map.end()) {
267 CG_Vertex v = boost::add_vertex(cg);
275 typename boost::graph_traits<const ControlFlowGraph>::edge_iterator ei, ei_end;
276 for (boost::tie(ei, ei_end)=boost::edges(cfg); ei!=ei_end; ++ei) {
277 CFG_Vertex cfg_a = boost::source(*ei, cfg);
278 CFG_Vertex cfg_b = boost::target(*ei, cfg);
280 ASSERT_not_null(block_a);
282 ASSERT_not_null(block_b);
286 typename FunctionVertexMap::iterator fi_a = fv_map.find(func_a);
287 if (fi_a!=fv_map.end()) {
288 typename FunctionVertexMap::iterator fi_b = fv_map.find(func_b);
289 if (fi_b!=fv_map.end())
290 boost::add_edge(fi_a->second, fi_b->second, cg);
296 template<
class FunctionCallGraph,
class ControlFlowGraph>
300 FunctionCallGraph cg;
305 template<
class FunctionCallGraph>
309 typedef typename boost::graph_traits<FunctionCallGraph>::vertex_descriptor
Vertex;
310 typedef std::map<SgAsmFunction*, Vertex> FunctionVertexMap;
311 FunctionVertexMap fv_map;
318 FunctionCallGraph &cg;
319 FunctionVertexMap &fv_map;
320 VertexAdder(
FunctionCall *analyzer, FunctionCallGraph &cg, FunctionVertexMap &fv_map)
321 : analyzer(analyzer), cg(cg), fv_map(fv_map)
323 void visit(
SgNode *node) {
326 Vertex vertex = boost::add_vertex(cg);
327 fv_map[func] = vertex;
336 FunctionCallGraph &cg;
337 FunctionVertexMap &fv_map;
338 Vertex source_vertex;
339 EdgeAdder(
FunctionCall *analyzer, FunctionCallGraph &cg, FunctionVertexMap &fv_map, Vertex source_vertex)
340 : analyzer(analyzer), cg(cg), fv_map(fv_map), source_vertex(source_vertex)
345 void visit(
SgNode *node) {
350 const SgAsmIntegerValuePtrList &succs = block_a->
get_successors();
351 for (SgAsmIntegerValuePtrList::const_iterator si=succs.begin(); si!=succs.end(); ++si) {
352 SgAsmFunction *func_b = isSgAsmFunction((*si)->get_baseNode());
353 if (func_b == NULL) {
354 SgAsmBlock *block_b = isSgAsmBlock((*si)->get_baseNode());
355 func_b = function_of(block_b);
356 if (func_b && func_b->get_entry_va() != block_b->
get_address())
360 typename FunctionVertexMap::iterator fi_b = fv_map.find(func_b);
361 if (fi_b!=fv_map.end())
362 boost::add_edge(source_vertex, fi_b->second, cg);
368 VertexAdder(
this, cg, fv_map).traverse(root, preorder);
369 typename boost::graph_traits<FunctionCallGraph>::vertex_iterator vi, vi_end;
370 for (boost::tie(vi, vi_end)=boost::vertices(cg); vi!=vi_end; ++vi) {
372 EdgeAdder(
this, cg, fv_map, *vi).traverse(source_func, preorder);
376 template<
class FunctionCallGraph>
380 FunctionCallGraph cg;
385 template<
class FunctionCallGraph>
389 typedef typename boost::graph_traits<FunctionCallGraph>::vertex_descriptor
Vertex;
390 Vertex NO_VERTEX = boost::graph_traits<FunctionCallGraph>::null_vertex();
393 std::vector<Vertex> src_to_dst(boost::num_vertices(src), NO_VERTEX);
395 typename boost::graph_traits<const FunctionCallGraph>::vertex_iterator vi, vi_end;
396 for (boost::tie(vi, vi_end)=boost::vertices(src); vi!=vi_end; ++vi) {
399 src_to_dst[*vi] = boost::add_vertex(dst);
404 typename boost::graph_traits<const FunctionCallGraph>::edge_iterator ei, ei_end;
405 for (boost::tie(ei, ei_end)=boost::edges(src); ei!=ei_end; ++ei) {
406 if (NO_VERTEX!=src_to_dst[boost::source(*ei, src)] && NO_VERTEX!=src_to_dst[boost::target(*ei, src)]) {
410 boost::add_edge(src_to_dst[boost::source(*ei, src)], src_to_dst[boost::target(*ei, src)], dst);
415 template<
class FunctionCallGraph>
419 FunctionCallGraph dst;
void put_ast_node(Sawyer::Container::Graph< V, E > &cfg, size_t vertexId, AstNode *astNode)
Set the AST node associated with a vertex.
bool is_vertex_filtered(SgAsmFunction *func)
Determines if a vertex is filtered out.
bool is_edge_filtered(SgAsmFunction *src, SgAsmFunction *dst, EdgeFilter *filter)
Determines if an edge is filtered out.
Class for traversing the AST.
bool is_vertex_filtered(SgAsmFunction *func, VertexFilter *filter)
Determines if a vertex is filtered out.
SgAsmBlock * get_entry_block() const
Function entry basic block.
void set_vertex_filter(VertexFilter *filter)
Manipulate the vertex filter.
Represents a synthesized function.
Sawyer::Container::Graph< V, E >::VertexValue get_ast_node(const Sawyer::Container::Graph< V, E > &cfg, size_t vertexId)
Return the AST node associated with a vertex.
Main namespace for the ROSE library.
Binary function call analysis.
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_name_t, SgAsmFunction * > > Graph
The default function call graph type.
This class represents the base class for all IR nodes within Sage III.
FunctionCallGraph copy(const FunctionCallGraph &src)
Copies a graph while filtering.
const SgAsmIntegerValuePtrList & get_successors() const
Property: Control flow successors.
VertexFilter * get_vertex_filter() const
Manipulate the vertex filter.
SgAsmFunction * get_enclosing_function() const
Returns the function that owns this block.
FunctionCallGraph build_cg_from_cfg(const ControlFlowGraph &)
Build a function call graph from a control flow graph.
FunctionCallGraph build_cg_from_ast(SgNode *root)
Build a function call graph from an AST.
EdgeFilter * get_edge_filter() const
Manipulate the edge filter.
bool is_edge_filtered(SgAsmFunction *src, SgAsmFunction *dst)
Determines if an edge is filtered out.
rose_addr_t get_address() const
Property: Starting virtual address.
void cache_vertex_descriptors(const FunctionCallGraph &)
Cache vertex descriptors in AST.
void set_edge_filter(EdgeFilter *filter)
Manipulate the edge filter.