private static Map<Integer, Value> getParameterTypes(MethodDescriptor descriptor) { Type[] argumentTypes = Type.getArgumentTypes(descriptor.getSignature()); int j = 0; Map<Integer, Value> result = new HashMap<>(); if(!descriptor.isStatic()) { result.put(j++, new Value("this", null, "L"+descriptor.getSlashedClassName()+";")); } for (int i = 0; i < argumentTypes.length; i++) { result.put(j, new Value("arg"+i, null, argumentTypes[i].getSignature())); j += argumentTypes[i].getSize(); } return result; }
static List<Item> getInitialLocals(MethodDescriptor descriptor) { List<Item> locals = new ArrayList<>(); Type[] argTypes = Type.getArgumentTypes(descriptor.getSignature()); int reg = 0; if (!descriptor.isStatic()) { Item it = Item.typeOnly("L" + descriptor.getSlashedClassName() + ";"); locals.add(it); reg += it.getSize(); } for (Type argType : argTypes) { Item it = Item.typeOnly(argType.getSignature()); locals.add(it); reg += it.getSize(); if (it.usesTwoSlots()) { locals.add(null); } } return locals; }
private Method findSuperclassMethod(@DottedClassName String superclassName, Method subclassMethod) throws ClassNotFoundException { String methodName = subclassMethod.getName(); Type[] subArgs = null; JavaClass superClass = Repository.lookupClass(superclassName); Method[] methods = superClass.getMethods(); outer: for (Method m : methods) { if (m.getName().equals(methodName)) { if (subArgs == null) { subArgs = Type.getArgumentTypes(subclassMethod.getSignature()); } Type[] superArgs = Type.getArgumentTypes(m.getSignature()); if (subArgs.length == superArgs.length) { for (int j = 0; j < subArgs.length; j++) { if (!superArgs[j].equals(subArgs[j])) { continue outer; } } return m; } } } if (!"Object".equals(superclassName)) { @DottedClassName String superSuperClassName = superClass.getSuperclassName(); if (superSuperClassName.equals(superclassName)) { throw new ClassNotFoundException("superclass of " + superclassName + " is itself"); } return findSuperclassMethod(superSuperClassName, subclassMethod); } return null; }
/** * Get array of Obligation types corresponding to the parameters of the * given method. * * @param xmethod * a method * @return array of Obligation types for each of the method's parameters; a * null element means the corresponding parameter is not an * Obligation type */ public Obligation[] getParameterObligationTypes(XMethod xmethod) { Type[] paramTypes = Type.getArgumentTypes(xmethod.getSignature()); Obligation[] result = new Obligation[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (!(paramTypes[i] instanceof ObjectType)) { continue; } try { result[i] = getObligationByType((ObjectType) paramTypes[i]); } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); } } return result; }
System.out.println(" --- " + className + " " + m.getName() + " " + signature); Type[] argTypes = Type.getArgumentTypes(signature); int reg = 0; if (!m.isStatic()) {
Type[] argTypes = Type.getArgumentTypes(methodSig); if ((argTypes.length < 1) || (argTypes.length > 2)) { return;
case SEEN_NOTHING: if (seen == Const.ALOAD_0) { argTypes = Type.getArgumentTypes(this.getMethodSig()); curParm = 0; curParmOffset = 1;
Type[] parameterTypeList = Type.getArgumentTypes(methodGen.getSignature()); Location firstLocation = new Location(cfg.getEntry().getFirstInstruction(), cfg.getEntry());
/** @return argument types of referenced method. */ public Type[] getArgumentTypes(ConstantPoolGen cpg) { return Type.getArgumentTypes(getSignature(cpg)); } }
/** @return argument types of referenced method. */ public Type[] getArgumentTypes( final ConstantPoolGen cpg ) { return Type.getArgumentTypes(getSignature(cpg)); }
/** * @return array of method argument types */ public Type[] getArgumentTypes() { return Type.getArgumentTypes(getSignature()); } }
/** * @return array of method argument types */ public Type[] getArgumentTypes() { return Type.getArgumentTypes(getSignature()); }
public static MethodBinding lookup(String className, String name, String signature) { String key= className + "#" + name + signature; MethodBinding binding= methodBindingsByKey.get(key); if (binding != null) return binding; binding= new MethodBinding(); binding.declaringClass= new ObjectType(className); binding.name= name; binding.parameterTypes= Type.getArgumentTypes(signature); binding.returnType= Type.getReturnType(signature); binding.signature= signature; methodBindingsByKey.put(key, binding); return binding; }
/** * Also works for instructions whose stack effect depends on the * constant pool entry they reference. * @return Number of words consumed from stack by this instruction */ public int consumeStack(ConstantPoolGen cpg) { String signature = getSignature(cpg); Type[] args = Type.getArgumentTypes(signature); int sum; if(opcode == Constants.INVOKESTATIC) sum = 0; else sum = 1; // this reference int n = args.length; for (int i = 0; i < n; i++) sum += args[i].getSize(); return sum; }
private static Map<Integer, Value> getParameterTypes(MethodDescriptor descriptor) { Type[] argumentTypes = Type.getArgumentTypes(descriptor.getSignature()); int j = 0; Map<Integer, Value> result = new HashMap<>(); if(!descriptor.isStatic()) { result.put(j++, new Value("this", null, "L"+descriptor.getSlashedClassName()+";")); } for (int i = 0; i < argumentTypes.length; i++) { result.put(j, new Value("arg"+i, null, argumentTypes[i].getSignature())); j += argumentTypes[i].getSize(); } return result; }
static List<Item> getInitialLocals(MethodDescriptor descriptor) { List<Item> locals = new ArrayList<Item>(); Type[] argTypes = Type.getArgumentTypes(descriptor.getSignature()); int reg = 0; if (!descriptor.isStatic()) { Item it = Item.typeOnly("L" + descriptor.getSlashedClassName() + ";"); locals.add(it); reg += it.getSize(); } for (Type argType : argTypes) { Item it = Item.typeOnly(argType.getSignature()); locals.add(it); reg += it.getSize(); if (it.usesTwoSlots()) { locals.add(null); } } return locals; }
static InstructionHandle emitInvoke(InstructionList il, InstructionFactory fac, MethodRef method) { String signature = method.getSignature(); Type[] args = Type.getArgumentTypes(signature); Type ret = Type.getReturnType(signature); String mname = method.getName(); String cname = method.getDeclaringClass().getName(); short kind; if (method.getDeclaringClass().isInterface()) { kind = Constants.INVOKEINTERFACE; } else if (java.lang.reflect.Modifier.isStatic(method.getModifiers())) { kind = Constants.INVOKESTATIC; } else if (method.getName().charAt(0) == '<') { kind = Constants.INVOKESPECIAL; } else { kind = Constants.INVOKEVIRTUAL; } return il.append(fac.createInvoke(cname, mname, ret, args, kind)); }
/** * Get array of Obligation types corresponding to the parameters of the * given method. * * @param xmethod * a method * @return array of Obligation types for each of the method's parameters; a * null element means the corresponding parameter is not an * Obligation type */ public Obligation[] getParameterObligationTypes(XMethod xmethod) { Type[] paramTypes = Type.getArgumentTypes(xmethod.getSignature()); Obligation[] result = new Obligation[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (!(paramTypes[i] instanceof ObjectType)) { continue; } try { result[i] = getObligationByType((ObjectType) paramTypes[i]); } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); } } return result; }
/** * Looks for the method referenced by the given invoke instruction in the given class. * @param jc the class that defines the referenced method * @param invoke the instruction that references the method * @return the referenced method or null if not found. */ private Method getMethod(final JavaClass jc, final InvokeInstruction invoke) { final Method[] ms = jc.getMethods(); for (final Method element : ms) { if ( (element.getName().equals(invoke.getMethodName(cpg))) && (Type.getReturnType(element.getSignature()).equals(invoke.getReturnType(cpg))) && (objarrayequals(Type.getArgumentTypes(element.getSignature()), invoke.getArgumentTypes(cpg))) ) { return element; } } 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."); } }