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;
}
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);
}
}
Aggregations