Java Code Examples for org.apache.bcel.generic.ConstantPoolGen

The following examples show how to use org.apache.bcel.generic.ConstantPoolGen. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static String getInstanceClassName(ConstantPoolGen cpg, InvokeInstruction invoke, TaintFrame frame) {
    try {
        int instanceIndex = frame.getNumArgumentsIncludingObjectInstance(invoke, cpg) - 1;
        if (instanceIndex != -1) {
            assert instanceIndex < frame.getStackDepth();
            Taint instanceTaint = frame.getStackValue(instanceIndex);
            String className = instanceTaint.getRealInstanceClassName();
            if (className != null) {
                return className;
            }
        }
    } catch (DataflowAnalysisException ex) {
        assert false : ex.getMessage();
    }
    String dottedClassName = invoke.getReferenceType(cpg).toString();
    return ClassName.toSlashedClassName(dottedClassName);
}
 
Example 2
Source Project: spotbugs   Source File: Hierarchy2.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Find the declared exceptions for the method called by given instruction.
 *
 * @param inv
 *            the InvokeInstruction
 * @param cpg
 *            the ConstantPoolGen used by the class the InvokeInstruction
 *            belongs to
 * @return array of ObjectTypes of thrown exceptions, or null if we can't
 *         find the method implementation
 */
public static @CheckForNull ObjectType[] findDeclaredExceptions(InvokeInstruction inv, ConstantPoolGen cpg) {
    XMethod method = findInvocationLeastUpperBound(inv, cpg, inv instanceof INVOKESTATIC ? STATIC_METHOD : INSTANCE_METHOD);

    if (method == null) {
        return null;
    }
    String[] exceptions = method.getThrownExceptions();

    if (exceptions == null) {
        return new ObjectType[0];
    }

    ObjectType[] result = new ObjectType[exceptions.length];
    for (int i = 0; i < exceptions.length; ++i) {
        result[i] = ObjectTypeFactory.getInstance(ClassName.toDottedClassName(exceptions[i]));
    }
    return result;
}
 
Example 3
private boolean mightCloseResource(ClassContext classContext, Method method, ResourceTrackerType resourceTracker)
        throws CFGBuilderException, DataflowAnalysisException {

    CFG cfg = classContext.getCFG(method);
    ConstantPoolGen cpg = classContext.getConstantPoolGen();

    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
        Location location = i.next();
        if (resourceTracker.mightCloseResource(location.getBasicBlock(), location.getHandle(), cpg)) {
            return true;
        }

    }

    return false;
}
 
Example 4
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {
    MethodGen methodGen = classContext.getMethodGen(m);
    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    CFG cfg = classContext.getCFG(m);

    if (methodGen == null || methodGen.getInstructionList() == null) {
        return; //No instruction .. nothing to do
    }
    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
        Location location = i.next();
        Instruction inst = location.getHandle().getInstruction();
        if (inst instanceof InvokeInstruction) {
            InvokeInstruction invoke = (InvokeInstruction) inst;
            String methodName = invoke.getMethodName(cpg);
            if ("enableDefaultTyping".equals(methodName)) {
                JavaClass clz = classContext.getJavaClass();
                bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY)
                        .addClass(clz)
                        .addMethod(clz, m)
                        .addCalledMethod(cpg, invoke)
                        .addSourceLine(classContext, m, location)
                );
            }
        }
    }
}
 
Example 5
@Override
protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg,
                                           InstructionHandle handle) {
    assert invoke != null && cpg != null;

    String method = invoke.getMethodName(cpg);
    String sig    = invoke.getSignature(cpg);

    if(method.equals("registerReceiver")){
        if(sig.contains("Ljava/lang/String;")){
            if(sig.contains(";I)")){
                return new InjectionPoint(new int[]{2}, ANDROID_REGISTER_RECEIVER_TYPE);
            }else{
                return new InjectionPoint(new int[]{1}, ANDROID_REGISTER_RECEIVER_TYPE);
            }
        }
    }
    return InjectionPoint.NONE;
}
 
