public RefType getOrAddRefType(RefType tp) { RefType existing = nameToClass.get(tp.getClassName()); if (existing != null) { return existing; } nameToClass.put(tp.getClassName(), tp); return tp; }
/** * Returns the RefType with the given className. */ public void addRefType(RefType type) { nameToClass.put(type.getClassName(), type); }
public void caseRefType(RefType t) { sb.append('L'); sb.append(slashify(t.getClassName())); sb.append(';'); }
public static boolean inLibrary(RefType type) { return inLibrary(type.getClassName()); }
public void caseRefType(RefType t) { setResult("L" + t.getClassName().replace('.', '/') + ";"); }
public void caseRefType(RefType t) { emitSpecial("RefType", "RefType.v(\"" + t.getClassName() + "\")"); }
public static String getDexTypeDescriptor(Type sootType) { if (sootType == null) { throw new NullPointerException("Soot type was null"); } final String typeDesc; if (sootType instanceof RefType) { typeDesc = getDexClassName(((RefType) sootType).getClassName()); } else if (sootType instanceof ArrayType) { typeDesc = getDexArrayTypeDescriptor((ArrayType) sootType); } else { typeDesc = sootToDexTypeDescriptor.get(sootType.getClass()); } if (typeDesc == null || typeDesc.isEmpty()) { throw new RuntimeException("Could not create type descriptor for class " + sootType); } return typeDesc; }
private void updateType(Type type) { if (type instanceof RefType) { RefType rt = (RefType) type; if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) { rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName()))); rt.setClassName(oldToNewClassNames.get(rt.getClassName())); } } else if (type instanceof ArrayType) { ArrayType at = (ArrayType) type; if (at.baseType instanceof RefType) { RefType rt = (RefType) at.baseType; if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) { rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName()))); } } } }
@Override public void caseNewInst(NewInst i) { mv.visitTypeInsn(Opcodes.NEW, slashify(i.getBaseType().getClassName())); }
public static FullObjectSet v(RefType t) { if (t.getClassName().equals("java.lang.Object")) { return v(); } return new FullObjectSet(t); }
@Override public void caseInstanceOfInst(InstanceOfInst i) { Type checkType = i.getCheckType(); if (checkType instanceof RefType) { mv.visitTypeInsn(Opcodes.INSTANCEOF, slashify(((RefType) checkType).getClassName())); } else if (checkType instanceof ArrayType) { mv.visitTypeInsn(Opcodes.INSTANCEOF, toTypeDesc(checkType)); } }
@Override public void caseInstanceCastInst(InstanceCastInst i) { Type castType = i.getCastType(); if (castType instanceof RefType) { mv.visitTypeInsn(Opcodes.CHECKCAST, slashify(((RefType) castType).getClassName())); } else if (castType instanceof ArrayType) { mv.visitTypeInsn(Opcodes.CHECKCAST, toTypeDesc(castType)); } }
@Override public void caseNewInst(NewInst i) { emit("new " + slashify(i.getBaseType().getClassName())); }
private static String sootTypeToString(Type tp) { if (tp instanceof RefType) { return "L" + ((RefType) tp).getClassName().replaceAll("\\.", "/") + ";"; } else if (tp instanceof ArrayType) { ArrayType at = (ArrayType) tp; return "[" + sootTypeToString(at.getElementType()); } else if (tp instanceof PrimType) { if (tp instanceof IntType) { return "I"; } else if (tp instanceof ByteType) { return "B"; } else if (tp instanceof CharType) { return "C"; } else if (tp instanceof DoubleType) { return "D"; } else if (tp instanceof FloatType) { return "F"; } else if (tp instanceof LongType) { return "L"; } else if (tp instanceof ShortType) { return "S"; } else if (tp instanceof BooleanType) { return "Z"; } else { throw new RuntimeException("Unsupported primitive type"); } } else { throw new RuntimeException("Unsupported type" + tp); } }
@Override public void caseInstanceCastInst(InstanceCastInst i) { Type castType = i.getCastType(); if (castType instanceof RefType) { emit("checkcast " + slashify(((RefType) castType).getClassName())); } else if (castType instanceof ArrayType) { emit("checkcast " + jasminDescriptorOf(castType)); } }
Type t = i.getBaseType(); if (t instanceof RefType) { mv.visitTypeInsn(Opcodes.ANEWARRAY, slashify(((RefType) t).getClassName())); } else if (t instanceof ArrayType) { mv.visitTypeInsn(Opcodes.ANEWARRAY, toTypeDesc(t));
public Wrapper() { PrimType[] tmp = { BooleanType.v(), ByteType.v(), CharType.v(), DoubleType.v(), FloatType.v(), IntType.v(), LongType.v(), ShortType.v() }; wrapperTypes = new HashMap<>(); valueOf = new HashMap<>(); primitiveValue = new HashMap<>(); for (PrimType primType : tmp) { RefType wrapperType = primType.boxedType(); String cn = wrapperType.getClassName(); wrapperTypes.put(wrapperType, primType); String valueOfMethodSignature = cn + " valueOf(" + primType.toString() + ")"; SootMethod valueOfMethod = wrapperType.getSootClass().getMethod(valueOfMethodSignature); valueOf.put(primType, valueOfMethod); String primitiveValueMethodSignature = primType.toString() + " " + primType.toString() + "Value()"; SootMethod primitiveValueMethod = wrapperType.getSootClass().getMethod(primitiveValueMethodSignature); primitiveValue.put(wrapperType, primitiveValueMethod); } wrapperTypes = Collections.unmodifiableMap(wrapperTypes); valueOf = Collections.unmodifiableMap(valueOf); primitiveValue = Collections.unmodifiableMap(primitiveValue); }
public void outInvokeExpr(InvokeExpr ie) { // If this is within a definitionStmt of a local if (inDefinitionStmt && (definedLocal != null)) { // if its a new object being created if (ie instanceof NewInvokeExpr) { // System.out.println("new object being created retrieve the name"); RefType ref = ((NewInvokeExpr) ie).getBaseType(); String className = ref.getClassName(); debug("outInvokeExpr", "defined local is" + definedLocal); info.setObjectClassName(definedLocal, className); } else { SootMethodRef methodRef = ie.getMethodRef(); String name = methodRef.name(); // System.out.println(name); info.setMethodName(definedLocal, name); } } }
@Override public void caseNewArrayInst(NewArrayInst i) { if (i.getBaseType() instanceof RefType) { emit("anewarray " + slashify(((RefType) i.getBaseType()).getClassName())); } else if (i.getBaseType() instanceof ArrayType) { emit("anewarray " + jasminDescriptorOf(i.getBaseType())); } else { emit("newarray " + i.getBaseType().toString()); } }
@Override protected String getCommonSuperClass(String type1, String type2) { String typeName1 = type1.replace('/', '.'); String typeName2 = type2.replace('/', '.'); SootClass s1 = Scene.v().getSootClass(typeName1); SootClass s2 = Scene.v().getSootClass(typeName2); // If these two classes haven't been loaded yet or are phantom, we take // java.lang.Object as the common superclass final Type mergedType; if (s1.isPhantom() || s2.isPhantom() || s1.resolvingLevel() == SootClass.DANGLING || s2.resolvingLevel() == SootClass.DANGLING) { mergedType = Scene.v().getObjectType(); } else { Type t1 = s1.getType(); Type t2 = s2.getType(); mergedType = t1.merge(t2, Scene.v()); } if (mergedType instanceof RefType) { return slashify(((RefType) mergedType).getClassName()); } else { throw new RuntimeException("Could not find common super class"); } }