Search in sources :

Example 36 with Type

use of org.apache.bcel.generic.Type in project jop by jop-devel.

the class SymbolicPointsTo method initial.

public ContextMap<CallString, SymbolicAddressMap> initial(InstructionHandle stmt) {
    ContextMap<CallString, SymbolicAddressMap> retval = new ContextMap<CallString, SymbolicAddressMap>(new Context(), new HashMap<CallString, SymbolicAddressMap>());
    SymbolicAddressMap init = new SymbolicAddressMap(bsFactory);
    // Add symbolic stack names
    int stackPtr = 0;
    if (!entryMethod.isStatic()) {
        init.putStack(stackPtr++, bsFactory.singleton(SymbolicAddress.rootAddress("$this")));
    }
    String[] args = entryMethod.getArgumentNames();
    for (int i = 0; i < args.length; i++) {
        Type ty = entryMethod.getArgumentType(i);
        if (ty instanceof ReferenceType) {
            init.putStack(stackPtr, bsFactory.singleton(SymbolicAddress.rootAddress("$" + args[i])));
        }
        stackPtr += ty.getSize();
    }
    retval.put(initialCallString, init);
    return retval;
}
Also used : Context(com.jopdesign.dfa.framework.Context) ReferenceType(org.apache.bcel.generic.ReferenceType) Type(org.apache.bcel.generic.Type) CallString(com.jopdesign.common.code.CallString) ContextMap(com.jopdesign.dfa.framework.ContextMap) ReferenceType(org.apache.bcel.generic.ReferenceType) CallString(com.jopdesign.common.code.CallString)

Example 37 with Type

use of org.apache.bcel.generic.Type in project contribution by checkstyle.

the class JavaClassDefinition method hasReference.

/**
 * Determines whether there is reference to a given Method in this JavaClass
 * definition or a definition in a superclass.
 * @param aMethodDef the Method to check.
 * @param aReferenceDAO reference DAO.
 * @return true if there is a reference to the method of aMethodDef in
 * this JavaClass or a superclass.
 */
public boolean hasReference(MethodDefinition aMethodDef, ReferenceDAO aReferenceDAO) {
    final String methodName = aMethodDef.getName();
    final Type[] argTypes = aMethodDef.getArgumentTypes();
    // search the inheritance hierarchy
    JavaClass currentJavaClass = getJavaClass();
    while (currentJavaClass != null) {
        final JavaClassDefinition javaClassDef = aReferenceDAO.findJavaClassDef(currentJavaClass);
        if (javaClassDef != null) {
            final MethodDefinition methodDef = javaClassDef.findNarrowestMethod(getJavaClass().getClassName(), methodName, argTypes);
            if ((methodDef != null) && (methodDef.hasReference(getJavaClass()))) {
                return true;
            }
        }
        currentJavaClass = currentJavaClass.getSuperClass();
    }
    return false;
}
Also used : Type(org.apache.bcel.generic.Type) JavaClass(org.apache.bcel.classfile.JavaClass)

Example 38 with Type

use of org.apache.bcel.generic.Type in project fb-contrib by mebigfatguy.

the class SloppyClassReflection method sawOpcode.

/**
 * overrides the visitor to find class loading that is non obfuscation proof
 *
 * @param seen
 *            the opcode that is being visited
 */