Example 6
@Override
    protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg,
                                               InstructionHandle handle) {
        assert invoke != null && cpg != null;

        String method = invoke.getMethodName(cpg);
        String sig    = invoke.getSignature(cpg);
//        System.out.println(invoke.getClassName(cpg));
        if(sig.contains("Ljava/lang/String;")) {
            if("loadUrl".equals(method)){
                if(sig.contains("Ljava/util/Map;")){
                    return new InjectionPoint(new int[]{1}, WEBVIEW_LOAD_DATA_URL_TYPE);
                }else{
                    return new InjectionPoint(new int[]{0}, WEBVIEW_LOAD_DATA_URL_TYPE);
                }
            }else if("loadData".equals(method)){
                return new InjectionPoint(new int[]{2}, WEBVIEW_LOAD_DATA_URL_TYPE);
            }else if("loadDataWithBaseURL".equals(method)){
                //BUG
                return new InjectionPoint(new int[]{4}, WEBVIEW_LOAD_DATA_URL_TYPE);
            }
        }
        return InjectionPoint.NONE;
    }
 
Example 7
@Override
    protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg,
                                               InstructionHandle handle) {
        assert invoke != null && cpg != null;

        String method = invoke.getMethodName(cpg);
        String sig    = invoke.getSignature(cpg);
//        System.out.println(sig);
        if(sig.contains("Ljava/lang/String;")) {
            if(method.contains("send") && method.contains("Broadcast") && !method.contains("Sticky")){
//                System.out.println(method);
                if("sendOrderedBroadcastAsUser".equals(method)){
                    return new InjectionPoint(new int[]{5}, ANDROID_BROADCAST_TYPE);
                }
                if("sendOrderedBroadcast".equals(method) && sig.contains("Landroid/content/BroadcastReceiver;")){
                    return new InjectionPoint(new int[]{5}, ANDROID_BROADCAST_TYPE);
                }
                return new InjectionPoint(new int[]{0}, ANDROID_BROADCAST_TYPE);
            }
        }
        return InjectionPoint.NONE;
    }
 
Example 8
@Override
protected BackwardTypeQualifierDataflow getDataflow(DepthFirstSearch dfs, XMethod xmethod, CFG cfg,
        ValueNumberDataflow vnaDataflow, ConstantPoolGen cpg, IAnalysisCache analysisCache,
        MethodDescriptor methodDescriptor, TypeQualifierValue<?> typeQualifierValue) throws CheckedAnalysisException {
    ReverseDepthFirstSearch rdfs = analysisCache.getMethodAnalysis(ReverseDepthFirstSearch.class, methodDescriptor);

    BackwardTypeQualifierDataflowAnalysis analysis = new BackwardTypeQualifierDataflowAnalysis(dfs, rdfs, xmethod, cfg,
            vnaDataflow, cpg, typeQualifierValue);

    // Get the corresponding forward dataflow.
    // We use it to halt tracking of backwards values once we know
    // that they encounter a conflicting forward value.
    ForwardTypeQualifierDataflowFactory forwardFactory = analysisCache.getMethodAnalysis(
            ForwardTypeQualifierDataflowFactory.class, methodDescriptor);
    ForwardTypeQualifierDataflow forwardDataflow = forwardFactory.getDataflow(typeQualifierValue);
    analysis.setForwardTypeQualifierDataflow(forwardDataflow);
    analysis.registerSourceSinkLocations();

    BackwardTypeQualifierDataflow dataflow = new BackwardTypeQualifierDataflow(cfg, analysis);

    dataflow.execute();
    if (ClassContext.DUMP_DATAFLOW_ANALYSIS) {
        dataflow.dumpDataflow(analysis);
    }
    return dataflow;
}
 
Example 9
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {

        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        CFG cfg = classContext.getCFG(m);
        
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
            Location location = i.next();

            Instruction inst = location.getHandle().getInstruction();
            
            if (inst instanceof LDC) {
                LDC ldc = (LDC) inst;
                if (ldc != null) {
                    if("java.naming.security.authentication".equals(ldc.getValue(cpg)) &&
                       "none".equals(ByteCode.getConstantLDC(location.getHandle().getNext(), cpg, String.class))){
                        JavaClass clz = classContext.getJavaClass();
                        bugReporter.reportBug(new BugInstance(this, LDAP_ANONYMOUS, Priorities.LOW_PRIORITY) //
                        .addClass(clz)
                        .addMethod(clz, m)
                        .addSourceLine(classContext, m, location));
                        break;
                    }
                }
            }            
        }
    }
 
