Search in sources :

Example 1 with BootstrapMethod

use of org.apache.bcel.classfile.BootstrapMethod in project fb-contrib by mebigfatguy.

the class OverlyPermissiveMethod method getBootstrapMethod.

@Nullable
private BootstrapMethod getBootstrapMethod(int bootstrapIndex) {
    for (Attribute a : cls.getAttributes()) {
        if ("BootstrapMethods".equals(a.getName())) {
            if (a instanceof BootstrapMethods) {
                BootstrapMethods bma = (BootstrapMethods) a;
                BootstrapMethod[] methods = bma.getBootstrapMethods();
                if (bootstrapIndex >= methods.length) {
                    return null;
                }
                return methods[bootstrapIndex];
            }
            throw new RuntimeException("Incompatible bcel version, the bcel that is in use, is too old and doesn't have attribute 'BootstrapMethods'");
        }
    }
    return null;
}
Also used : BootstrapMethod(org.apache.bcel.classfile.BootstrapMethod) Attribute(org.apache.bcel.classfile.Attribute) BootstrapMethods(org.apache.bcel.classfile.BootstrapMethods) Nullable(javax.annotation.Nullable)

Example 2 with BootstrapMethod

use of org.apache.bcel.classfile.BootstrapMethod in project fb-contrib by mebigfatguy.

the class OverlyPermissiveMethod method sawOpcode.

@Override
public void sawOpcode(int seen) {
    try {
        stack.precomputation(this);
        switch(seen) {
            case Const.INVOKEVIRTUAL:
            case Const.INVOKEINTERFACE:
            case Const.INVOKESTATIC:
            case Const.INVOKESPECIAL:
                {
                    String calledClass = getClassConstantOperand();
                    String sig = getSigConstantOperand();
                    MethodInfo mi = Statistics.getStatistics().getMethodStatistics(calledClass, getNameConstantOperand(), sig);
                    if (mi != null) {
                        if (seen == Const.INVOKEINTERFACE) {
                            mi.addCallingAccess(Const.ACC_PUBLIC);
                        } else {
                            String calledPackage;
                            int slashPos = calledClass.lastIndexOf('/');
                            if (slashPos >= 0) {
                                calledPackage = calledClass.substring(0, slashPos);
                            } else {
                                calledPackage = "";
                            }
                            boolean sameClass = calledClass.equals(callingClass);
                            boolean samePackage = calledPackage.equals(callingPackage);
                            if (sameClass) {
                                mi.addCallingAccess(Const.ACC_PRIVATE);
                            } else if (samePackage) {
                                mi.addCallingAccess(0);
                            } else {
                                if (seen == Const.INVOKESTATIC) {
                                    mi.addCallingAccess(Const.ACC_PUBLIC);
                                } else if (isCallingOnThis(sig)) {
                                    mi.addCallingAccess(Const.ACC_PROTECTED);
                                } else {
                                    mi.addCallingAccess(Const.ACC_PUBLIC);
                                }
                            }
                        }
                    }
                }
                break;
            case Const.INVOKEDYNAMIC:
                ConstantInvokeDynamic id = (ConstantInvokeDynamic) getConstantRefOperand();
                BootstrapMethod bm = getBootstrapMethod(id.getBootstrapMethodAttrIndex());
                if (bm != null) {
                    ConstantPool pool = getConstantPool();
                    ConstantMethodHandle mh = getFirstMethodHandle(pool, bm);
                    if (mh != null) {
                        ConstantCP ref = (ConstantCP) pool.getConstant(mh.getReferenceIndex());
                        ConstantClass cc = (ConstantClass) pool.getConstant(ref.getClassIndex());
                        String clz = ((ConstantUtf8) pool.getConstant(cc.getNameIndex())).getBytes();
                        ConstantNameAndType nameAndType = (ConstantNameAndType) pool.getConstant(ref.getNameAndTypeIndex());
                        String sig = ((ConstantUtf8) pool.getConstant(nameAndType.getSignatureIndex())).getBytes();
                        String name = ((ConstantUtf8) pool.getConstant(nameAndType.getNameIndex())).getBytes();
                        MethodInfo mi = Statistics.getStatistics().getMethodStatistics(clz, name, sig);
                        mi.addCallingAccess(Const.ACC_PUBLIC);
                    }
                }
                break;
            default:
                break;
        }
    } finally {
        stack.sawOpcode(this, seen);
    }
}
Also used : BootstrapMethod(org.apache.bcel.classfile.BootstrapMethod) ConstantPool(org.apache.bcel.classfile.ConstantPool) ConstantInvokeDynamic(org.apache.bcel.classfile.ConstantInvokeDynamic) MethodInfo(com.mebigfatguy.fbcontrib.collect.MethodInfo) ConstantMethodHandle(org.apache.bcel.classfile.ConstantMethodHandle) ConstantUtf8(org.apache.bcel.classfile.ConstantUtf8) ConstantCP(org.apache.bcel.classfile.ConstantCP) ConstantClass(org.apache.bcel.classfile.ConstantClass) ConstantNameAndType(org.apache.bcel.classfile.ConstantNameAndType)

Aggregations

BootstrapMethod (org.apache.bcel.classfile.BootstrapMethod)2 MethodInfo (com.mebigfatguy.fbcontrib.collect.MethodInfo)1 Nullable (javax.annotation.Nullable)1 Attribute (org.apache.bcel.classfile.Attribute)1 BootstrapMethods (org.apache.bcel.classfile.BootstrapMethods)1 ConstantCP (org.apache.bcel.classfile.ConstantCP)1 ConstantClass (org.apache.bcel.classfile.ConstantClass)1 ConstantInvokeDynamic (org.apache.bcel.classfile.ConstantInvokeDynamic)1 ConstantMethodHandle (org.apache.bcel.classfile.ConstantMethodHandle)1 ConstantNameAndType (org.apache.bcel.classfile.ConstantNameAndType)1 ConstantPool (org.apache.bcel.classfile.ConstantPool)1 ConstantUtf8 (org.apache.bcel.classfile.ConstantUtf8)1