protected void readNonRefField(OpenCLField field) { SootField soot_field = field.getSootField(); String function_name = "read" + getTypeString(soot_field); BytecodeLanguage bcl = m_bcl.top(); bcl.pushMethod(m_currMem.top(), function_name, soot_field.getType()); Local data = bcl.invokeMethodRet(m_currMem.top()); SootClass soot_class = Scene.v().getSootClass(soot_field.getDeclaringClass().getName()); if (soot_class.isApplicationClass()) { if (field.isInstance()) { bcl.setInstanceField(soot_field, m_objSerializing.top(), data); } else { bcl.setStaticField(soot_field, data); } } else { SootClass obj = Scene.v().getSootClass("java.lang.Object"); SootClass string = Scene.v().getSootClass("java.lang.String"); String static_str; SootClass first_param_type; Value first_param; if (field.isInstance()) { static_str = ""; first_param_type = obj; first_param = m_objSerializing.top(); } else { static_str = "Static"; first_param_type = Scene.v().getSootClass("java.lang.Class"); first_param = ClassConstant.v(soot_class.getName()); } String private_field_fun_name = "write" + static_str + getTypeString(soot_field); Local private_fields = bcl.newInstance("org.trifort.rootbeer.runtime.PrivateFields"); bcl.pushMethod( private_fields, private_field_fun_name, VoidType.v(), first_param_type.getType(), string.getType(), string.getType(), soot_field.getType()); bcl.invokeMethodNoRet( private_fields, first_param, StringConstant.v(soot_field.getName()), StringConstant.v(soot_field.getDeclaringClass().getName()), data); } }
protected String getTypeString(SootField soot_field) { Type type = soot_field.getType(); String name = type.toString(); char[] name_array = name.toCharArray(); name_array[0] = Character.toUpperCase(name_array[0]); return new String(name_array); }
public void fixFields() { Iterator<SootField> iter = m_fieldsToFix.keySet().iterator(); while (iter.hasNext()) { SootField curr = iter.next(); SootClass soot_class = curr.getDeclaringClass(); SootField orig = curr; SootClass field_cls = curr.getDeclaringClass(); if (shouldMap(field_cls)) { SootClass new_field_cls = getMapping(field_cls); curr = new_field_cls.getFieldByName(curr.getName()); } Type type = curr.getType(); if (type instanceof RefType) { RefType ref_type = (RefType) type; if (shouldMap(ref_type.getSootClass())) { SootClass new_class = getMapping(ref_type.getSootClass()); curr.setType(new_class.getType()); } } else if (type instanceof ArrayType) { ArrayType array_type = (ArrayType) type; if (array_type.baseType instanceof RefType == false) { continue; } RefType ref_type = (RefType) array_type.baseType; if (shouldMap(ref_type.getSootClass())) { SootClass new_class = getMapping(ref_type.getSootClass()); ArrayType new_type = ArrayType.v(new_class.getType(), array_type.numDimensions); curr.setType(new_type); } } List<FieldRef> refs = m_fieldsToFix.get(orig); for (FieldRef ref : refs) { ref.setFieldRef(curr.makeRef()); } } }
protected void readRefField(OpenCLField ref_field) { SootField soot_field = ref_field.getSootField(); SootClass soot_class = Scene.v().getSootClass(soot_field.getDeclaringClass().getName()); BytecodeLanguage bcl = m_bcl.top(); Local gc_obj_visit = m_gcObjVisitor.top(); BclMemory bcl_mem = new BclMemory(bcl, m_currMem.top()); Local ref = bcl_mem.readRef(); bcl_mem.useInstancePointer(); bcl_mem.pushAddress(); bcl_mem.setAddress(ref); // bcl.println("reading field: "+ref_field.getName()); SootClass obj_class = Scene.v().getSootClass("java.lang.Object"); SootClass string = Scene.v().getSootClass("java.lang.String"); SootClass class_class = Scene.v().getSootClass("java.lang.Class"); Local original_field_value; if (soot_class.isApplicationClass() == false) { if (ref_field.isInstance()) { bcl.pushMethod( gc_obj_visit, "readField", obj_class.getType(), obj_class.getType(), string.getType()); original_field_value = bcl.invokeMethodRet( gc_obj_visit, m_objSerializing.top(), StringConstant.v(soot_field.getName())); } else { bcl.pushMethod( gc_obj_visit, "readStaticField", obj_class.getType(), class_class.getType(), string.getType()); Local cls = bcl.classConstant(soot_field.getDeclaringClass().getType()); original_field_value = bcl.invokeMethodRet(gc_obj_visit, cls, StringConstant.v(soot_field.getName())); } } else { if (ref_field.isInstance()) { original_field_value = bcl.refInstanceField(m_objSerializing.top(), ref_field.getName()); } else { original_field_value = bcl.refStaticField(soot_class.getType(), ref_field.getName()); } } bcl.pushMethod( gc_obj_visit, "readFromHeap", obj_class.getType(), obj_class.getType(), BooleanType.v(), LongType.v()); int should_read = 1; Local ret_obj = bcl.invokeMethodRet(gc_obj_visit, original_field_value, IntConstant.v(should_read), ref); Type type = soot_field.getType(); Local ret = bcl.cast(type, ret_obj); if (soot_class.isApplicationClass() == false) { if (ref_field.isInstance()) { bcl.pushMethod( gc_obj_visit, "writeField", VoidType.v(), obj_class.getType(), string.getType(), obj_class.getType()); bcl.invokeMethodNoRet( gc_obj_visit, m_objSerializing.top(), StringConstant.v(soot_field.getName()), ret); } else { bcl.pushMethod( gc_obj_visit, "writeStaticField", VoidType.v(), class_class.getType(), string.getType(), obj_class.getType()); Local cls = bcl.classConstant(soot_field.getDeclaringClass().getType()); bcl.invokeMethodNoRet(gc_obj_visit, cls, StringConstant.v(soot_field.getName()), ret); } } else { if (ref_field.isInstance()) { bcl.setInstanceField(soot_field, m_objSerializing.top(), ret); } else { bcl.setStaticField(soot_field, ret); } } bcl_mem.popAddress(); }
/** Returns the set of objects pointed to by static field f. */ public PointsToSet reachingObjects(SootField f) { Type t = f.getType(); if (t instanceof RefType) return FullObjectSet.v((RefType) t); return FullObjectSet.v(); }
private Value mutate(Value value) { if (value instanceof FieldRef) { FieldRef ref = (FieldRef) value; SootField field = ref.getField(); Type type = field.getType(); if (type instanceof RefType) { RefType ref_type = (RefType) type; SootClass soot_class = ref_type.getSootClass(); if (shouldMap(soot_class)) { addField(field, ref); } } else if (type instanceof ArrayType) { ArrayType array_type = (ArrayType) type; Type base_type = array_type.baseType; if (base_type instanceof RefType) { RefType ref_type = (RefType) base_type; SootClass soot_class = ref_type.getSootClass(); if (shouldMap(soot_class)) { addField(field, ref); } } } SootClass soot_class = field.getDeclaringClass(); if (shouldMap(soot_class)) { addField(field, ref); } return value; } else if (value instanceof InvokeExpr) { InvokeExpr expr = (InvokeExpr) value; SootMethodRef ref = expr.getMethodRef(); SootClass soot_class = ref.declaringClass(); final NumberedString subSignature = ref.getSubSignature(); if (shouldMap(soot_class)) { SootClass new_class = getMapping(soot_class); if (new_class.declaresMethod(subSignature)) { SootMethod new_method = RootbeerScene.v().getMethod(new_class, subSignature.getString()); addAddedMethod(new_method); fixArguments(new_method); RootbeerScene.v().getDfsInfo().addReachableMethodSig(new_method.getSignature()); expr.setMethodRef(new_method.makeRef()); } } else { if (soot_class.declaresMethod(ref.getSubSignature())) { SootMethod method = soot_class.getMethod(ref.getSubSignature()); fixArguments(method); } } ref = remapRef(ref); try { if (shouldMap(soot_class)) { soot_class = getMapping(soot_class); } SootMethod method = soot_class.getMethod(ref.getSubSignature()); RootbeerScene.v().getDfsInfo().addReachableMethodSig(method.getSignature()); expr.setMethodRef(method.makeRef()); } catch (Exception ex) { // ex.printStackTrace(); } return value; } else if (value instanceof NewExpr) { NewExpr expr = (NewExpr) value; RefType base_type = expr.getBaseType(); SootClass soot_class = base_type.getSootClass(); if (shouldMap(soot_class)) { SootClass new_class = getMapping(soot_class); expr.setBaseType(new_class.getType()); } return value; } else if (value instanceof NewArrayExpr) { NewArrayExpr expr = (NewArrayExpr) value; Type base_type = expr.getBaseType(); base_type = fixType(base_type); expr.setBaseType(base_type); return value; } else if (value instanceof NewMultiArrayExpr) { NewMultiArrayExpr expr = (NewMultiArrayExpr) value; ArrayType array_type = expr.getBaseType(); Type base_type = array_type.baseType; if (base_type instanceof RefType) { RefType ref_type = (RefType) base_type; SootClass soot_class = ref_type.getSootClass(); if (shouldMap(soot_class)) { SootClass new_class = getMapping(soot_class); ArrayType new_type = ArrayType.v(new_class.getType(), array_type.numDimensions); expr.setBaseType(new_type); } } return value; } else if (value instanceof CastExpr) { CastExpr expr = (CastExpr) value; Type cast_type = expr.getCastType(); cast_type = fixType(cast_type); expr.setCastType(cast_type); return value; } else if (value instanceof ParameterRef) { ParameterRef ref = (ParameterRef) value; Type new_type = fixType(ref.getType()); return new ParameterRef(new_type, ref.getIndex()); } else if (value instanceof ThisRef) { ThisRef ref = (ThisRef) value; Type new_type = fixType(ref.getType()); return new ThisRef((RefType) new_type); } else if (value instanceof Local) { Local local = (Local) value; Type type = local.getType(); local.setType(fixType(type)); return value; } else { return value; } }
protected ReferenceVariable staticFieldImpl(String className, String fieldName) { SootClass c = RefType.v(className).getSootClass(); SootField f = c.getFieldByName(fieldName); return pag.makeGlobalVarNode(f, f.getType()); }