Example 10
public boolean matches(Instruction instruction, ConstantPoolGen cpg) {
    if(instruction != null && instruction instanceof InvokeInstruction) {
        InvokeInstruction invokeInstruction = (InvokeInstruction) instruction;
        if (classesNames.size() != 0 && !classesNames.contains(invokeInstruction.getClassName(cpg))) {
            return false;
        }
        else if (methodNames.size() != 0 && !methodNames.contains(invokeInstruction.getMethodName(cpg))) {
            return false;
        }
        else if (argSignatures.size() != 0 && !argSignatures.contains(invokeInstruction.getSignature(cpg))) {
            return false;
        }
        return true;
    }
    return false;
}
 
Example 11
private static Map<InstructionHandle, Call> buildCallMap(CFG cfg, ConstantPoolGen cpg) {
    Map<InstructionHandle, Call> callMap = new HashMap<>();

    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
        InstructionHandle handle = i.next().getHandle();
        Instruction ins = handle.getInstruction();

        if (ins instanceof InvokeInstruction) {
            InvokeInstruction inv = (InvokeInstruction) ins;
            Call call = new Call(inv.getClassName(cpg), inv.getName(cpg), inv.getSignature(cpg));
            callMap.put(handle, call);
        }
    }

    return callMap;
}
 
Example 12
Source Project: spotbugs   Source File: Stream.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public boolean isStreamOpen(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg, ResourceValueFrame frame) {
    if (isOpenOnCreation) {
        return false;
    }

    Instruction ins = handle.getInstruction();
    if (!(ins instanceof INVOKESPECIAL)) {
        return false;
    }

    // Does this instruction open the stream?
    INVOKESPECIAL inv = (INVOKESPECIAL) ins;

    return frame.isValid() && getInstanceValue(frame, inv, cpg).isInstance()
            && matchMethod(inv, cpg, this.getResourceClass(), Const.CONSTRUCTOR_NAME);
}
 
Example 13
@Override
public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg,
        RepositoryLookupFailureCallback lookupFailureCallback) {

    Instruction ins = location.getHandle().getInstruction();
    if (ins.getOpcode() != Const.GETSTATIC) {
        return null;
    }

    GETSTATIC getstatic = (GETSTATIC) ins;
    if (!className.equals(getstatic.getClassName(cpg)) || !fieldName.equals(getstatic.getName(cpg))
            || !fieldSig.equals(getstatic.getSignature(cpg))) {
        return null;
    }

    return new Stream(location, type.getClassName(), streamBaseClass).setIgnoreImplicitExceptions(true).setIsOpenOnCreation(
            true);
}
 
Example 14
public static boolean isNullCheck(InstructionHandle h, ConstantPoolGen cpg) {
    if (!(h.getInstruction() instanceof IFNONNULL)) {
        return false;
    }
    h = h.getNext();
    final Instruction newInstruction = h.getInstruction();
    if (!(newInstruction instanceof NEW)) {
        return false;
    }
    final ObjectType loadClassType = ((NEW) newInstruction).getLoadClassType(cpg);
    if (!"java.lang.NullPointerException".equals(loadClassType.getClassName())) {
        return false;
    }
    h = h.getNext();
    return check(h, NULLCHECK1) || check(h, NULLCHECK2);

}
 
Example 15
Source Project: spotbugs   Source File: Hierarchy.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Look up the field referenced by given FieldInstruction, returning it as
 * an {@link XField XField} object.
 *
 * @param fins
 *            the FieldInstruction
 * @param cpg
 *            the ConstantPoolGen used by the class containing the
 *            instruction
 * @return an XField object representing the field, or null if no such field
 *         could be found
 */
public static @CheckForNull XField findXField(FieldInstruction fins, @Nonnull ConstantPoolGen cpg) {

    String className = fins.getClassName(cpg);
    String fieldName = fins.getFieldName(cpg);
    String fieldSig = fins.getSignature(cpg);

    boolean isStatic = (fins.getOpcode() == Const.GETSTATIC || fins.getOpcode() == Const.PUTSTATIC);

    XField xfield = findXField(className, fieldName, fieldSig, isStatic);
    short opcode = fins.getOpcode();
    if (xfield != null && xfield.isResolved()
            && xfield.isStatic() == (opcode == Const.GETSTATIC || opcode == Const.PUTSTATIC)) {
        return xfield;
    } else {
        return null;
    }
}
 