@Override
public void sawOpcode(int seen) {
    switch(state) {
        case COLLECT:
            if ((seen == INVOKESTATIC) || (seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE) || (seen == INVOKESPECIAL)) {
                refClasses.add(getClassConstantOperand());
                String signature = getSigConstantOperand();
                Type[] argTypes = Type.getArgumentTypes(signature);
                for (Type t : argTypes) {
                    addType(t);
                }
                Type resultType = Type.getReturnType(signature);
                addType(resultType);
            }
            break;
        case SEEN_NOTHING:
            if ((seen == LDC) || (seen == LDC_W)) {
                Constant c = getConstantRefOperand();
                if (c instanceof ConstantString) {
                    clsName = ((ConstantString) c).getBytes(getConstantPool());
                    state = State.SEEN_LDC;
                }
            }
            break;
        case SEEN_LDC:
            if ((seen == INVOKESTATIC) && "forName".equals(getNameConstantOperand()) && "java/lang/Class".equals(getClassConstantOperand()) && refClasses.contains(clsName)) {
                bugReporter.reportBug(new BugInstance(this, BugType.SCR_SLOPPY_CLASS_REFLECTION.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
            }
            state = State.SEEN_NOTHING;
            break;
    }
}
Also used : BugType(com.mebigfatguy.fbcontrib.utils.BugType) Type(org.apache.bcel.generic.Type) ConstantString(org.apache.bcel.classfile.ConstantString) Constant(org.apache.bcel.classfile.Constant) BugInstance(edu.umd.cs.findbugs.BugInstance) ConstantString(org.apache.bcel.classfile.ConstantString)

Example 39 with Type

use of org.apache.bcel.generic.Type in project fb-contrib by mebigfatguy.

the class SloppyClassReflection method visitMethod.

/**
 * overrides the visitor reset the opcode stack
 *
 * @param obj
 *            the method object of the currently parsed method
 */
@Override
public void visitMethod(Method obj) {
    if (Values.STATIC_INITIALIZER.equals(obj.getName())) {
        return;
    }
    if (state == State.COLLECT) {
        Type[] argTypes = obj.getArgumentTypes();
        for (Type t : argTypes) {
            addType(t);
        }
        Type resultType = obj.getReturnType();
        addType(resultType);
        LocalVariableTable lvt = obj.getLocalVariableTable();
        if (lvt != null) {
            LocalVariable[] lvs = lvt.getLocalVariableTable();
            if (lvs != null) {
                for (LocalVariable lv : lvs) {
                    if (lv != null) {
                        Type t = Type.getType(lv.getSignature());
                        addType(t);
                    }
                }
            }
        }
    } else {
        state = State.SEEN_NOTHING;
    }
    super.visitMethod(obj);
}
Also used : LocalVariableTable(org.apache.bcel.classfile.LocalVariableTable) BugType(com.mebigfatguy.fbcontrib.utils.BugType) Type(org.apache.bcel.generic.Type) LocalVariable(org.apache.bcel.classfile.LocalVariable)

Example 40 with Type

use of org.apache.bcel.generic.Type in project fb-contrib by mebigfatguy.

the class SignatureUtils method getFirstRegisterSlot.

/**
 * returns the first open register slot after parameters
 *
 * @param m
 *            the method for which you want the parameters
 * @return the first available register slot
 */
public static int getFirstRegisterSlot(Method m) {
    Type[] parms = m.getArgumentTypes();
    int first = m.isStatic() ? 0 : 1;
    for (Type t : parms) {
        first += getSignatureSize(t.getSignature());
    }
    return first;
}
Also used : Type(org.apache.bcel.generic.Type)

Aggregations

Type (org.apache.bcel.generic.Type)42 BugType (com.mebigfatguy.fbcontrib.utils.BugType)9 ObjectType (org.apache.bcel.generic.ObjectType)9 FieldInstruction (org.apache.bcel.generic.FieldInstruction)8 InstructionHandle (org.apache.bcel.generic.InstructionHandle)8 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)8 JavaClass (org.apache.bcel.classfile.JavaClass)7 Instruction (org.apache.bcel.generic.Instruction)7 InstructionList (org.apache.bcel.generic.InstructionList)7 ReferenceType (org.apache.bcel.generic.ReferenceType)7 Method (org.apache.bcel.classfile.Method)6 GETFIELD (org.apache.bcel.generic.GETFIELD)6 PUTFIELD (org.apache.bcel.generic.PUTFIELD)6 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)5 MethodGen (org.apache.bcel.generic.MethodGen)5 BranchInstruction (org.apache.bcel.generic.BranchInstruction)4 GETSTATIC (org.apache.bcel.generic.GETSTATIC)4 LDC (org.apache.bcel.generic.LDC)4 LoadInstruction (org.apache.bcel.generic.LoadInstruction)4 PUTSTATIC (org.apache.bcel.generic.PUTSTATIC)4