@Override public void visitINVOKESTATIC(INVOKESTATIC ins) { // Find calls to System.exit(), since this effectively terminates the // basic block. String className = ins.getClassName(constPoolGen); String methodName = ins.getName(constPoolGen); String methodSig = ins.getSignature(constPoolGen); if ("java.lang.System".equals(className) && "exit".equals(methodName) && "(I)V".equals(methodSig)) { isExit = true; } }
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); }
@Override public void visitINVOKESTATIC(INVOKESTATIC obj) { if (returnsString(obj)) { consumeStack(obj); String className = obj.getClassName(getCPG()); if ("java.lang.String".equals(className)) { pushValue(dynamicStringTypeInstance); } else { pushReturnType(obj); } } else { super.visitINVOKESTATIC(obj); } }
/** * Get the InnerClassAccess for access method called by given INVOKESTATIC. * * @param inv * the INVOKESTATIC instruction * @param cpg * the ConstantPoolGen for the method * @return the InnerClassAccess, or null if the instruction is not an * inner-class access */ public static InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException { String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); InnerClassAccess access = AnalysisContext.currentAnalysisContext().getInnerClassAccessMap() .getInnerClassAccess(className, methodName); return (access != null && access.getMethodSignature().equals(methodSig)) ? access : null; }
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)) {
if (REDUNDANT_LOAD_ELIMINATION) { ConstantPoolGen cpg = getCPG(); String targetClassName = obj.getClassName(cpg); String methodName = obj.getName(cpg); String methodSig = obj.getSignature(cpg);
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)); }
@Override public void visitINVOKESTATIC(INVOKESTATIC ins) { // Find calls to System.exit(), since this effectively terminates the // basic block. String className = ins.getClassName(constPoolGen); String methodName = ins.getName(constPoolGen); String methodSig = ins.getSignature(constPoolGen); if ("java.lang.System".equals(className) && "exit".equals(methodName) && "(I)V".equals(methodSig)) { isExit = true; } }
public INVOKESTATIC nextInvokeStatic(String className) { for (; index < handles.length; index++) { if (index > -1) { if (handles[index].getInstruction() instanceof INVOKESTATIC) { INVOKESTATIC methodCall = (INVOKESTATIC) handles[index].getInstruction(); if (methodCall.getClassName(cpg).equals(className)) { return methodCall; } } } } return null; }
/** * 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 getCallClassName(Instruction ins, ConstantPoolGen cp) { if (ins instanceof INVOKESTATIC) { INVOKESTATIC invst = (INVOKESTATIC) ins; return invst.getClassName(cp); } else if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL invst = (INVOKEVIRTUAL) ins; return invst.getClassName(cp); } else if (ins instanceof INVOKEINTERFACE) { INVOKEINTERFACE invst = (INVOKEINTERFACE) ins; return invst.getClassName(cp); } else if (ins instanceof INVOKESPECIAL) { INVOKESPECIAL invst = (INVOKESPECIAL) ins; return invst.getClassName(cp); } else { return null; } }
@Override public void visitINVOKESTATIC(INVOKESTATIC obj) { if (returnsString(obj)) { consumeStack(obj); String className = obj.getClassName(getCPG()); if ("java.lang.String".equals(className)) { pushValue(dynamicStringTypeInstance); } else { pushReturnType(obj); } } else { super.visitINVOKESTATIC(obj); } }
/** * Get the InnerClassAccess for access method called by given INVOKESTATIC. * * @param inv * the INVOKESTATIC instruction * @param cpg * the ConstantPoolGen for the method * @return the InnerClassAccess, or null if the instruction is not an * inner-class access */ public static InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException { String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); InnerClassAccess access = AnalysisContext.currentAnalysisContext().getInnerClassAccessMap() .getInnerClassAccess(className, methodName); return (access != null && access.getMethodSignature().equals(methodSig)) ? access : null; }
/** 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); } }
/** 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."); } }
if (handles[i].getInstruction() instanceof INVOKESTATIC && GenericMethods.isNumber(handles[i - 1].getInstruction())) { INVOKESTATIC methodCall = (INVOKESTATIC) handles[i].getInstruction(); if (methodCall.getClassName(cg.getConstantPool()).contains(LoaderClass.getClassName())) { int push = GenericMethods.getValueOfNumber(handles[i - 1].getInstruction(), cg.getConstantPool()); String decryptedString = StoreHandler.I(push);