Example 16
private Location getValueNumberCreationLocation(ValueNumberDataflow vnd, ValueNumber vn) {
    ConstantPoolGen cpg = vnd.getCFG().getMethodGen().getConstantPool();
    for (Iterator<Location> it = vnd.getCFG().locationIterator(); it.hasNext();) {
        Location loc = it.next();
        if (loc.getHandle().getInstruction().produceStack(cpg) != 1) {
            continue;
        }
        try {
            ValueNumberFrame vnf = vnd.getFactAfterLocation(loc);
            if (vnf.getTopValue().equals(vn)) {
                return loc;
            }
        } catch (DataflowAnalysisException e) {
            AnalysisContext.logError("While analyzing " + vnd.getCFG().getMethodGen() + " at " + loc, e);
        }
    }
    return null;
}
 
Example 17
Source Project: commons-bcel   Source File: PLSETestCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * BCEL-208: A couple of methods in MethodGen.java need to test for
 * an empty instruction list.
 */
public void testB208() throws ClassNotFoundException
{
    final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.PLSETestClass");
    final ClassGen gen = new ClassGen(clazz);
    final ConstantPoolGen pool = gen.getConstantPool();
    final Method m = gen.getMethodAt(1);
    final MethodGen mg = new MethodGen(m, gen.getClassName(), pool);
    mg.setInstructionList(null);
    mg.addLocalVariable("local2", Type.INT, null, null);
    // currently, this will cause null pointer exception
    mg.getLocalVariableTable(pool);
}
 
Example 18
/**
 * @param aInstruction
 * @param aPoolGen
 */
public GETFIELDReference(
    GETFIELD aInstruction,
    ConstantPoolGen aPoolGen)
{
    super(aInstruction, aPoolGen);
}
 
Example 19
@Override
protected void analyzeLocation(ClassContext classContext, Method method, InstructionHandle handle,
        ConstantPoolGen cpg, InvokeInstruction invoke, TaintFrame fact, String currentMethod)
        throws DataflowAnalysisException {
    SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(classContext, method, handle);
    checkSink(cpg, invoke, fact, sourceLine, currentMethod);
    InjectionPoint injectionPoint = getInjectionPoint(invoke, cpg, handle);
    for (int offset : injectionPoint.getInjectableArguments()) {
        int priority = getPriorityFromTaintFrame(fact, offset);
        if (priority == Priorities.IGNORE_PRIORITY) {
            continue;
        }

        Taint parameterTaint = fact.getStackValue(offset);

        InjectionSink injectionSink = new InjectionSink(this, injectionPoint.getBugType(), priority,
                classContext, method, handle, injectionPoint.getInjectableMethod());
        injectionSink.addLines(parameterTaint.getAllLocations());
        injectionSink.addUnknownSources(parameterTaint.getUnknownLocations());
        if (parameterTaint.hasParameters()) {
            // add sink to multi map
            Set<InjectionSink> sinkSet = injectionSinks.get(currentMethod);
            if (sinkSet == null) {
                sinkSet = new HashSet<InjectionSink>();
            }
            assert !sinkSet.contains(injectionSink) : "duplicate sink";
            sinkSet.add(injectionSink);
            injectionSinks.put(currentMethod, sinkSet);
            sinkTaints.put(new MethodAndSink(currentMethod, injectionSink), parameterTaint);
        } else {
            // sink cannot be influenced by other methods calls, so report it immediately
            bugReporter.reportBug(injectionSink.generateBugInstance(true));
        }
        return;
    }
}
 
Example 20
@Override
protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg,
        InstructionHandle handle) {
    InjectionPoint injectionPoint = null;
    for (InjectionSource source : getInjectionSource()) {
        injectionPoint = source.getInjectableParameters(invoke, cpg, handle);
        if (injectionPoint != InjectionPoint.NONE) {
            break;
        }
    }
    if (injectionPoint == null || injectionPoint == InjectionPoint.NONE) {
        injectionPoint = super.getInjectionPoint(invoke, cpg, handle);
    }
    return injectionPoint;
}
 
Example 21
/**
 * Constructs the object and stores the parameters
 * 
 * @param cpg constant pool gen for super class
 * @param method descriptor of analysed method
 * @param taintConfig current configured and derived taint summaries
 * @throws NullPointerException if arguments method or taintConfig is null
 */
public TaintFrameModelingVisitor(ConstantPoolGen cpg, MethodDescriptor method,
        TaintConfig taintConfig) {
    super(cpg);
    if (method == null) {
        throw new NullPointerException("null method descriptor");
    }
    if (taintConfig == null) {
        throw new NullPointerException("null taint config");
    }
    this.methodDescriptor = method;
    this.taintConfig = taintConfig;
    this.analyzedMethodConfig = new TaintMethodConfig(false);
}
 
