Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.MethodGen


  public SearchResult run(RSClient data, HashMap<String, ClassGen> classes) {
        for (Entry<String, ClassGen> c : classes.entrySet()) {
            for (Method m : c.getValue().getMethods()) {
              if(m.isFinal() && m.isStatic() && m.getReturnType().equals(Type.VOID)){
                    ConstantPoolGen cpg = c.getValue().getConstantPool();
                    MethodGen gen = new MethodGen(m, c.getValue().getClassName(), cpg);
                    InstructionList il = gen.getInstructionList();
                    if (il == null) {
                        continue;
                    }
                    InstructionFinder f = new InstructionFinder(il);
                    Iterator e = f.search("GETSTATIC GETFIELD ICONST IALOAD LDC ISHR ISTORE GETSTATIC GETFIELD ICONST IALOAD LDC");
View Full Code Here


      if(c.getValue().getSuperclassName().equals(nodeClass.className) && c.getValue().isFinal()){
        for(Method m : c.getValue().getMethods()){
          MethodSearcher mS = new MethodSearcher(m, cg, cpg);
          if(m.getName().equals("<init>") && mS.getArgCount() == 10 &&
              mS.getTypeCount("int") == 5 && mS.getTypeCount("java.lang.String")==2){
            MethodGen mg = new MethodGen(m, cg.getClassName(), cpg);
            RSClass menu = data.addClass("Menu", c.getValue().getClassName());
            int found = 0;
            InstructionSearcher iS = new InstructionSearcher(mg.getInstructionList(), cpg);
            Instruction i;
            FieldInstruction option;
            FieldInstruction action;
            while(iS.next() != null){
              i = iS.current();
View Full Code Here

  public SearchResult run(RSClient data, HashMap<String, ClassGen> classes) {
        for (Entry<String, ClassGen> c : classes.entrySet()) {
          for (Method m : c.getValue().getMethods()) {
            if (m.isStatic() && m.isFinal() && m.getReturnType().equals(Type.VOID)) {
                ConstantPoolGen cpg = c.getValue().getConstantPool();
                MethodGen gen = new MethodGen(m, c.getValue().getClassName(), cpg);
                InstructionList il = gen.getInstructionList();
                if (il == null) {
                   continue;
                }
                InstructionFinder f = new InstructionFinder(il);
                            // ISTORE GETSTATIC ISTORE GETSTATIC
View Full Code Here

            ResourceCollection<Stream> resourceCollection) throws CFGBuilderException, DataflowAnalysisException {

        potentialOpenStreamList.clear();

        JavaClass javaClass = classContext.getJavaClass();
        MethodGen methodGen = classContext.getMethodGen(method);
        if (methodGen == null) {
            return;
        }
        CFG cfg = classContext.getCFG(method);

        // Add Streams passed into the method as parameters.
        // These are uninteresting, and should poison
        // any streams which wrap them.
        try {
            Type[] parameterTypeList = Type.getArgumentTypes(methodGen.getSignature());
            Location firstLocation = new Location(cfg.getEntry().getFirstInstruction(), cfg.getEntry());

            int local = methodGen.isStatic() ? 0 : 1;

            for (Type type : parameterTypeList) {
                if (type instanceof ObjectType) {
                    ObjectType objectType = (ObjectType) type;
View Full Code Here

            bugAccumulator.reportAccumulatedBugs();
        }
    }

    private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
        MethodGen methodGen = classContext.getMethodGen(method);
        if (methodGen == null) {
            return;
        }
        BitSet bytecodeSet = classContext.getBytecodeSet(method);
        if (bytecodeSet == null) {
            return;
        }
        // We don't adequately model instanceof interfaces yet
        if (bytecodeSet.get(Constants.INSTANCEOF) || bytecodeSet.get(Constants.CHECKCAST)) {
            return;
        }
        CFG cfg = classContext.getCFG(method);
        TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
        ConstantPoolGen cpg = classContext.getConstantPoolGen();

        String sourceFile = classContext.getJavaClass().getSourceFileName();
        if (DEBUG) {
            String methodName = methodGen.getClassName() + "." + methodGen.getName();
            System.out.println("Checking " + methodName);
        }

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();
View Full Code Here

    private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
        CFG cfg = classContext.getCFG(method);
        ConstantDataflow constantDataflow = classContext.getConstantDataflow(method);
        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        MethodGen methodGen = classContext.getMethodGen(method);
        String sourceFile = classContext.getJavaClass().getSourceFileName();

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();
View Full Code Here

        BitSet lineMentionedMultipleTimes = classContext.linesMentionedMultipleTimes(method);
        BitSet linesWithLoadsOfNotDefinitelyNullValues = null;

        CFG cfg = classContext.getCFG(method);
        IsNullValueDataflow nullValueDataflow = classContext.getIsNullValueDataflow(method);
        MethodGen methodGen = classContext.getMethodGen(method);
        String sourceFile = classContext.getJavaClass().getSourceFileName();

        if (lineMentionedMultipleTimes.cardinality() > 0) {
            linesWithLoadsOfNotDefinitelyNullValues = new BitSet();
            LineNumberTable lineNumbers = method.getLineNumberTable();
View Full Code Here

    // Maximum number of iterations before we assume there is a bug and give up.
    private static final int MAX_ITERS = SystemProperties.getInt("dataflow.maxiters", 97);

    private String getFullyQualifiedMethodName() {
        String methodName;
        MethodGen methodGen = cfg.getMethodGen();
        if (methodGen == null) {
            methodName = cfg.getMethodName();
        } else {
            methodName = SignatureConverter.convertMethodSignature(methodGen);
        }
View Full Code Here

            }

            if (DEBUG) {
                System.out.println("----------------------------------------------------------------------");
                System.out.println(this.getClass().getName() + " iteration: " + numIterations + ", timestamp: " + timestamp);
                MethodGen mg = cfg.getMethodGen();
                System.out.println(mg.getClassName() + "." + mg.getName() + mg.getSignature());
                System.out.println("----------------------------------------------------------------------");

            }

            if (numIterations >= MAX_ITERS + 9) {
                throw new DataflowAnalysisException("Too many iterations (" + numIterations + ") in dataflow when analyzing "
                        + getFullyQualifiedMethodName());
            }

            analysis.startIteration();

            if (DEBUG && firstTime && blockOrder instanceof ReverseDFSOrder) {
                ReverseDFSOrder rBlockOrder = (ReverseDFSOrder) blockOrder;
                System.out.println("Entry point is: " + logicalEntryBlock());
                System.out.println("Basic block order: ");
                Iterator<BasicBlock> i = blockOrder.blockIterator();
                while (i.hasNext()) {

                    BasicBlock block = i.next();
                    debug(block, "rBlockOrder " + rBlockOrder.rdfs.getDiscoveryTime(block) + "\n");
                }
            }
            Iterator<BasicBlock> i = blockOrder.blockIterator();
            if (numIterations > 3 && numIterations % 2 == 0 && blockOrder instanceof ReverseDFSOrder) {
                if (DEBUG) {
                    System.out.println("Trying program order");
                }
                TreeSet<BasicBlock> bb = new TreeSet<BasicBlock>(new BackwardProgramOrder());
                Iterator<BasicBlock> j = blockOrder.blockIterator();
                while (j.hasNext()) {
                    BasicBlock block = j.next();
                    bb.add(block);
                }
                if (DEBUG) {
                    for (BasicBlock block : bb) {
                        debug(block, "\n");
                    }
                }
                i = bb.iterator();
            }
            if (DEBUG) {
                dumpDataflow(analysis);
            }

            // For each block in CFG...

            while (i.hasNext()) {

                BasicBlock block = i.next();

                // Get start fact for block.
                Fact start = analysis.getStartFact(block);
                assert start != null;

                boolean needToRecompute = false;
                // Get result facts for block,
                Fact result = analysis.getResultFact(block);
                assert result != null;

                int originalResultTimestamp = analysis.getLastUpdateTimestamp(result);

                // Meet all of the logical predecessor results into this block's
                // start.
                // Special case: if the block is the logical entry, then it gets
                // the special "entry fact".
                if (block == logicalEntryBlock()) {
                    analysis.makeFactTop(start);
                    analysis.initEntryFact(start);
                    if (DEBUG) {
                        debug(block, "Init entry fact ==> " + analysis.factToString(start) + "\n");
                    }
                    needToRecompute = true;
                } else {
                    int lastCalculated = analysis.getLastUpdateTimestamp(start);
                    Iterator<Edge> predEdgeIter = logicalPredecessorEdgeIterator(block);

                    int predCount = 0;
                    int rawPredCount = 0;
                    while (predEdgeIter.hasNext()) {
                        Edge edge = predEdgeIter.next();
                        rawPredCount++;
                        if (needToRecompute) {
                            // don't need to check to see if we need to recompute.
                            if (firstTime && !sawBackEdge) {
                                // may need to se sawBackEdge
                            } else {
                                continue;
                            }

                        }
                        BasicBlock logicalPred = isForwards ? edge.getSource() : edge.getTarget();

                        int direction = blockOrder.compare(block, logicalPred);

                        if (DEBUG) {
                            debug(block, "direction " + direction + " for " + blockId(logicalPred) + "\n");
                        }
                        if (direction < 0) {
                            sawBackEdge = true;
                        }

                        // Get the predecessor result fact
                        Fact predFact = analysis.getResultFact(logicalPred);
                        int predLastUpdated = analysis.getLastUpdateTimestamp(predFact);
                        if (!analysis.isTop(predFact)) {
                            predCount++;
                            if (predLastUpdated >= lastCalculated) {

                                needToRecompute = true;
                                if (DEBUG) {
                                    debug(block, "\n Need to recompute. My timestamp = " + lastCalculated + ", pred timestamp = "
                                            + predLastUpdated + ",\n   pred fact = " + predFact + "\n");
                                }
                                // break;
                            }
                        }
                    }
                    if (predCount == 0) {
                        needToRecompute = true;
                    }

                    if (!needToRecompute) {
                        continue;
                    }

                    if (needToRecompute) {

                        analysis.makeFactTop(start);
                        predEdgeIter = logicalPredecessorEdgeIterator(block);
                        while (predEdgeIter.hasNext()) {
                            Edge edge = predEdgeIter.next();
                            BasicBlock logicalPred = isForwards ? edge.getSource() : edge.getTarget();

                            // Get the predecessor result fact
                            Fact predFact = analysis.getResultFact(logicalPred);

                            // Apply the edge transfer function.
                            Fact edgeFact = analysis.createFact();
                            analysis.copy(predFact, edgeFact);
                            analysis.edgeTransfer(edge, edgeFact);

                            if (DEBUG && !analysis.same(edgeFact, predFact)) {
                                debug(block, logicalPred, edge, "Edge transfer " + analysis.factToString(predFact) + " ==> "
                                        + analysis.factToString(edgeFact));
                            }

                            // Merge the predecessor fact (possibly transformed
                            // by the edge transfer function)
                            // into the block's start fact.
                            if (DEBUG) {
                                if (analysis.isTop(start)) {
                                    debug(block, logicalPred, edge, "\n  First pred is " + analysis.factToString(edgeFact)
                                            + "\n   last updated at " + analysis.getLastUpdateTimestamp(predFact) + "\n");
                                } else {
                                    debug(block, logicalPred, edge, "\n  Meet " + analysis.factToString(start) + "\n   with "
                                            + analysis.factToString(edgeFact)

                                            + "\n   pred last updated at " + analysis.getLastUpdateTimestamp(predFact) + "\n");
                                }
                            }

                            if (analysis instanceof UnconditionalValueDerefAnalysis) {
                                ((UnconditionalValueDerefAnalysis) analysis).meetInto((UnconditionalValueDerefSet) edgeFact,
                                        edge, (UnconditionalValueDerefSet) start, rawPredCount == 1);
                            } else {
                                analysis.meetInto(edgeFact, edge, start);
                            }
                            analysis.setLastUpdateTimestamp(start, timestamp);

                            int pos = -1;
                            if (block.getFirstInstruction() != null) {
                                pos = block.getFirstInstruction().getPosition();
                            }
                            if (DEBUG) {
                                System.out.println(" [" + pos + "]==> " + analysis.factToString(start) + " @ " + timestamp
                                        + " \n");
                            }
                        }
                    }
                }
                if (DEBUG) {
                    debug(block, "start fact is " + analysis.factToString(start) + "\n");
                }

                // making a copy of result facts (so we can detect if it
                // changed).
                boolean resultWasTop = analysis.isTop(result);
                Fact origResult = null;
                if (!resultWasTop) {
                    origResult = analysis.createFact();
                    analysis.copy(result, origResult);
                }

                //                if (true || analysis.isTop(start)) {
                // Apply the transfer function.

                analysis.transfer(block, null, start, result);
                //                } else {
                //                    analysis.copy(start, result);
                //                }

                if (DEBUG && SystemProperties.getBoolean("dataflow.blockdebug")) {
                    debug(block, "Dumping flow values for block:\n");
                    Iterator<org.apache.bcel.generic.InstructionHandle> ii = block.instructionIterator();
                    while (ii.hasNext()) {
                        org.apache.bcel.generic.InstructionHandle handle = ii.next();
                        Fact tmpResult = analysis.createFact();
                        analysis.transfer(block, handle, start, tmpResult);
                        System.out.println("\t" + handle + " " + analysis.factToString(tmpResult));
                    }
                }

                // See if the result changed.
                if (DEBUG) {
                    debug(block, "orig result is " + (origResult == null ? "TOP" : analysis.factToString(origResult)) + "\n");
                }
                boolean thisResultChanged = false;
                if (resultWasTop) {
                    thisResultChanged = !analysis.isTop(result);
                } else {
                    thisResultChanged = !analysis.same(result, origResult);
                }
                if (thisResultChanged) {
                    timestamp++;
                    if (DEBUG) {
                        debug(block, "result changed at timestamp " + timestamp + "\n");
                    }
                    if (DEBUG && !needToRecompute) {
                        System.out.println("I thought I didn't need to recompute");
                    }
                    change = true;
                    analysis.setLastUpdateTimestamp(result, timestamp);
                } else {
                    analysis.setLastUpdateTimestamp(result, originalResultTimestamp);
                }

                if (DEBUG) {
                    debug(block,
                            "result is " + analysis.factToString(result) + " @ timestamp "
                                    + analysis.getLastUpdateTimestamp(result) + "\n");
                }
            }

            analysis.finishIteration();
            if (!sawBackEdge) {
                break;
            }

        } while (change);

        if (DEBUG) {
            System.out.println("-- Quiescence achieved-------------------------------------------------");
            System.out.println(this.getClass().getName() + " iteration: " + numIterations + ", timestamp: " + timestamp);
            MethodGen mg = cfg.getMethodGen();
            System.out.println(mg.getClassName() + "." + mg.getName() + mg.getSignature());
            new RuntimeException("Quiescence achieved----------------------------------------------------------------")
            .printStackTrace(System.out);

        }
        DEBUG = debugWas;
View Full Code Here

        if ((method.getAccessFlags() & Constants.ACC_BRIDGE) != 0) {
            return;
        }

        MethodGen methodGen = classContext.getMethodGen(method);

        if (methodGen == null) {
            return;
        }
        if (!checkedDatabases) {
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.MethodGen

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.