public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); try { if (ins instanceof InvokeInstruction) { if (!Hierarchy.isSubtype(type, baseClassType)) return null; Stream stream = new Stream(location, type.getClassName(), baseClassType.getClassName()) .setIsOpenOnCreation(true) .setIgnoreImplicitExceptions(true); if (bugType != null) stream.setInteresting(bugType); return stream; } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return null; }
public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); if (ins.getOpcode() != Constants.GETSTATIC) return null; GETSTATIC getstatic = (GETSTATIC) ins; if (!className.equals(getstatic.getClassName(cpg)) || !fieldName.equals(getstatic.getName(cpg)) || !fieldSig.equals(getstatic.getSignature(cpg))) return null; return new Stream(location, type.getClassName(), streamBaseClass) .setIgnoreImplicitExceptions(true) .setIsOpenOnCreation(true); }
private ResourceCollection<Resource> buildResourceCollection(ClassContext classContext, Method method, ResourceTrackerType resourceTracker) throws CFGBuilderException, DataflowAnalysisException { ResourceCollection<Resource> resourceCollection = new ResourceCollection<Resource>(); CFG cfg = classContext.getCFG(method); ConstantPoolGen cpg = classContext.getConstantPoolGen(); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Resource resource = resourceTracker.isResourceCreation(location.getBasicBlock(), location.getHandle(), cpg); if (resource != null) resourceCollection.addCreatedResource(location, resource); } return resourceCollection; }
private Set<MethodAndSink> getSinks(ConstantPoolGen cpg, InvokeInstruction invoke, TaintFrame frame) { String className = getInstanceClassName(cpg, invoke, frame); String methodName = "." + invoke.getMethodName(cpg) + invoke.getSignature(cpg); String fullMethodName = className.concat(methodName); Set<InjectionSink> sinks = injectionSinks.get(fullMethodName); if (sinks != null) { assert !sinks.isEmpty() : "empty set of sinks"; return getMethodAndSinks(fullMethodName, sinks); } try { if (className.endsWith("]")) { // not a real class return Collections.emptySet(); } JavaClass javaClass = Repository.lookupClass(className); assert javaClass != null; return getSuperSinks(javaClass, methodName); } catch (ClassNotFoundException ex) { AnalysisContext.reportMissingClass(ex); } return Collections.emptySet(); }
private static String getInstanceClassName(ConstantPoolGen cpg, InvokeInstruction invoke, TaintFrame frame) { try { int instanceIndex = frame.getNumArgumentsIncludingObjectInstance(invoke, cpg) - 1; if (instanceIndex != -1) { assert instanceIndex < frame.getStackDepth(); Taint instanceTaint = frame.getStackValue(instanceIndex); String className = instanceTaint.getRealInstanceClassName(); if (className != null) { return className; } } } catch (DataflowAnalysisException ex) { assert false : ex.getMessage(); } String dottedClassName = invoke.getReferenceType(cpg).toString(); return ClassName.toSlashedClassName(dottedClassName); }
@Override protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg, InstructionHandle handle) { assert invoke != null && cpg != null; String method = invoke.getMethodName(cpg); String sig = invoke.getSignature(cpg); if(sig.startsWith("(Ljava/lang/String;)")) { if(method.startsWith("set")) { // Targeting : x.setPassword("abc123") String methodLowerCase = method.toLowerCase(); for (String password : PASSWORD_WORDS) { if (methodLowerCase.contains(password)) { return new InjectionPoint(new int[]{0}, HARD_CODE_PASSWORD_TYPE); } } } else if(PASSWORD_WORDS.contains(method.toLowerCase())) { // Targeting : DSL().user("").password(String x) return new InjectionPoint(new int[]{0}, HARD_CODE_PASSWORD_TYPE); } } return InjectionPoint.NONE; }
/** * Check if the readObject is doing multiple external call beyond the basic readByte, readBoolean, etc.. * @param m * @param classContext * @return * @throws CFGBuilderException * @throws DataflowAnalysisException */ private boolean hasCustomReadObject(Method m, ClassContext classContext,List<String> classesToIgnore) throws CFGBuilderException, DataflowAnalysisException { ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = classContext.getCFG(m); int count = 0; for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location location = i.next(); Instruction inst = location.getHandle().getInstruction(); //ByteCode.printOpCode(inst,cpg); if(inst instanceof InvokeInstruction) { InvokeInstruction invoke = (InvokeInstruction) inst; if (!READ_DESERIALIZATION_METHODS.contains(invoke.getMethodName(cpg)) && !classesToIgnore.contains(invoke.getClassName(cpg))) { count +=1; } } } return count > 3; }
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException { MethodGen methodGen = classContext.getMethodGen(m); ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = classContext.getCFG(m); if (methodGen == null || methodGen.getInstructionList() == null) { return; //No instruction .. nothing to do } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location location = i.next(); Instruction inst = location.getHandle().getInstruction(); if (inst instanceof InvokeInstruction) { InvokeInstruction invoke = (InvokeInstruction) inst; String methodName = invoke.getMethodName(cpg); if ("enableDefaultTyping".equals(methodName)) { JavaClass clz = classContext.getJavaClass(); bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY) .addClass(clz) .addMethod(clz, m) .addCalledMethod(cpg, invoke) .addSourceLine(classContext, m, location) ); } } } }
@Override protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg, InstructionHandle handle) { assert invoke != null && cpg != null; String method = invoke.getMethodName(cpg); String sig = invoke.getSignature(cpg); if(method.equals("registerReceiver")){ if(sig.contains("Ljava/lang/String;")){ if(sig.contains(";I)")){ return new InjectionPoint(new int[]{2}, ANDROID_REGISTER_RECEIVER_TYPE); }else{ return new InjectionPoint(new int[]{1}, ANDROID_REGISTER_RECEIVER_TYPE); } } } return InjectionPoint.NONE; }
@Override protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg, InstructionHandle handle) { assert invoke != null && cpg != null; String method = invoke.getMethodName(cpg); String sig = invoke.getSignature(cpg); // System.out.println(invoke.getClassName(cpg)); if(sig.contains("Ljava/lang/String;")) { if("loadUrl".equals(method)){ if(sig.contains("Ljava/util/Map;")){ return new InjectionPoint(new int[]{1}, WEBVIEW_LOAD_DATA_URL_TYPE); }else{ return new InjectionPoint(new int[]{0}, WEBVIEW_LOAD_DATA_URL_TYPE); } }else if("loadData".equals(method)){ return new InjectionPoint(new int[]{2}, WEBVIEW_LOAD_DATA_URL_TYPE); }else if("loadDataWithBaseURL".equals(method)){ //BUG return new InjectionPoint(new int[]{4}, WEBVIEW_LOAD_DATA_URL_TYPE); } } return InjectionPoint.NONE; }
@Override protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg, InstructionHandle handle) { assert invoke != null && cpg != null; String method = invoke.getMethodName(cpg); String sig = invoke.getSignature(cpg); // System.out.println(sig); if(sig.contains("Ljava/lang/String;")) { if(method.contains("send") && method.contains("Broadcast") && !method.contains("Sticky")){ // System.out.println(method); if("sendOrderedBroadcastAsUser".equals(method)){ return new InjectionPoint(new int[]{5}, ANDROID_BROADCAST_TYPE); } if("sendOrderedBroadcast".equals(method) && sig.contains("Landroid/content/BroadcastReceiver;")){ return new InjectionPoint(new int[]{5}, ANDROID_BROADCAST_TYPE); } return new InjectionPoint(new int[]{0}, ANDROID_BROADCAST_TYPE); } } return InjectionPoint.NONE; }
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException { ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = classContext.getCFG(m); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location location = i.next(); Instruction inst = location.getHandle().getInstruction(); if (inst instanceof LDC) { LDC ldc = (LDC) inst; if (ldc != null) { if("java.naming.security.authentication".equals(ldc.getValue(cpg)) && "none".equals(ByteCode.getConstantLDC(location.getHandle().getNext(), cpg, String.class))){ JavaClass clz = classContext.getJavaClass(); bugReporter.reportBug(new BugInstance(this, LDAP_ANONYMOUS, Priorities.LOW_PRIORITY) // .addClass(clz) .addMethod(clz, m) .addSourceLine(classContext, m, location)); break; } } } } }
public boolean matches(Instruction instruction, ConstantPoolGen cpg) { if(instruction != null && instruction instanceof InvokeInstruction) { InvokeInstruction invokeInstruction = (InvokeInstruction) instruction; if (classesNames.size() != 0 && !classesNames.contains(invokeInstruction.getClassName(cpg))) { return false; } else if (methodNames.size() != 0 && !methodNames.contains(invokeInstruction.getMethodName(cpg))) { return false; } else if (argSignatures.size() != 0 && !argSignatures.contains(invokeInstruction.getSignature(cpg))) { return false; } return true; } return false; }
private void generateFields(RootClass k, ConstantPoolGen cp, ClassGen cg) { RootMember[] members = k.getMembers(); for (int i = 0; i < members.length; i++) { if (cg.containsField(members[i].getName()) == null) { Type type = ((BasicMember) members[i]).getJavaType(); if (type != null) { FieldGen fg = new FieldGen(ACC_PRIVATE, type, members[i].getName(), cp); cg.addField(fg.getField()); } } } }
SpawningMethod (Method method, String className, ConstantPoolGen constantPoolGen, SpawnSignature spawnSignature, int indexSync, Debug d) throws NoSpawningMethodException, AssumptionFailure { super(method, className, constantPoolGen); if (callsSync()) { throw new MethodCallsSyncException(); } MethodGen spawnSignatureGen = new MethodGen(spawnSignature.getMethod(), spawnSignature.getClassName(), constantPoolGen); ArrayList<SpawnableCall> spawnableCalls = getSpawnableCalls(constantPoolGen, spawnSignatureGen); if (spawnableCalls.size() > 0) { this.spawnableCalls = spawnableCalls; this.indexSync = indexSync; // this.spawnSignature = spawnSignature; this.d = d; } else { throw new NoSpawningMethodException(); } }
private boolean callsSync() { ConstantPoolGen cpg = getConstantPool(); InstructionList instructionList = getInstructionList(); InstructionHandle handle = instructionList.getStart(); while (handle != null) { Instruction ins = handle.getInstruction(); if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins; if (inv.getMethodName(cpg).equals("sync") && inv.getSignature(cpg).equals("()V")) { JavaClass cl = findMethodClass(inv, cpg); if (cl != null && cl.getClassName().equals("ibis.cashmere.CashmereObject")) { return true; } } } handle = handle.getNext(); } return false; }
/** Instantiate from an existing method. * * @param method method * @param className class name containing this method * @param constantPoolGen constant pool */ public MethodGen(Method method, String className, ConstantPoolGen constantPoolGen) { super(method, className, constantPoolGen); // Analyze how many stack positions are for parameters. // We won't touch those. parameterPos = isStatic() ? 0 : 1; Type[] parameters = getArgumentTypes(); parameterPos += parameters.length; for (int i = 0; i < parameters.length; i++) { if (parameters[i].equals(Type.LONG) || parameters[i].equals(Type.DOUBLE)) { parameterPos++; } } }
void showControlFlow4(PrintStream out, JavaClass javaClass, Method method) { out.println("Control flow:"); MethodGen methodGen = new MethodGen(method, javaClass.getClassName(), new ConstantPoolGen(javaClass.getConstantPool())); BasicBlockGraph basicBlockGraph = new BasicBlockGraph(methodGen); out.println(basicBlockGraph); out.println(); /* out.println("Ending paths:"); ArrayList<Path> paths = basicBlockGraph.getEndingPathsFrom(0); printPaths(paths); */ }
void showClass(PrintStream out, JavaClass javaClass) { print(out, 0, "constantpool:\n"); out.println(javaClass.getConstantPool()); ConstantPoolGen cp = new ConstantPoolGen(javaClass.getConstantPool()); Method[] methods = javaClass.getMethods(); for (Method method : methods) { MethodGen methodGen = new MethodGen(method, javaClass.getClassName(), cp); print(out, 0, "%s (with stack consumption)\n", method); showMethod(out, methodGen, javaClass.getConstantPool()); out.println(); print(out, 0, "%s\n", method); if (method.getCode() != null) out.println((method.getCode()).toString(true)); out.println(); } }
/** * Find the declared exceptions for the method called by given instruction. * * @param inv * the InvokeInstruction * @param cpg * the ConstantPoolGen used by the class the InvokeInstruction * belongs to * @return array of ObjectTypes of thrown exceptions, or null if we can't * find the method implementation */ public static @CheckForNull ObjectType[] findDeclaredExceptions(InvokeInstruction inv, ConstantPoolGen cpg) { XMethod method = findInvocationLeastUpperBound(inv, cpg, inv instanceof INVOKESTATIC ? Hierarchy.STATIC_METHOD : Hierarchy.INSTANCE_METHOD); if (method == null) return null; String[] exceptions = method.getThrownExceptions(); if (exceptions == null) return new ObjectType[0]; ObjectType[] result = new ObjectType[exceptions.length]; for (int i = 0; i < exceptions.length; ++i) { result[i] = ObjectTypeFactory.getInstance(ClassName.toDottedClassName(exceptions[i])); } return result; }
public boolean preScreen(MethodGen mg) { ConstantPoolGen cpg = mg.getConstantPool(); int lockCount = mg.isSynchronized() ? 1 : 0; boolean sawWaitOrNotify = false; InstructionHandle handle = mg.getInstructionList().getStart(); while (handle != null && !(lockCount >= 2 && sawWaitOrNotify)) { Instruction ins = handle.getInstruction(); if (ins instanceof MONITORENTER) ++lockCount; else if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins; String methodName = inv.getMethodName(cpg); if (methodName.equals("wait") || methodName.startsWith("notify")) sawWaitOrNotify = true; } handle = handle.getNext(); } return lockCount >= 2 && sawWaitOrNotify; }
@CheckForNull Use getUse(ConstantPoolGen cpg, Instruction ins) { if (ins instanceof InvokeInstruction) { InvokeInstruction invoke = (InvokeInstruction) ins; String mName = invoke.getMethodName(cpg); String cName = invoke.getClassName(cpg); if (mName.equals("setAttribute") && cName.equals("javax.servlet.http.HttpSession")) return Use.STORE_INTO_HTTP_SESSION; if (mName.equals("writeObject") && (cName.equals("java.io.ObjectOutput") || cName.equals("java.io.ObjectOutputStream"))) return Use.PASSED_TO_WRITE_OBJECT; } return null; }
public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); try { if (ins instanceof InvokeInstruction) { if (!Hierarchy.isSubtype(type, baseClassType)) return null; Stream stream = new Stream(location, type.getClassName(), baseClassType.getClassName()).setIsOpenOnCreation(true) .setIgnoreImplicitExceptions(true); if (bugType != null) stream.setInteresting(bugType); return stream; } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return null; }
private StringAppendState updateStringAppendState(Location location, ConstantPoolGen cpg, StringAppendState stringAppendState) { InstructionHandle handle = location.getHandle(); Instruction ins = handle.getInstruction(); if (!isConstantStringLoad(location, cpg)) { throw new IllegalArgumentException("instruction must be LDC"); } LDC load = (LDC) ins; Object value = load.getValue(cpg); String stringValue = ((String) value).trim(); if (stringValue.startsWith(",") || stringValue.endsWith(",")) stringAppendState.setSawComma(handle); if (isCloseQuote(stringValue) && stringAppendState.getSawOpenQuote(handle)) stringAppendState.setSawCloseQuote(handle); if (isOpenQuote(stringValue)) stringAppendState.setSawOpenQuote(handle); return stringAppendState; }
private static <DescriptorType> Map<DescriptorType, Object> createMap( final Map<Class<?>, ? extends IAnalysisEngine<DescriptorType, ?>> engineMap, final Class<?> analysisClass) { Map<DescriptorType, Object> descriptorMap; // Create a MapCache that allows the analysis engine to // decide that analysis results should be retained indefinitely. IAnalysisEngine<DescriptorType, ?> engine = engineMap.get(analysisClass); if (analysisClass.equals(JavaClass.class)) { descriptorMap = new MapCache<DescriptorType, Object>(MAX_JAVACLASS_RESULTS_TO_CACHE); } else if (analysisClass.equals(FBClassReader.class)) { descriptorMap = new MapCache<DescriptorType, Object>(MAX_FBCLASSREADER_RESULTS_TO_CACHE); } else if (analysisClass.equals(ConstantPoolGen.class)) { descriptorMap = new MapCache<DescriptorType, Object>(MAX_CONSTANT_POOL_GEN_RESULTS_TO_CACHE); } else if (analysisClass.equals(ClassContext.class)) { descriptorMap = new MapCache<DescriptorType, Object>(10); } else if (engine instanceof IClassAnalysisEngine && ((IClassAnalysisEngine<?>) engine).canRecompute()) { descriptorMap = new MapCache<DescriptorType, Object>(MAX_CLASS_RESULTS_TO_CACHE); } else { descriptorMap = new HashMap<DescriptorType, Object>(); } return descriptorMap; }
public static Set<ValueNumber> checkAllNonNullParams(Location location, ValueNumberFrame vnaFrame, ConstantPoolGen constantPool, @CheckForNull Method method, @CheckForNull IsNullValueDataflow invDataflow, TypeDataflow typeDataflow) throws DataflowAnalysisException { IsNullValueFrame invFrame = null; if (invDataflow != null) { invFrame = invDataflow.getFactAtLocation(location); } Set<ValueNumber> result1 = checkNonNullParams(location, vnaFrame, constantPool, method, invFrame); Set<ValueNumber> result2 = checkUnconditionalDerefDatabase(location, vnaFrame, constantPool, invFrame, typeDataflow); if (result1.isEmpty()) return result2; if (result2.isEmpty()) return result1; result1.addAll(result2); return result1; }
/** * Look up the field referenced by given FieldInstruction, returning it as * an {@link XField XField} object. * * @param fins * the FieldInstruction * @param cpg * the ConstantPoolGen used by the class containing the * instruction * @return an XField object representing the field, or null if no such field * could be found */ public static @CheckForNull XField findXField(FieldInstruction fins, @Nonnull ConstantPoolGen cpg) { String className = fins.getClassName(cpg); String fieldName = fins.getFieldName(cpg); String fieldSig = fins.getSignature(cpg); boolean isStatic = (fins.getOpcode() == Constants.GETSTATIC || fins.getOpcode() == Constants.PUTSTATIC); XField xfield = findXField(className, fieldName, fieldSig, isStatic); short opcode = fins.getOpcode(); if (xfield != null && xfield.isResolved() && xfield.isStatic() == (opcode == Constants.GETSTATIC || opcode == Constants.PUTSTATIC)) return xfield; else return null; }
public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { try { Instruction ins = location.getHandle().getInstruction(); if (ins.getOpcode() != Constants.NEW) return null; if (Hierarchy.isSubtype(type, baseClassType)) { boolean isUninteresting = false; for (int i = 0; i < uninterestingSubclassTypeList.length; ++i) { if (Hierarchy.isSubtype(type, uninterestingSubclassTypeList[i])) { isUninteresting = true; break; } } Stream result = new Stream(location, type.getClassName(), baseClassType.getClassName()) .setIgnoreImplicitExceptions(true); if (!isUninteresting) result.setInteresting(bugType); return result; } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return null; }
public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); if (ins.getOpcode() != Constants.GETFIELD) return null; String fieldClass = type.getClassName(); try { if (fieldClass.startsWith("[")) return null; if (!Hierarchy.isSubtype(fieldClass, streamBaseClass)) return null; Stream stream = new Stream(location, fieldClass, streamBaseClass); stream.setIsOpenOnCreation(true); stream.setOpenLocation(location); if (bugPatternType != null) stream.setInteresting(bugPatternType); //System.out.println("Instance field stream at " + location); return stream; } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); return null; } }
/** * Add a method annotation for the method which is called by given * instruction. * * @param methodGen the method containing the call * @param inv the InvokeInstruction * @return this object */ public BugInstance addCalledMethod(MethodGen methodGen, InvokeInstruction inv) { ConstantPoolGen cpg = methodGen.getConstantPool(); String className = inv.getClassName(cpg); String methodName = inv.getMethodName(cpg); String methodSig = inv.getSignature(cpg); addMethod(className, methodName, methodSig); describe("METHOD_CALLED"); return this; }
/** * 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; }
public PruneUnconditionalExceptionThrowerEdges(MethodGen methodGen, CFG cfg, ConstantPoolGen cpg, AnalysisContext analysisContext) { this.methodGen = methodGen; this.cfg = cfg; this.cpg = cpg; this.analysisContext = analysisContext; }
public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException { if (handle.getInstruction().getOpcode() == opcode) return new MatchResult(this, bindingSet); else return null; }
public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException { Instruction ins = handle.getInstruction(); if (!(ins instanceof NEW)) return null; LocalVariable result = new LocalVariable(after.getTopValue()); return addOrCheckDefinition(result, bindingSet); }
public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException { // See if the instruction is an InvokeInstruction Instruction ins = handle.getInstruction(); if (!(ins instanceof InvokeInstruction)) return null; InvokeInstruction inv = (InvokeInstruction) ins; String methodName = inv.getMethodName(cpg); boolean isStatic = inv.getOpcode() == Constants.INVOKESTATIC; boolean isCtor = methodName.equals("<init>"); int actualMode = 0; if (isStatic) actualMode |= STATIC; if (isCtor) actualMode |= CONSTRUCTOR; if (!isStatic && !isCtor) actualMode |= INSTANCE; // Intersection of actual and desired modes must be nonempty. if ((actualMode & mode) == 0) return null; // Check class name, method name, and method signature. if (!methodNameMatcher.match(methodName) || !methodSigMatcher.match(inv.getSignature(cpg)) || !classNameMatcher.match(inv.getClassName(cpg))) return null; // It's a match! return new MatchResult(this, bindingSet); }
public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException { // Instruction must be MONITORENTER. Instruction ins = handle.getInstruction(); if (!(ins instanceof MONITORENTER)) return null; // Ensure the object being locked matches any previous // instructions which bound our variable name to a value. Variable lock = new LocalVariable(before.getTopValue()); return addOrCheckDefinition(lock, bindingSet); }
/** * Get a Variable representing the stack value which will either be stored * into or loaded from a field. * * @param fieldIns the FieldInstruction accessing the field * @param cpg the ConstantPoolGen for the method * @param frame the ValueNumberFrame containing the value to be stored * or the value loaded */ protected static Variable snarfFieldValue(FieldInstruction fieldIns, ConstantPoolGen cpg, ValueNumberFrame frame) throws DataflowAnalysisException { if (isLongOrDouble(fieldIns, cpg)) { int numSlots = frame.getNumSlots(); ValueNumber topValue = frame.getValue(numSlots - 1); ValueNumber nextValue = frame.getValue(numSlots - 2); return new LongOrDoubleLocalVariable(topValue, nextValue); } else { return new LocalVariable(frame.getTopValue()); } }
public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException { for (int i = 0; i < childList.length; ++i) { PatternElement child = childList[i]; MatchResult matchResult = child.match(handle, cpg, before, after, bindingSet); if (matchResult != null) return matchResult; } return null; }
/** * @param aInstruction * @param aPoolGen */ public PUTSTATICReference( PUTSTATIC aInstruction, ConstantPoolGen aPoolGen) { super(aInstruction, aPoolGen); }