Ejemplo n.º 1
0
void InterPro::print(raw_ostream &O,  Module *M)  
{

	char pPath[100];
	for(Module::iterator F = M->begin(); F != M->end(); F ++)
	{
		if(!F->getName().startswith("test"))
		{
			continue;
		}

		O << F->getName() << ":\n";

		for(Function::iterator BB = F->begin(); BB != F->end(); ++ BB)
		{
			for(BasicBlock::iterator I = BB->begin(); I != BB->end(); I ++)
			{
				I->dump();

				if( MDNode *N = I->getMetadata("dbg") )
				{	 
					DILocation Loc(N);
					string sFileNameForInstruction = Loc.getDirectory().str() + "/" + Loc.getFilename().str();    
					realpath( sFileNameForInstruction.c_str() , pPath);
					sFileNameForInstruction = string(pPath);                        
					unsigned int uLineNoForInstruction = Loc.getLineNumber();
					O << sFileNameForInstruction << ": " << uLineNoForInstruction << ": ";
				}

				O << this->InstBeforeSetMapping[I].size() << " ";
				O << this->InstAfterSetMapping[I].size() << "\n";
			}

		}


		O << "*********************************************\n";

	}
	
}
Ejemplo n.º 2
0
void ComputeSSO::HandleQueries(Module& M)
{

    for(set<QueryInput*>::iterator qit = queryinputs.begin();qit!=queryinputs.end();++qit)
    {
        bool constCheck;
        errs()<<"\n\n\n\n*******************************************************Query ";
        errs()<<"\nOperation : "<<(*qit)->operation;
        errs()<<"\nConstCheck : "<<(*qit)->constcheck;
        string operation = (*qit)->operation;
        set<string> labels = (*qit)->labels;
        set<Value*> vals = (*qit)->labVals;
        std::set<GraphNode*> taintedA;
        std::set<GraphNode*> taintedB;
        std::set<GraphNode*> intersectGraph;

        for(set<string>::iterator label = labels.begin();label != labels.end();++label)
            errs()<<" - "<<*label;
        errs()<<"\n*******************************************************\n ";

        constCheck = (*qit)->constcheck;
        if(constCheck)
        {
            for(set<Value*>::iterator val = vals.begin();val != vals.end();++val)
            {
                taintedA = taintGraphMap[*val];
            }
            intersectGraph = taintedA;
        }
        else
        {

            for(set<Value*>::iterator val = vals.begin();val != vals.end();++val)
            {
                taintedA = taintGraphMap[*val];
                ++val;
                if(val!=vals.end())
                    taintedB = taintGraphMap[*val];
            }
            if(strcmp(operation.c_str(),"intersect")==0)
            {
                //  intersectGraph = getIntersect(taintedA,taintedB);

                for(set<GraphNode*>::iterator gnode = taintedA.begin();gnode != taintedA.end();++gnode)
                {
                    if(taintedB.count(*gnode) > 0)
                    {
                        GraphNode* interNode = (*gnode)->clone();
                        intersectGraph.insert(interNode);
                    }

                }
            }
        }





        int branches =0;
        errs()<<"\n Intersect graph size :"<<intersectGraph.size();
        //print intersect graph nodes:

        //     PrintTainted(intersectGraph);

        //        for(set<GraphNode*>::iterator gnode = intersectGraph.begin();gnode != intersectGraph.end();++gnode)
        //        {
        //            errs()<<"\n Node: "<<(*gnode)->getLabel();
        //        }

        //Print appropriate vals....:
        for (Module::iterator F = M.begin(), endF = M.end(); F != endF; ++F) {
            string funcName = F->getName();
            //  errs()<<"\nTaints in function: "<<funcName;
            for (Function::iterator BB = F->begin(), endBB = F->end(); BB != endBB; ++BB) {
                string bbName ="noName";
                if(BB->hasName())
                {
                    bbName = BB->getName();
                }
                //  errs()<<" - block: "<<bbName;

                for (BasicBlock::iterator I = BB->begin(), endI = BB->end(); I
                     != endI; ++I) {
                    GraphNode* g = depGraph->findNode(I);
                    if (intersectGraph.count(g)) {
                        errs()<<"\n Node found..:";
                        I->dump();

                            errs()<<"Taint in function : "<<funcName<<"  :";
                            I->dump();

                            if (BranchInst *BI = dyn_cast<BranchInst>(I))
                            {
                                if(constCheck)
                                {
                                    Value* conditional = BI->getCondition();

                                    for (unsigned int i = 0; i < cast<User> (conditional)->getNumOperands(); i++)
                                    {
                                        Value *v1 = cast<User> (conditional)->getOperand(i);
                                        if(isa<ConstantInt>(v1))
                                        {
                                            errs()<<"Branch Inst tainted in func : "<<funcName<<"  :";
                                            BI->dump();
                                            branches++;
                                        }

                                    }

                                }
                                else
                                {
                                    //    BI->getCondition()->dump();
                                    errs()<<"Branch Inst tainted : ";
                                    BI->dump();
                                    branches++;
                                }
                            }

                    }
                }
            }
        }


        errs()<<"\n Number of conditionals tainted : " <<branches;
    }

    errs()<<"\n*******************************************************\n ";
}