コード例 #1
0
ファイル: Scene.java プロジェクト: droidsec-cn/EC700-Epoch-2
  public void setMainClassFromOptions() {
    if (mainClass != null) return;
    if (Options.v().main_class() != null && Options.v().main_class().length() > 0) {
      setMainClass(getSootClass(Options.v().main_class()));
    } else {
      // try to infer a main class from the command line if none is given
      for (Iterator<String> classIter = Options.v().classes().iterator(); classIter.hasNext(); ) {
        SootClass c = getSootClass(classIter.next());
        if (c.declaresMethod(
            "main",
            Collections.<Type>singletonList(ArrayType.v(RefType.v("java.lang.String"), 1)),
            VoidType.v())) {
          G.v().out.println("No main class given. Inferred '" + c.getName() + "' as main class.");
          setMainClass(c);
          return;
        }
      }

      // try to infer a main class from the usual classpath if none is given
      for (Iterator<SootClass> classIter = getApplicationClasses().iterator();
          classIter.hasNext(); ) {
        SootClass c = (SootClass) classIter.next();
        if (c.declaresMethod(
            "main",
            Collections.<Type>singletonList(ArrayType.v(RefType.v("java.lang.String"), 1)),
            VoidType.v())) {
          G.v().out.println("No main class given. Inferred '" + c.getName() + "' as main class.");
          setMainClass(c);
          return;
        }
      }
    }
  }
コード例 #2
0
 public Boolean visit(VoidType n1, Node arg) {
   VoidType n2 = (VoidType) arg;
   if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
     return Boolean.FALSE;
   }
   return Boolean.TRUE;
 }
コード例 #3
0
ファイル: Scene.java プロジェクト: droidsec-cn/EC700-Epoch-2
 public SootMethod getMainMethod() {
   if (!hasMainClass()) {
     throw new RuntimeException("There is no main class set!");
   }
   if (!mainClass.declaresMethod(
       "main",
       Collections.<Type>singletonList(ArrayType.v(RefType.v("java.lang.String"), 1)),
       VoidType.v())) {
     throw new RuntimeException("Main class declares no main method!");
   }
   return mainClass.getMethod(
       "main",
       Collections.<Type>singletonList(ArrayType.v(RefType.v("java.lang.String"), 1)),
       VoidType.v());
 }
コード例 #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);
    }
  }
コード例 #5
0
ファイル: OpenCLScene.java プロジェクト: mxmlnkn/rootbeer1
  /**
   * Replaces place holders in the form of %%placeholder_name%% with valid values. E.g.
   * %%shared_mem_size%%. These are used in the CUDA templates provided by Rootbeer
   *
   * @see rootbeer/generate/opencl/CudaKernel.c
   *     <p>It also replaces %%java_lang_*_TypeNumber%% with their respective type numbers as
   *     returned by the Soot RoobteerClassLoader fork.
   * @see rootbeer/generate/opencl/GarbageCollector.c
   */
  private String setupEntryPoint(StringBuilder builder) {
    String cuda_code = builder.toString();
    String replacement =
        getRuntimeBasicBlockClassName() + "_gpuMethod" + NameMangling.v().mangle(VoidType.v());
    // class names can have $ in them, make them regex safe
    replacement = replacement.replace("$", "\\$");
    cuda_code = cuda_code.replaceAll("%%invoke_run%%", replacement);

    assert (m_configuration != null);
    int size = m_configuration.getSharedMemSize();
    String size_str = "" + size;
    cuda_code = cuda_code.replaceAll("%%shared_mem_size%%", size_str);

    cuda_code = cuda_code.replaceAll("%%MallocAlignZeroBits%%", "" + Constants.MallocAlignZeroBits);
    cuda_code = cuda_code.replaceAll("%%MallocAlignBytes%%", "" + Constants.MallocAlignBytes);

    boolean exceptions = m_configuration.getExceptions();
    String exceptions_str;
    if (exceptions) exceptions_str = "" + 1;
    else exceptions_str = "" + 0;
    cuda_code = cuda_code.replaceAll("%%using_exceptions%%", exceptions_str);

    for (String typeString :
        Arrays.asList(
            "StringBuilder",
            "NullPointerException",
            "OutOfMemoryError",
            "String",
            "Integer",
            "Long",
            "Float",
            "Double",
            "Boolean")) {
      cuda_code =
          cuda_code.replaceAll(
              "%%java_lang_" + typeString + "_TypeNumber%%",
              "" + RootbeerClassLoader.v().getClassNumber("java.lang." + typeString));
    }
    return cuda_code;
  }
コード例 #6
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
 public void outAVoidType(AVoidType node) {
   mProductions.addLast(VoidType.v());
 }
コード例 #7
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();
  }
コード例 #8
0
 @Override
 public void visit(final VoidType n, final A arg) {
   visitComment(n.getComment(), arg);
   visitAnnotations(n, arg);
 }
コード例 #9
0
ファイル: Scene.java プロジェクト: droidsec-cn/EC700-Epoch-2
 /** Create an unresolved reference to a constructor. */
 public SootMethodRef makeConstructorRef(SootClass declaringClass, List<Type> parameterTypes) {
   return makeMethodRef(
       declaringClass, SootMethod.constructorName, parameterTypes, VoidType.v(), false);
 }