Example 22
Source Project: annotation-tools   Source File: BCELPerfTest.java    License: MIT License 5 votes vote down vote up
byte[] nullAdaptClass(final InputStream is, final String name)
        throws Exception
{
    JavaClass jc = new ClassParser(is, name + ".class").parse();
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cp = cg.getConstantPool();
    Method[] ms = cg.getMethods();
    for (int j = 0; j < ms.length; ++j) {
        MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
        boolean lv = ms[j].getLocalVariableTable() == null;
        boolean ln = ms[j].getLineNumberTable() == null;
        if (lv) {
            mg.removeLocalVariables();
        }
        if (ln) {
            mg.removeLineNumbers();
        }
        mg.stripAttributes(skipDebug);
        InstructionList il = mg.getInstructionList();
        if (il != null) {
            InstructionHandle ih = il.getStart();
            while (ih != null) {
                ih = ih.getNext();
            }
            if (compute) {
                mg.setMaxStack();
                mg.setMaxLocals();
            }
        }
        cg.replaceMethod(ms[j], mg.getMethod());
    }
    return cg.getJavaClass().getBytes();
}
 
Example 23
/**
 * @param aInstruction
 * @param aPoolGen
 */
public GETFIELDReference(
    GETFIELD aInstruction,
    ConstantPoolGen aPoolGen)
{
    super(aInstruction, aPoolGen);
}
 
Example 24
Source Project: spotbugs   Source File: Hierarchy2.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Resolve possible instance method call targets.
 *
 * @param receiverType
 *            type of the receiver object
 * @param invokeInstruction
 *            the InvokeInstruction
 * @param cpg
 *            the ConstantPoolGen
 * @param receiverTypeIsExact
 *            if true, the receiver type is known exactly, which should
 *            allow a precise result
 * @return Set of methods which might be called
 * @throws ClassNotFoundException
 */
public static Set<XMethod> resolveMethodCallTargets(ReferenceType receiverType, InvokeInstruction invokeInstruction,
        ConstantPoolGen cpg, boolean receiverTypeIsExact) throws ClassNotFoundException {

    if (invokeInstruction.getOpcode() == Const.INVOKESTATIC) {
        throw new IllegalArgumentException();
    }

    String methodName = invokeInstruction.getName(cpg);
    String methodSig = invokeInstruction.getSignature(cpg);

    // Array method calls aren't virtual.
    // They should just resolve to Object methods.
    if (receiverType instanceof ArrayType) {
        try {
            return Util.emptyOrNonnullSingleton(getXClass(objectDescriptor).findMethod(methodName, methodSig, false));
        } catch (CheckedAnalysisException e) {
            return Collections.<XMethod>emptySet();
        }
    }

    if (receiverType instanceof ObjectType) {
        // Get the receiver class.
        String receiverClassName = ((ObjectType) receiverType).getClassName();

        return resolveVirtualMethodCallTargets(receiverClassName, methodName, methodSig, receiverTypeIsExact,
                invokeInstruction instanceof INVOKESPECIAL);
    }
    assert receiverType instanceof NullType;
    return Collections.<XMethod>emptySet();

}
 
Example 25
private Location nextLocation(Iterator<Location> i,ConstantPoolGen cpg) {
    Location loc = i.next();
    if(DEBUG) {
        ByteCode.printOpCode(loc.getHandle().getInstruction(), cpg);
    }
    return loc;
}
 
Example 26
Source Project: annotation-tools   Source File: BCELPerfTest.java    License: MIT License 5 votes vote down vote up
byte[] nullAdaptClass(final InputStream is, final String name)
        throws Exception
{
    JavaClass jc = new ClassParser(is, name + ".class").parse();
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cp = cg.getConstantPool();
    Method[] ms = cg.getMethods();
    for (int j = 0; j < ms.length; ++j) {
        MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
        boolean lv = ms[j].getLocalVariableTable() == null;
        boolean ln = ms[j].getLineNumberTable() == null;
        if (lv) {
            mg.removeLocalVariables();
        }
        if (ln) {
            mg.removeLineNumbers();
        }
        mg.stripAttributes(skipDebug);
        InstructionList il = mg.getInstructionList();
        if (il != null) {
            InstructionHandle ih = il.getStart();
            while (ih != null) {
                ih = ih.getNext();
            }
            if (compute) {
                mg.setMaxStack();
                mg.setMaxLocals();
            }
        }
        cg.replaceMethod(ms[j], mg.getMethod());
    }
    return cg.getJavaClass().getBytes();
}
 
