Example #1
0
 void visit(SgNode *node) {
     SgAsmFunction *func = isSgAsmFunction(node);
     if (func && 0==func->get_name().compare("simple06")) {
         ++nvisits;
         CFG cfg = rose::BinaryAnalysis::ControlFlow().build_block_cfg_from_ast<CFG>(func);
         CFG_Vertex start = 0;
         assert(get(boost::vertex_name, cfg, start)==func->get_entry_block());
         DG_RelMap dgmap1 = rose::BinaryAnalysis::Dominance().build_postdom_relation_from_cfg(cfg, start);
         DG_RelMap dgmap2 = MyDominance().build_postdom_relation_from_cfg(cfg, start);
     }
 }
void AST_BIN_Traversal::visit(SgNode* n) {
    if (n) {
      nrOfInstructions++;
      std::string name = "";
      if (isSgAsmInstruction(n))
        name = unparseInstruction(isSgAsmInstruction(n));
      SgNode* parent = n->get_parent();
      // node
      std::string add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=yellow,fontname=\"7x13bold\",fontcolor=black,style=filled";
      if (isSgAsmFunction(n)) { 
        add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=purple,fontname=\"7x13bold\",fontcolor=black,style=filled";
        name = isSgAsmFunction(n)->get_name();
      }
      if (isSgAsmX86Instruction(n) && isSgAsmX86Instruction(n)->get_kind() == x86_call)
        add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=red,fontname=\"7x13bold\",fontcolor=black,style=filled";
      if (isSgAsmValueExpression(n))
        add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=lightgreen,fontname=\"7x13bold\",fontcolor=black,style=filled";
      if (isSgAsmMemoryReferenceExpression(n))
        add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=lightblue,fontname=\"7x13bold\",fontcolor=black,style=filled";
      if (isSgAsmBinaryExpression(n))
        add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=orange,fontname=\"7x13bold\",fontcolor=black,style=filled";
      if (isSgAsmRegisterReferenceExpression(n)) {
        SgAsmRegisterReferenceExpression* rr = isSgAsmRegisterReferenceExpression(n);
        std::string exprName = unparseX86Register(rr->get_descriptor(), NULL);
        name += " "+exprName;
        add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=green,fontname=\"7x13bold\",fontcolor=black,style=filled";
      }
      if (isSgAsmOperandList(n))
        add = ",shape=ellipse,regular=0, sides=5,peripheries=1,color=\"Black\",fillcolor=white,fontname=\"7x13bold\",fontcolor=black,style=filled";
      myfile << "\"" << n << "\"[label=\"" << name << "\\n" << n->class_name() << "\"" << add << " ];\n"; 
      if (parent) {
        // edge
        myfile << "\"" << parent << "\" -> \"" << n << "\" [label=\"" << n->class_name() << "\" ];\n"; 
      }
    }
}
 virtual void visit(SgNode* n) {
     SgAsmX86Instruction* insn = isSgAsmX86Instruction(n);
     if (!insn) return;
     if (insn->get_kind() != x86_call) return;
     //cerr << "Found call xxx at " << hex << insn->get_address() << endl;
     uint64_t tgtAddr;
     if (!insn->getBranchTarget(&tgtAddr)) return;
     //cerr << "Found call at " << hex << insn->get_address() << " with known target " << hex << tgtAddr << endl;
     SgAsmInstruction* tgt = info->getInstructionAtAddress(tgtAddr);
     if (!tgt) return;
     //cerr << "Found target insn" << endl;
     SgNode* f = tgt;
     while (f && !isSgAsmBlock(f) && !isSgAsmFunction(f)) f = f->get_parent();
     if (!f) return;
     //cerr << "Found function of target" << endl;
     uint64_t next = insn->get_address() + insn->get_raw_bytes().size();
     info->returnTargets[isSgAsmStatement(f)].insert(next);
 }
 const std::set<uint64_t>& AuxiliaryInformation::getPossibleSuccessors(SgAsmInstruction* insn) const {
     static const std::set<uint64_t> emptySet;
     std::map<SgAsmInstruction*, std::set<uint64_t> >::const_iterator succsIter = indirectJumpTargets.find(insn);
     if (isSgAsmX86Instruction(insn) && isSgAsmX86Instruction(insn)->get_kind() == x86_ret) {
         SgNode* f = insn;
         while (f && !isSgAsmBlock(f) && !isSgAsmFunction(f)) f = f->get_parent();
         std::map<SgAsmStatement*, std::set<uint64_t> >::const_iterator retIter = returnTargets.find(isSgAsmStatement(f));
         if (retIter == returnTargets.end()) {
             return emptySet;
         } else {
             return retIter->second;
         }
     } else if (succsIter == indirectJumpTargets.end()) {
         return emptySet;
     } else {
         // rose translator has trouble in unparsing it correctly.
         return succsIter->second;
     }
 }
Example #5
0
 void visit(SgNode *node) { index->add_function(isSgAsmFunction(node)); }
 string CFGNode::toString() const {
     if (isSgAsmFunction(node)) {
         return "BinaryFunctionDefinition";
     }
     return "";
 }