public void caseStaticFieldRef(StaticFieldRef arg0) {
   SootField field = arg0.getField();
   OpenCLField ocl_field = new OpenCLField(arg0.getField(), field.getDeclaringClass());
   if (isLhs()) {
     m_output.append(ocl_field.getStaticSetterInvoke());
   } else {
     m_output.append(ocl_field.getStaticGetterInvoke());
   }
 }
示例#2
0
 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);
 }
示例#3
0
  private void loadTypes() {
    Set<String> methods = RootbeerClassLoader.v().getDfsInfo().getMethods();
    MethodSignatureUtil util = new MethodSignatureUtil();
    for (final String method_sig : methods) {
      util.parse(method_sig);
      SootMethod method = util.getSootMethod();
      addMethod(method);
    }
    CompilerSetup compiler_setup = new CompilerSetup();
    for (final String extra_method : compiler_setup.getExtraMethods()) {
      util.parse(extra_method);
      addMethod(util.getSootMethod());
    }

    Set<SootField> fields = RootbeerClassLoader.v().getDfsInfo().getFields();
    for (final SootField field : fields) {
      final SootClass soot_class = field.getDeclaringClass();
      getOpenCLClass(soot_class).addField(new OpenCLField(field, soot_class));
    }

    FieldSignatureUtil field_util = new FieldSignatureUtil();
    ForcedFields forced_fields = new ForcedFields();
    for (final String field_sig : forced_fields.get()) {
      field_util.parse(field_sig);
      final SootField field = field_util.getSootField();
      final SootClass soot_class = field.getDeclaringClass();
      getOpenCLClass(soot_class).addField(new OpenCLField(field, soot_class));
    }

    Set<ArrayType> array_types = RootbeerClassLoader.v().getDfsInfo().getArrayTypes();
    for (final ArrayType array_type : array_types) {
      final OpenCLArrayType ocl_array_type = new OpenCLArrayType(array_type);
      if (!m_arrayTypes.contains(ocl_array_type)) m_arrayTypes.add(ocl_array_type);
    }
    for (final ArrayType array_type : compiler_setup.getExtraArrayTypes()) {
      final OpenCLArrayType ocl_array_type = new OpenCLArrayType(array_type);
      if (!m_arrayTypes.contains(ocl_array_type)) m_arrayTypes.add(ocl_array_type);
    }

    Set<Type> instanceofs = RootbeerClassLoader.v().getDfsInfo().getInstanceOfs();
    for (final Type type : instanceofs) {
      final OpenCLInstanceof to_add = new OpenCLInstanceof(type);
      if (!m_instanceOfs.contains(to_add)) m_instanceOfs.add(to_add);
    }

    m_compositeFields = CompositeFieldFactory.getCompositeFields(this, m_classes);
  }
示例#4
0
  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);
    }
  }
 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());
     }
   }
 }
示例#6
0
  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();
  }
示例#7
0
  public void printTo(SootClass cl, PrintWriter out) {
    // add jimple line number tags
    setJimpleLnNum(1);

    // Print class name + modifiers
    {
      StringTokenizer st = new StringTokenizer(Modifier.toString(cl.getModifiers()));
      while (st.hasMoreTokens()) {
        String tok = (String) st.nextToken();
        if (cl.isInterface() && tok.equals("abstract")) continue;
        out.print(tok + " ");
      }

      String classPrefix = "";

      if (!cl.isInterface()) {
        classPrefix = classPrefix + " class";
        classPrefix = classPrefix.trim();
      }

      out.print(classPrefix + " " + Scene.v().quotedNameOf(cl.getName()) + "");
    }

    // Print extension
    {
      if (cl.hasSuperclass())
        out.print(" extends " + Scene.v().quotedNameOf(cl.getSuperclass().getName()) + "");
    }

    // Print interfaces
    {
      Iterator interfaceIt = cl.getInterfaces().iterator();

      if (interfaceIt.hasNext()) {
        out.print(" implements ");

        out.print("" + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + "");

        while (interfaceIt.hasNext()) {
          out.print(",");
          out.print(" " + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + "");
        }
      }
    }

    out.println();
    incJimpleLnNum();
    /*        if (!addJimpleLn()) {
        Iterator clTagsIt = cl.getTags().iterator();
        while (clTagsIt.hasNext()) {
            final Tag t = (Tag)clTagsIt.next();
            out.println(t);
        }
    }*/
    out.println("{");
    incJimpleLnNum();
    if (Options.v().print_tags_in_output()) {
      Iterator cTagIterator = cl.getTags().iterator();
      while (cTagIterator.hasNext()) {
        Tag t = (Tag) cTagIterator.next();
        out.print("/*");
        out.print(t.toString());
        out.println("*/");
      }
    }

    // Print fields
    {
      Iterator fieldIt = cl.getFields().iterator();

      if (fieldIt.hasNext()) {
        while (fieldIt.hasNext()) {
          SootField f = (SootField) fieldIt.next();

          if (f.isPhantom()) continue;

          if (Options.v().print_tags_in_output()) {
            Iterator fTagIterator = f.getTags().iterator();
            while (fTagIterator.hasNext()) {
              Tag t = (Tag) fTagIterator.next();
              out.print("/*");
              out.print(t.toString());
              out.println("*/");
            }
          }
          out.println("    " + f.getDeclaration() + ";");
          if (addJimpleLn()) {
            setJimpleLnNum(addJimpleLnTags(getJimpleLnNum(), f));
          }

          // incJimpleLnNum();
        }
      }
    }

    // Print methods
    {
      Iterator methodIt = cl.methodIterator();

      if (methodIt.hasNext()) {
        if (cl.getMethodCount() != 0) {
          out.println();
          incJimpleLnNum();
        }

        while (methodIt.hasNext()) {
          SootMethod method = (SootMethod) methodIt.next();

          if (method.isPhantom()) continue;

          if (!Modifier.isAbstract(method.getModifiers())
              && !Modifier.isNative(method.getModifiers())) {
            if (!method.hasActiveBody())
              throw new RuntimeException("method " + method.getName() + " has no active body!");
            else if (Options.v().print_tags_in_output()) {
              Iterator mTagIterator = method.getTags().iterator();
              while (mTagIterator.hasNext()) {
                Tag t = (Tag) mTagIterator.next();
                out.print("/*");
                out.print(t.toString());
                out.println("*/");
              }
            }
            printTo(method.getActiveBody(), out);

            if (methodIt.hasNext()) {
              out.println();
              incJimpleLnNum();
            }
          } else {

            if (Options.v().print_tags_in_output()) {
              Iterator mTagIterator = method.getTags().iterator();
              while (mTagIterator.hasNext()) {
                Tag t = (Tag) mTagIterator.next();
                out.print("/*");
                out.print(t.toString());
                out.println("*/");
              }
            }

            out.print("    ");
            out.print(method.getDeclaration());
            out.println(";");
            incJimpleLnNum();
            if (methodIt.hasNext()) {
              out.println();
              incJimpleLnNum();
            }
          }
        }
      }
    }
    out.println("}");
    incJimpleLnNum();
  }
示例#8
0
 private int addJimpleLnTags(int lnNum, SootField f) {
   f.addTag(new JimpleLineNumberTag(lnNum));
   lnNum++;
   return lnNum;
 }
示例#9
0
 /** 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;
   }
 }
示例#11
0
 protected ReferenceVariable staticFieldImpl(String className, String fieldName) {
   SootClass c = RefType.v(className).getSootClass();
   SootField f = c.getFieldByName(fieldName);
   return pag.makeGlobalVarNode(f, f.getType());
 }