private boolean isSleep(INVOKESTATIC ins, ConstantPoolGen cpg) { String className = ins.getClassName(cpg); if (!"java.lang.Thread".equals(className)) { return false; } String methodName = ins.getMethodName(cpg); String signature = ins.getSignature(cpg); return "sleep".equals(methodName) && ("(J)V".equals(signature) || "(JI)V".equals(signature)); }
/** * Get the inner class access object for given invokestatic instruction. * Returns null if the called method is not an inner class access. * * @param inv * the invokestatic instruction * @param cpg * the ConstantPoolGen for the method * @return the InnerClassAccess, or null if the call is not an inner class * access */ public InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException { String methodName = inv.getMethodName(cpg); if (methodName.startsWith("access$")) { String className = inv.getClassName(cpg); return getInnerClassAccess(className, methodName); } return null; }
@Override public void visitINVOKESTATIC(INVOKESTATIC obj) { String methodName = obj.getMethodName(cpg); String signature = obj.getSignature(cpg); String className = obj.getClassName(cpg); if ("asList".equals(methodName) && "java.util.Arrays".equals(className) && "([Ljava/lang/Object;)Ljava/util/List;".equals(signature)) { consumeStack(obj); Type returnType = Type.getType("Ljava/util/Arrays$ArrayList;"); pushValue(returnType); return; } visitInvokeInstructionCommon(obj); }
if ("java.lang.Integer".equals(invoke.getClassName(cpg)) && "toHexString".equals(invoke.getMethodName(cpg))) { invokeToHexString = true;
if ("javax.crypto.KeyGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) { String value = ByteCode.getConstantLDC(location.getHandle().getPrev(), cpg, String.class); if ("Blowfish".equals(value)) {
} else if (ins instanceof InvokeInstruction) { if (ins instanceof INVOKESTATIC && ((INVOKESTATIC) ins).getMethodName(classContext.getConstantPoolGen()).startsWith("new")) { sawNEW = true;
String name = is.getMethodName(cpg); String signature = is.getSignature(cpg); if (name.startsWith("access$")) {
if (next != null && next.getInstruction() instanceof INVOKESTATIC) { INVOKESTATIC is = (INVOKESTATIC) next.getInstruction(); if ("assertFalse".equals(is.getMethodName(cpg))) { return;
private boolean isSleep(INVOKESTATIC ins, ConstantPoolGen cpg) { String className = ins.getClassName(cpg); if (!"java.lang.Thread".equals(className)) { return false; } String methodName = ins.getMethodName(cpg); String signature = ins.getSignature(cpg); return "sleep".equals(methodName) && ("(J)V".equals(signature) || "(JI)V".equals(signature)); }
/** * Get the inner class access object for given invokestatic instruction. * Returns null if the called method is not an inner class access. * * @param inv * the invokestatic instruction * @param cpg * the ConstantPoolGen for the method * @return the InnerClassAccess, or null if the call is not an inner class * access */ public InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException { String methodName = inv.getMethodName(cpg); if (methodName.startsWith("access$")) { String className = inv.getClassName(cpg); return getInnerClassAccess(className, methodName); } return null; }
@Override public void visitINVOKESTATIC(INVOKESTATIC obj) { String methodName = obj.getMethodName(cpg); String signature = obj.getSignature(cpg); String className = obj.getClassName(cpg); if ("asList".equals(methodName) && "java.util.Arrays".equals(className) && "([Ljava/lang/Object;)Ljava/util/List;".equals(signature)) { consumeStack(obj); Type returnType = Type.getType("Ljava/util/Arrays$ArrayList;"); pushValue(returnType); return; } visitInvokeInstructionCommon(obj); }
public static String getCallMethodName(Instruction ins, ConstantPoolGen cp) { if (ins instanceof INVOKESTATIC) { INVOKESTATIC invst = (INVOKESTATIC) ins; return invst.getMethodName(cp); } else if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL invst = (INVOKEVIRTUAL) ins; return invst.getMethodName(cp); } else if (ins instanceof INVOKEINTERFACE) { INVOKEINTERFACE invst = (INVOKEINTERFACE) ins; return invst.getMethodName(cp); } else if (ins instanceof INVOKESPECIAL) { INVOKESPECIAL invst = (INVOKESPECIAL) ins; return invst.getMethodName(cp); } else { return null; } }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ public void visitINVOKESTATIC(INVOKESTATIC o){ // INVOKESTATIC is a LoadClass; the Class where the referenced method is declared in, // is therefore resolved/verified. // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified, // too. So are the allowed method names. String classname = o.getClassName(cpg); JavaClass jc = Repository.lookupClass(classname); Method[] ms = jc.getMethods(); Method m = null; for (int i=0; i<ms.length; i++){ if ( (ms[i].getName().equals(o.getMethodName(cpg))) && (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) && (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){ m = ms[i]; break; } } if (m == null){ constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature not found in class '"+jc.getClassName()+"'. The native verifier possibly allows the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not."); } if (! (m.isStatic())){ // implies it's not abstract, verified in pass 2. constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset."); } }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override public void visitINVOKESTATIC(final INVOKESTATIC o) { try { // INVOKESTATIC is a LoadClass; the Class where the referenced method is declared in, // is therefore resolved/verified. // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified, // too. So are the allowed method names. final String classname = o.getClassName(cpg); final JavaClass jc = Repository.lookupClass(classname); final Method m = getMethodRecursive(jc, o); if (m == null) { constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+ o.getSignature(cpg) +"' not found in class '"+jc.getClassName()+"'."); } else if (! (m.isStatic())) { // implies it's not abstract, verified in pass 2. constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset."); } } catch (final ClassNotFoundException e) { // FIXME: maybe not the best way to handle this throw new AssertionViolatedException("Missing class: " + e, e); } }
if ("java.lang.Integer".equals(invoke.getClassName(cpg)) && "toHexString".equals(invoke.getMethodName(cpg))) { invokeToHexString = true;
if ("java.security.KeyPairGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) { String value = ByteCode.getConstantLDC(location.getHandle().getPrev(), cpg, String.class); if (value != null && value.toUpperCase().startsWith("RSA")) {
if ("java.security.KeyPairGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) { final List<Type> argumentTypes = Arrays.asList(invoke.getArgumentTypes(cpg)); String value = null;
if ("javax.crypto.KeyGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) { String value = ByteCode.getConstantLDC(location.getHandle().getPrev(), cpg, String.class); if ("Blowfish".equals(value)) {
String mcall = invoke.getMethodName(cg.getConstantPool()); if (call.equals(decryptorclass) && mcall.equals(decryptor)) { LDC orig = ((LDC) handles[i].getInstruction());
String name = is.getMethodName(cpg); String signature = is.getSignature(cpg); if (name.startsWith("access$")) {