private boolean matchMethod(InvokeInstruction inv, ConstantPoolGen cpg, String className, String methodName) { return inv.getClassName(cpg).equals(className) && inv.getName(cpg).equals(methodName); }
public static boolean mightCloseStream(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg) { Instruction ins = handle.getInstruction(); if ((ins instanceof INVOKEVIRTUAL) || (ins instanceof INVOKEINTERFACE)) { // Does this instruction close the stream? InvokeInstruction inv = (InvokeInstruction) ins; // It's a close if the invoked class is any subtype of the stream // base class. // (Basically, we may not see the exact original stream class, // even though it's the same instance.) return "close".equals(inv.getName(cpg)) && "()V".equals(inv.getSignature(cpg)); } return false; }
private static Map<InstructionHandle, Call> buildCallMap(CFG cfg, ConstantPoolGen cpg) { Map<InstructionHandle, Call> callMap = new HashMap<>(); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { InstructionHandle handle = i.next().getHandle(); Instruction ins = handle.getInstruction(); if (ins instanceof InvokeInstruction) { InvokeInstruction inv = (InvokeInstruction) ins; Call call = new Call(inv.getClassName(cpg), inv.getName(cpg), inv.getSignature(cpg)); callMap.put(handle, call); } } return callMap; }
/** * Convenience method for generating a method signature in human readable * form. * * @param inv * an InvokeInstruction * @param cpg * the ConstantPoolGen for the class the instruction belongs to */ public static String convertMethodSignature(InvokeInstruction inv, ConstantPoolGen cpg) { return convertMethodSignature(inv.getClassName(cpg), inv.getName(cpg), inv.getSignature(cpg)); }
private void handleInstanceMethod(InvokeInstruction obj) { assert returnsString(obj); consumeStack(obj); String className = obj.getClassName(getCPG()); String methodName = obj.getName(getCPG()); // System.out.println(className + "." + methodName); if ("intern".equals(methodName) && "java.lang.String".equals(className)) { sawStringIntern = true; pushValue(staticStringTypeInstance); } else if ("toString".equals(methodName) || "java.lang.String".equals(className)) { pushValue(dynamicStringTypeInstance); // System.out.println(" dynamic"); } else { pushReturnType(obj); } }
String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); if (DEBUG_METHOD_LOOKUP) {
@Override public boolean mightCloseResource(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg) throws DataflowAnalysisException { InvokeInstruction inv = toInvokeInstruction(handle.getInstruction()); if (inv == null) { return false; } String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); try { if ("unlock".equals(methodName) && "()V".equals(methodSig) && Hierarchy.isSubtype(className, "java.util.concurrent.locks.Lock")) { return true; } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return false; }
} else { String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); if (DEBUG_METHOD_LOOKUP) {
/** * Create an XMethod object from an InvokeInstruction. * * @param invokeInstruction * the InvokeInstruction * @param cpg * ConstantPoolGen from the class containing the instruction * @return XMethod representing the method called by the InvokeInstruction */ public static XMethod createXMethod(InvokeInstruction invokeInstruction, ConstantPoolGen cpg) { String className = invokeInstruction.getClassName(cpg); String methodName = invokeInstruction.getName(cpg); String methodSig = invokeInstruction.getSignature(cpg); if (invokeInstruction instanceof INVOKEDYNAMIC) { // XXX the lambda representation makes no sense for XMethod // "classical" instruction attributes are filled with garbage, causing // the code later to produce crazy errors (looking for non existing types etc) // We should NOT be called here from our code, but 3rd party code still may // use this method. So *at least* provide a valid class name, which is // (don't ask me why) is encoded in the first argument type of the lambda // className = invokeInstruction.getArgumentTypes(cpg)[0].toString(); className = "java.lang.Object"; } return createXMethod(className, methodName, methodSig, invokeInstruction.getOpcode() == Const.INVOKESTATIC); }
/** * Look up the method referenced by given InvokeInstruction. This method * does <em>not</em> look for implementations in super or subclasses * according to the virtual dispatch rules. * * @param inv * the InvokeInstruction * @param cpg * the ConstantPoolGen used by the class the InvokeInstruction * belongs to * @param chooser * JavaClassAndMethodChooser to use to pick the method from among * the candidates * @return the JavaClassAndMethod, or null if no such method is defined in * the class */ public static JavaClassAndMethod findExactMethod(InvokeInstruction inv, ConstantPoolGen cpg, JavaClassAndMethodChooser chooser) throws ClassNotFoundException { String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); JavaClass jclass = Repository.lookupClass(className); return findMethod(jclass, methodName, methodSig, chooser); }
String methodName = invokeInstruction.getName(cpg); String methodSig = invokeInstruction.getSignature(cpg);
String methodName = inv.getName(cpg); if (("forName".equals(methodName) && "java.lang.Class".equals(inv.getClassName(cpg)) || "class$".equals(methodName)) && "(Ljava/lang/String;)Ljava/lang/Class;".equals(inv.getSignature(cpg))
String methodName = invokeInstruction.getName(cpg); String signature = invokeInstruction.getSignature(cpg);
/** * Look up the method referenced by given InvokeInstruction. This method * does <em>not</em> look for implementations in super or subclasses * according to the virtual dispatch rules. * * @param inv * the InvokeInstruction * @param cpg * the ConstantPoolGen used by the class the InvokeInstruction * belongs to * @param chooser * JavaClassAndMethodChooser to use to pick the method from among * the candidates * @return the JavaClassAndMethod, or null if no such method is defined in * the class */ public static XMethod findExactMethod(InvokeInstruction inv, ConstantPoolGen cpg, JavaClassAndMethodChooser chooser) { String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); XMethod result = findMethod(DescriptorFactory.createClassDescriptorFromDottedClassName(className), methodName, methodSig, inv instanceof INVOKESTATIC); return thisOrNothing(result, chooser); }
@Override public Lock isResourceCreation(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg) throws DataflowAnalysisException { InvokeInstruction inv = toInvokeInstruction(handle.getInstruction()); if (inv == null) { return null; } String className = inv.getClassName(cpg); String methodName = inv.getName(cpg); String methodSig = inv.getSignature(cpg); try { if ("lock".equals(methodName) && "()V".equals(methodSig) && Hierarchy.isSubtype(className, "java.util.concurrent.locks.Lock")) { Location location = new Location(handle, basicBlock); ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location); ValueNumber lockValue = frame.getTopValue(); if (DEBUG) { System.out.println("Lock value is " + lockValue.getNumber() + ", frame=" + frame.toString()); } if (DEBUG) { ++numAcquires; } return new Lock(location, className, lockValue); } } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); } return null; }
case INVOKEINTERFACE: InvokeInstruction iins = (InvokeInstruction) ins; String invoking = iins.getName(cpg); if ( comparatorMethod(invoking) || booleanComparisonMethod(invoking) ) { if (methodGen.getName().toLowerCase().indexOf("test") >= 0) {
String methodName = invokeInstruction.getName(cpg); String methodSig = invokeInstruction.getSignature(cpg);
if ("toArray".equals(obj.getName(getCPG()))) { ReferenceType target = obj.getReferenceType(getCPG()); String signature = obj.getSignature(getCPG());
/** @return name of referenced method. */ public String getMethodName( final ConstantPoolGen cpg ) { return getName(cpg); }
/** * Convenience method for generating a method signature in human readable * form. * * @param inv * an InvokeInstruction * @param cpg * the ConstantPoolGen for the class the instruction belongs to */ public static String convertMethodSignature(InvokeInstruction inv, ConstantPoolGen cpg) { return convertMethodSignature(inv.getClassName(cpg), inv.getName(cpg), inv.getSignature(cpg)); }