void RoseBin_GMLGraph::printEdges( VirtualBinCFG::AuxiliaryInformation* info, bool forward_analysis, std::ofstream& myfile, SgDirectedGraphEdge* edge) { // traverse edges and visualize results of graph SgGraphNode* source = isSgGraphNode(edge->get_from()); SgGraphNode* target = isSgGraphNode(edge->get_to()); ROSE_ASSERT(source); ROSE_ASSERT(target); string edgeLabel=""; map < int , string> edge_p = edge->get_properties(); map < int , string>::iterator prop = edge_p.begin(); //string type = node->get_type(); for (; prop!=edge_p.end(); ++prop) { int addr = prop->first; // cerr << " dot : property for addr : " << addr << " and node " << hex_address << endl; if (addr==SgGraph::edgeLabel) edgeLabel = prop->second; if (edgeLabel.length()>1) if (edgeLabel[0]!='U') edgeLabel=""; } SgAsmStatement* binStat_s = isSgAsmStatement(source->get_SgNode()); SgAsmStatement* binStat_t = isSgAsmStatement(target->get_SgNode()); if (binStat_s==NULL || binStat_t==NULL) { //cerr << "binStat_s==NULL || binStat_t==NULL" << endl; } else { map <SgAsmStatement*, int>::iterator it_s = nodesMap.find(binStat_s); map <SgAsmStatement*, int>::iterator it_t = nodesMap.find(binStat_t); int pos_s=0; int pos_t=0; if (it_s!=nodesMap.end()) pos_s = it_s->second; if (it_t!=nodesMap.end()) pos_t = it_t->second; if (pos_s==0 || pos_t==0) { //cerr << " GMLGraph edge, node == 0 " << endl; } string output = "edge [\n label \""+edgeLabel+"\"\n source " + RoseBin_support::ToString(pos_s) + "\n target " + RoseBin_support::ToString(pos_t) + "\n"; // ------------------ SgAsmX86Instruction* contrl = isSgAsmX86Instruction(source->get_SgNode()); string add = ""; if (contrl && x86InstructionIsControlTransfer(contrl)) { // the source is a control transfer function // we use either dest or dest_list // dest is used for single destinations during cfg run // dest_list is used for a static cfg image vector<VirtualBinCFG::CFGEdge> outEdges = contrl->cfgBinOutEdges(info); SgAsmX86Instruction* dest = isSgAsmX86Instruction(outEdges.empty() ? NULL : outEdges.back().target().getNode()); bool dest_list_empty = true; if (contrl->get_kind() == x86_ret) dest_list_empty = outEdges.empty(); SgAsmInstruction* nextNode = isSgAsmInstruction(target->get_SgNode()); ROSE_ASSERT(nextNode); if (dest) { //string type = "jmp_if"; if (dest==nextNode) { if (contrl->get_kind() == x86_call || contrl->get_kind() == x86_ret) { add += " graphics [ type \"line\" style \"dashed\" arrow \"last\" fill \"#FF0000\" ] ]\n"; } else if (contrl->get_kind() == x86_jmp) { add += " graphics [ type \"line\" style \"dashed\" arrow \"last\" fill \"#FF0000\" ] ]\n"; } else add += " graphics [ type \"line\" style \"dashed\" arrow \"last\" fill \"#00FF00\" ] ]\n"; } else if (forward_analysis && (contrl->get_kind() == x86_call || contrl->get_kind() == x86_jmp)) { add += " graphics [ type \"line\" arrow \"last\" fill \"#FFFF00\" ] ]\n"; } } else if (contrl->get_kind() == x86_ret ) { //&& dest_list_empty) { // in case of a multiple return add += " graphics [ type \"line\" style \"dashed\" arrow \"last\" fill \"#3399FF\" ] ]\n"; } } string type_n = getProperty(SgGraph::type, edge); if (type_n==RoseBin_support::ToString(SgGraph::usage)) { add = " graphics [ type \"line\" style \"dashed\" arrow \"last\" fill \"#000000\" ] ]\n"; } // skip the function declaration edges for now // bool blankOutput=false; //if (skipFunctions) //if (isSgAsmFunction(binStat_s)) // blankOutput=true; if (skipInternalEdges) { SgAsmX86Instruction* contrl = isSgAsmX86Instruction(source->get_SgNode()); if (contrl && x86InstructionIsControlTransfer(contrl) && contrl->get_kind() != x86_ret) { if (contrl->get_kind() == x86_call) output += " Edge_Color_ FF0000 \n Type_ \"[ 33554432 CALL_EDGE ]\" \n"; else if (contrl->get_kind() == x86_jmp) output += " Edge_Color_ 00FF00 \n Type_ \"[ 33554432 FILECALL_EDGE ]\" \n"; else output += " Edge_Color_ 0000FF \n "; } //else // blankOutput=true; } if (add=="") output += " graphics [ type \"line\" arrow \"last\" fill \"#000000\" ] ]\n"; else output +=add; myfile << output; } // } // ---------- // nodesMap.clear(); }