Example 27
private Map<String, List<Location>> get_line_location(Method m, ClassContext classContext){
        HashMap<String, List<Location>> all_line_location = new HashMap<>();
        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        CFG cfg = null;
        try {
            cfg = classContext.getCFG(m);
        } catch (CFGBuilderException e) {
            e.printStackTrace();
            return all_line_location;
        }
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
            Location loc = i.next();
            Instruction inst = loc.getHandle().getInstruction();
            if(inst instanceof INVOKEVIRTUAL) {
                INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) inst;
//                if (classname.equals(invoke.getClassName(cpg)) &&
//                        methodName.equals(invoke.getMethodName(cpg))) {
                    if(all_line_location.containsKey(invoke.getMethodName(cpg))){
                        all_line_location.get(invoke.getMethodName(cpg)).add(loc);
                    }else {
                        LinkedList<Location> loc_list = new LinkedList<>();
                        loc_list.add(loc);
                        all_line_location.put(invoke.getMethodName(cpg), loc_list);
                    }
//                }
            }
        }
        return all_line_location;
    }
 
Example 28
/** @see com.puppycrawl.tools.checkstyle.bcel.IDeepVisitor */
public void visitObject(Object aObject)
{
    final JavaClass javaClass = (JavaClass) aObject;
    final ConstantPool pool = javaClass.getConstantPool();
    mCurrentPoolGen = new ConstantPoolGen(pool);
}
 
Example 29
/**
 * Creates the LDAPSocketFactoryImpl class (subclass of {@link AbstractLDAPSSLSocketFactory}.
 * A static method #getDefaulta, a static field _sslContent and no-arg constructor are added
 * to the class.
 *
 * @param className
 *
 * @return byte code
 */
private static byte[] createSubClassByteCode(final String className)
{
    ClassGen classGen = new ClassGen(className,
            AbstractLDAPSSLSocketFactory.class.getName(),
            "<generated>",
            ACC_PUBLIC | ACC_SUPER,
            null);
    ConstantPoolGen constantPoolGen = classGen.getConstantPool();
    InstructionFactory factory = new InstructionFactory(classGen);

    createSslContextStaticField(classGen, constantPoolGen);
    createGetDefaultStaticMethod(classGen, constantPoolGen, factory);

    classGen.addEmptyConstructor(ACC_PROTECTED);

    JavaClass javaClass = classGen.getJavaClass();
    ByteArrayOutputStream out = null;
    try
    {
        out = new ByteArrayOutputStream();
        javaClass.dump(out);
        return out.toByteArray();
    }
    catch (IOException ioex)
    {
        throw new IllegalStateException("Could not write to a ByteArrayOutputStream - should not happen", ioex);
    }
    finally
    {
        closeSafely(out);
    }
}
 
Example 30
@Override
public ObligationDataflow analyze(IAnalysisCache analysisCache, MethodDescriptor methodDescriptor)
        throws CheckedAnalysisException {
    CFG cfg = analysisCache.getMethodAnalysis(CFG.class, methodDescriptor);
    DepthFirstSearch dfs = analysisCache.getMethodAnalysis(DepthFirstSearch.class, methodDescriptor);
    XMethod xmethod = XFactory.createXMethod(methodDescriptor);
    ConstantPoolGen cpg = analysisCache.getClassAnalysis(ConstantPoolGen.class, methodDescriptor.getClassDescriptor());

    ObligationPolicyDatabase database = analysisCache.getDatabase(ObligationPolicyDatabase.class);

    TypeDataflow typeDataflow = analysisCache.getMethodAnalysis(TypeDataflow.class, methodDescriptor);
    IsNullValueDataflow invDataflow = analysisCache.getMethodAnalysis(IsNullValueDataflow.class, methodDescriptor);

    ObligationFactory factory = database.getFactory();

    ObligationAnalysis analysis = new ObligationAnalysis(dfs, xmethod, cpg, factory, database, typeDataflow, invDataflow,
            analysisCache.getErrorLogger());
    ObligationDataflow dataflow = new ObligationDataflow(cfg, analysis);

    Profiler profiler = analysisCache.getProfiler();
    profiler.start(analysis.getClass());
    try {
        dataflow.execute();
    } finally {
        profiler.end(analysis.getClass());
    }

    if (DEBUG_PRINTCFG) {
        System.out.println("Dataflow CFG:");
        DataflowCFGPrinter.printCFG(dataflow, System.out);
    }

    return dataflow;
}