public void caseCastExpr(CastExpr arg0) {
   Type cast_type = arg0.getCastType();
   OpenCLType ocl_type = new OpenCLType(cast_type);
   m_output.append("(" + ocl_type.getCudaTypeString() + ") ");
   Value rhs = arg0.getOp();
   rhs.apply(this);
 }
Пример #2
0
 public boolean twoValueEquals(Value v1, Value v2) {
   if (v1.toString().equals(v2.toString())
       && v1.getType().toString().equals(v2.getType().toString())) {
     return true;
   }
   return false;
 }
Пример #3
0
 private static boolean checkIfIsArrayFunction(
     SootMethod method, InstanceInvokeExpr instanceInvokeExpr) {
   String methodName = method.getName();
   Value base = instanceInvokeExpr.getBase();
   System.out.println(base.getType());
   if (base.getType().toString().equals("android.content.Intent")) {
     if (methodName.startsWith("get") && methodName.contains("Array")) {
       return true;
     }
   }
   return false;
 }
Пример #4
0
  /**
   * @ast method
   * @aspect Expressions
   * @declaredat
   *     /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/Expressions.jrag:84
   */
  public soot.Value eval(Body b) {
    TypeDecl dest = getDest().type();
    TypeDecl source = getSource().type();
    if (dest.isString()) {

      Value lvalue = getDest().eval(b);

      Value v = asImmediate(b, lvalue);

      // new StringBuffer(left)
      Local local =
          b.newTemp(b.newNewExpr(lookupType("java.lang", "StringBuffer").sootRef(), this));
      b.setLine(this);
      b.add(
          b.newInvokeStmt(
              b.newSpecialInvokeExpr(
                  local,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: void <init>(java.lang.String)>")
                      .makeRef(),
                  v,
                  this),
              this));

      // append right
      Local rightResult =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  local,
                  lookupType("java.lang", "StringBuffer")
                      .methodWithArgs("append", new TypeDecl[] {source.stringPromotion()})
                      .sootRef(),
                  asImmediate(b, getSource().eval(b)),
                  this));

      // toString
      Local result =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  rightResult,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: java.lang.String toString()>")
                      .makeRef(),
                  this));

      Value v2 = lvalue instanceof Local ? lvalue : (Value) lvalue.clone();
      getDest().emitStore(b, v2, result, this);
      return result;
    } else {
      return super.eval(b);
    }
  }
Пример #5
0
  /** Count taint on prims or strings */
  private static Set<InfoValue> getTaintSet(Value v, MethodOrMethodContext momc) {
    Set<InfoValue> taints = null;

    if (v instanceof Local && v.getType() instanceof PrimType) {
      taints = InformationFlowAnalysis.v().getTaints(momc, (Local) v);
    } else if (PTABridge.v().isPointer(v) && SootUtils.isStringOrSimilarType(v.getType())) {
      taints = new HashSet<InfoValue>();
      for (IAllocNode node : PTABridge.v().getPTSet(v, momc.context())) {
        taints.addAll(InformationFlowAnalysis.v().getTaints(node, momc));
      }
    }

    return taints;
  }
Пример #6
0
  @Override
  public Set<? extends IAllocNode> getPTSet(Value val, Context context) {
    // handle case for insensitive run
    if (k == 0) return getPTSetIns(val);

    final Set<AllocNode> allocNodes = new LinkedHashSet<AllocNode>();
    final Type filteringType = val.getType();

    PointsToSetInternal pts = null;

    try {
      if (val instanceof InstanceFieldRef) {
        final InstanceFieldRef ifr = (InstanceFieldRef) val;
        pts =
            (PointsToSetInternal)
                ptsProvider.reachingObjects(context, (Local) ifr.getBase(), ifr.getField());
      } else if (val instanceof ArrayRef) {
        ArrayRef arrayRef = (ArrayRef) val;
        pts =
            (PointsToSetInternal)
                ptsProvider.reachingObjectsOfArrayElement(
                    ptsProvider.reachingObjects(context, (Local) arrayRef.getBase()));
      } else if (val instanceof Local) {
        pts = (PointsToSetInternal) ptsProvider.reachingObjects(context, (Local) val);
      } else if (val instanceof StaticFieldRef) {
        SootField field = ((StaticFieldRef) val).getField();
        pts = (PointsToSetInternal) ptsProvider.reachingObjects(field);
      } else if (val instanceof NullConstant) {
        return allocNodes;
      } else {
        logger.error("Unknown reference type for insenstive search: {} {}", val, val.getClass());
        droidsafe.main.Main.exit(1);
      }

      // visit internal points to set and grab all allocnodes
      pts.forall(
          new P2SetVisitor() {
            public void visit(Node n) {
              if (typeManager.castNeverFails(n.getType(), filteringType))
                allocNodes.add((AllocNode) n);
            }
          });

    } catch (Exception e) {
      logger.info("Some sort of error getting context insensitive points to set for {}", val, e);
      // e.printStackTrace();
    }

    return allocNodes;
  }
Пример #7
0
  public static boolean maybeSameLocation(Value v1, Value v2) {
    if (!(v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef)
        && !(v1 instanceof ArrayRef && v2 instanceof ArrayRef)) {
      return v1.equivTo(v2);
    }
    if (v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef) {
      InstanceFieldRef ifr1 = (InstanceFieldRef) v1;
      InstanceFieldRef ifr2 = (InstanceFieldRef) v2;
      if (!ifr1.getField().getName().equals(ifr2.getField().getName())) return false;

      Local base1 = (Local) ifr1.getBase();
      Local base2 = (Local) ifr2.getBase();
      PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
      PointsToSet pts1 = pta.reachingObjects(base1);
      PointsToSet pts2 = pta.reachingObjects(base2);
      return pts1.hasNonEmptyIntersection(pts2);
    } else { // v1 instanceof ArrayRef && v2 instanceof ArrayRef
      ArrayRef ar1 = (ArrayRef) v1;
      ArrayRef ar2 = (ArrayRef) v2;

      Local base1 = (Local) ar1.getBase();
      Local base2 = (Local) ar2.getBase();
      PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
      PointsToSet pts1 = pta.reachingObjects(base1);
      PointsToSet pts2 = pta.reachingObjects(base2);
      return pts1.hasNonEmptyIntersection(pts2);
    }
  }
Пример #8
0
  private int numMatchArgs(int numFormals, UnchangedParamsAnalysis mrpa, Stmt s) {
    FlowSet before = (FlowSet) mrpa.getFlowBefore(s);

    List args = ((InvokeExpr) s.getInvokeExpr()).getArgs();
    int matchArg = 0;
    for (int i = 0; i < numFormals; i++) {
      Value arg = (Value) args.get(i);
      for (Iterator rppIt = before.iterator(); rppIt.hasNext(); ) {
        IDValuePair rpp = (IDValuePair) rppIt.next();
        if (rpp.groupID == i && arg.equivTo(rpp.value)) {
          matchArg++;
          break;
        }
      }
    }
    return matchArg;
  }
Пример #9
0
  /**
   * Returns <code>true</code> if both references may point to the same memory location. The current
   * implementation is conservative, as it does not take any points-to information into account.
   */
  public static boolean maybeSameLocation(Value abstrRef, Value programRef) {
    // arrays are handled through their "base" pointer
    assert !(abstrRef instanceof ArrayRef);
    assert !(programRef instanceof ArrayRef);

    if (abstrRef == programRef) return true;

    // handle primtive types
    Type abstrRefType = abstrRef.getType();
    Type programRefType = programRef.getType();
    if (programRefType instanceof PrimType) {
      // we don't track primitive types, just Strings, ClassLoaders, etc.
      // ...
      return false;
    }
    if (abstrRefType instanceof PrimType) {
      // we don't track primitive types, just Strings, ClassLoaders, etc.
      // ...
      throw new InternalError("abstraction ref type is " + abstrRefType);
    }

    if (abstrRef instanceof Local && programRef instanceof Local) {
      // two locals only point to the same memory locations if they are
      // the same
      return abstrRef == programRef;
    } else if (abstrRef instanceof FieldRef && programRef instanceof FieldRef) {
      FieldRef fieldRef = (FieldRef) abstrRef;
      FieldRef fieldRef2 = (FieldRef) programRef;
      // references point to the same location if class and field name are
      // identical;
      // note that we ignore the receiver object of InstanceFieldRefs
      return fieldRef
              .getField()
              .getDeclaringClass()
              .equals(fieldRef2.getField().getDeclaringClass())
          && fieldRef.getFieldRef().name().equals(fieldRef2.getFieldRef().name());
    } else {
      return false;
    }
  }
  public static List<Value> getAllImmediateValue(Stmt stmt) {
    List<Value> rtVal = new ArrayList<Value>();

    List<ValueBox> vbs = stmt.getUseAndDefBoxes();
    Set<String> frs = new HashSet<String>();

    for (ValueBox vb : vbs) {
      Value v = vb.getValue();

      if (v instanceof FieldRef) {
        int endPos = v.toString().indexOf('.');
        String name = v.toString().substring(0, endPos);
        frs.add(name);

        Value existV = null;
        for (ValueBox vBox : vbs) {
          if (name.equals(vBox.getValue().toString())) {
            existV = vBox.getValue();
            break;
          }
        }

        if (null != existV) {
          rtVal.remove(existV);
        }

        rtVal.add(v);
      }

      if (v instanceof Immediate) {
        if (!frs.contains(v.toString())) {
          rtVal.add(v);
        }
      }
    }

    return rtVal;
  }
Пример #11
0
  /**
   * Hash code for Value representing a variable if it's a constant, local, field ref (for field
   * itself), or array elem ref (for all elements of array of that type).
   */
  public static int valueHashCode(Value v) {
    // case 1: null or constant
    if (v == null) return 0;
    if (v instanceof Constant) return v.hashCode();

    // case 2: local
    if (v instanceof Local) return v.hashCode();
    // case 3: field ref (base is ignored)
    if (v instanceof FieldRef) {
      SootFieldRef sfr = ((FieldRef) v).getFieldRef();
      return sfr.resolve().hashCode();
    }
    // case 4: array elems
    assert (v instanceof ArrayRef);
    ArrayRef ae1 = (ArrayRef) v;
    // *** FOR NOW, we avoid distinguishing array elems with constant indices as different
    // variables,
    //  because it leads to too much instrumentation at defs and uses of array elem with unknown
    // index.
    return ae1.getBase()
        .getType()
        .hashCode(); // + ((ae1.getIndex() instanceof Constant)? ae1.getIndex().hashCode() : 0);
  }
Пример #12
0
  /**
   * Because the parameter passing in Java is generally pass-by-value, the traditional meaning of
   * reference parameter can hardly be used to judge whether a parameter should be considered in
   * binding in Java.
   *
   * <p>Here we choose use the type of a parameter to determined whether it is mutable.
   * Specifically, we just exclude some common immutable types, such as primitives, their wrappers,
   * and java.lang.String.
   *
   * @param v
   * @return
   */
  private boolean isMutableRefParam(Value v) {
    Type type = v.getType();

    // this condition excludes the primitive types, but not their wrappers
    if (type instanceof RefType) {
      // TODO: test the cases of Java generics
      String typeName = ((RefType) type).getClassName();
      if (commonImmutableTypes.contains(typeName)) {
        return false;
      } else {
        // this is really a conservative design, as there may
        // be a lot of customized immutable types.
        return true;
      }
    } else {
      // if the type is a primitive type or
      // an other special type, e.g., NullType
      return false;
    }
  }
Пример #13
0
  /**
   * Returns all possible ref/array types of instances that Value can represent as variables.
   * Returns null if no instance obj can be represented by Value (e.g., static method call).
   */
  private static Set<RefLikeType> getAllPossibleRuntimeRefTypes(Value val) {
    Set<RefLikeType> typeTargets = new HashSet<RefLikeType>();
    // 1.a) NewExpr        (instance)
    if (val instanceof NewExpr) typeTargets.add((RefLikeType) ((NewExpr) val).getType());
    // 1.b) NewArrayExpr   (instance)
    else if (val instanceof NewArrayExpr)
      typeTargets.add((RefLikeType) ((NewArrayExpr) val).getType());
    // 2. InvokeExpr     (static or instance)
    else if (val instanceof InvokeExpr) {
      if (val instanceof StaticInvokeExpr) typeTargets = null; // special case
      else if (val instanceof SpecialInvokeExpr)
        typeTargets.add((RefType) ((SpecialInvokeExpr) val).getBase().getType());
      else {
        assert val instanceof InstanceInvokeExpr;
        SootClass declCls = ((InvokeExpr) val).getMethod().getDeclaringClass();
        typeTargets.add(declCls.getType());

        for (SootClass clsSub : getAllSubtypes(declCls)) typeTargets.add(clsSub.getType());
      }
    }
    // 3. Local/statfield ref var  (instance)
    else if (val instanceof Local || val instanceof StaticFieldRef) {
      RefLikeType lType = (RefLikeType) val.getType();
      typeTargets.add(lType);
      if (lType instanceof RefType) {
        // add all possible subtypes of ref type
        for (SootClass clsSub : getAllSubtypes(((RefType) lType).getSootClass()))
          typeTargets.add(clsSub.getType());
      } else assert lType instanceof ArrayType; // array type has no subtypes
    }
    // 4. StringConstant (instance)
    else {
      assert (val instanceof StringConstant);
      typeTargets.add(Scene.v().getRefType("java.lang.String"));
    }
    return typeTargets;
  }
Пример #14
0
  /**
   * A value represents a var if it's a constant, local, field ref (for field itself), or array elem
   * ref (any element in it). Objects are *not* considered here.
   */
  public static boolean valuesEqual(Value v1, Value v2) {
    // case 1: both null refs or constants
    if (v1 == null || v2 == null) return v1 == v2;
    if (v1 instanceof Constant) {
      if (v2 instanceof Constant) return v1.equals(v2);
      return false;
    }

    // case 2: locals
    if (v1 instanceof Local) return v1 == v2;
    // case 3: field refs (base is ignored)
    if (v1 instanceof FieldRef) {
      SootFieldRef sfr1 = ((FieldRef) v1).getFieldRef();
      if (!(v2 instanceof FieldRef)) return false;
      SootFieldRef sfr2 = ((FieldRef) v2).getFieldRef();
      return sfr1.declaringClass() == sfr2.declaringClass() && sfr1.name().equals(sfr2.name());
    }
    // case 4: array elems (index compared only if constant)
    //         they are the same if elem types are equal and index values are not definitely
    // different
    assert (v1 instanceof ArrayRef);

    ArrayRef ae1 = (ArrayRef) v1;
    if (!(v2 instanceof ArrayRef)) return false;
    ArrayRef ae2 = (ArrayRef) v2;
    if (!ae1.getBase().getType().equals(ae2.getBase().getType())) return false;
    // *** FOR NOW, we avoid distinguishing array elems with constant indices as different
    // variables,
    //  because it leads to too much instrumentation at defs and uses of array elem with unknown
    // index.
    //		Value vIdx1 = ae1.getIndex();
    //		Value vIdx2 = ae2.getIndex();
    //		if (vIdx1 instanceof Constant && vIdx2 instanceof Constant && !vIdx1.equals(vIdx2))
    //			return false;
    return true;
  }
 public void caseLengthExpr(LengthExpr arg0) {
   Value op = arg0.getOp();
   m_output.append("org_trifort_array_length(gc_info, ");
   op.apply(this);
   m_output.append(")");
 }
 public void caseNegExpr(NegExpr arg0) {
   Value op = arg0.getOp();
   m_output.append("-");
   op.apply(this);
 }
Пример #17
0
  /**
   * @param cfg
   * @param sink
   * @param assignmentStatement
   */
  private void instrumentSourceToSinkConnections(
      BiDiInterproceduralCFG<Unit, SootMethod> cfg,
      ResultSinkInfo sink,
      boolean assignmentStatement) {
    sourceSinkConnectionCounter += 1;

    // loop through the sinks
    for (ResultSinkInfo key : results.getResults().keySet()) {

      log.debug("compare: " + key);
      log.debug("     to: " + sink);

      // if the current sink is the sink at the unit tagged with 'sink'
      if (key.equals(sink)) {

        // loop through the sources
        for (ResultSourceInfo si : results.getResults().get(key)) {

          Stmt stmt = si.getSource();
          SootMethod sm = cfg.getMethodOf(stmt);
          Body body = sm.retrieveActiveBody();

          // Source instrumentation. The three type categories for the source are:
          // - callback
          // - ICC source method (i.e., Intent.getExtras())
          // - not a callback and not an ICC source method (i.e., getLine1Number())
          //
          if (isInterComponentSourceCallback(si, cfg)) {
            throw new RuntimeException("Callbacks as sources are not supported right now");
          } else if (isInterComponentSourceNoCallback(si, cfg)) {
            // only invoke expression are treated here
            if (stmt.containsInvokeExpr()) {
              // only statements that return a android.os.Bundle are currently supported
              if (stmt instanceof DefinitionStmt) {
                DefinitionStmt defStmt = (DefinitionStmt) stmt;
                Value leftValue = defStmt.getLeftOp();

                if (leftValue.getType().equals(RefType.v("android.os.Bundle"))) {
                  List<Object> args = new ArrayList<Object>();
                  args.add(IntType.v());
                  args.add(IntConstant.v(sourceSinkConnectionCounter));
                  args.add(RefType.v("android.os.Bundle"));
                  args.add(leftValue);
                  InvokeExpr invExpr =
                      Instrumentation.createJimpleStaticInvokeExpr(
                          Settings.INSTRUMENTATION_HELPER_JAVA,
                          "registerNewSourceSinkConnection",
                          args);
                  InvokeStmt invStmt = Jimple.v().newInvokeStmt(invExpr);

                  Unit instrumentationPoint = null;
                  if (stmt instanceof IdentityStmt) {
                    instrumentationPoint = getLastIdentityStmt(body);
                  } else {
                    instrumentationPoint = stmt;
                  }
                  body.getUnits().insertAfter(invStmt, instrumentationPoint);
                  log.debug("insert a: " + invStmt);
                } else {
                  System.err.println("We do only support android.os.Bundle right now!");
                }
              }
            }
          } else {

            String sourceCat = getSourceCategory(si);
            if (sourceCat != null) {
              List<Object> args = new ArrayList<Object>();
              args.add(IntType.v());
              args.add(IntConstant.v(sourceSinkConnectionCounter));
              args.add(RefType.v("java.lang.String"));
              args.add(StringConstant.v(sourceCat));
              InvokeExpr invExpr =
                  Instrumentation.createJimpleStaticInvokeExpr(
                      Settings.INSTRUMENTATION_HELPER_JAVA,
                      "registerNewSourceSinkConnection",
                      args);
              InvokeStmt invStmt = Jimple.v().newInvokeStmt(invExpr);

              Unit instrumentationPoint = null;
              if (stmt instanceof IdentityStmt) instrumentationPoint = getLastIdentityStmt(body);
              else instrumentationPoint = stmt;
              body.getUnits().insertAfter(invStmt, instrumentationPoint);
              log.debug("insert b: " + invStmt);
            }
          }

          // sink instrumentation
          if (sink.getSink().containsInvokeExpr()) {
            Body bodyOfSink = cfg.getMethodOf(key.getSink()).getActiveBody();
            InvokeExpr invExpr = sink.getSink().getInvokeExpr();
            List<Unit> generated = new ArrayList<Unit>();
            generated.addAll(
                instrumentIntentAddings(cfg, stmt, invExpr, results.getResults().get(key)));

            EventInformation sinkEventInfo =
                allEventInformation.get(invExpr.getMethod().getSignature());
            EventInformation sourceEventInfo =
                allEventInformation.get(si.getSource().getInvokeExpr().getMethod().getSignature());

            generated.addAll(
                generatePolicyEnforcementPoint(
                    key.getSink(),
                    invExpr,
                    bodyOfSink,
                    sourceSinkConnectionCounter,
                    assignmentStatement));

            log.debug("body with data flow:\n" + body);
            for (Unit u : generated) {
              log.debug("gen: " + u);
            }

            if (sinkEventInfo.isInstrumentAfterStatement())
              bodyOfSink.getUnits().insertAfter(generated, key.getSink());
            else bodyOfSink.getUnits().insertBefore(generated, key.getSink());
          } else throw new RuntimeException("Double-Check the assumption");
        } // loop through the sources
      } // if the sink at the unit is the current sink
    } // loop through the sinks
  }
Пример #18
0
  /*
   * Generates the sequence of instructions needed to instrument ifStmtUnit
   *
   * @param ifStmtUnit: the unit to be instrumented
   * @return A Chain of Units that represent the instrumentation of ifStmtUnit
   */
  private static Chain<Unit> generateInstrumentationUnits(Unit ifStmtUnit, Body b) {

    AbstractBinopExpr expression =
        (AbstractBinopExpr)
            ((JIfStmt) ifStmtUnit).getCondition(); // implementation of AbstractBinopExpr
    Value operand1 = expression.getOp1();
    Value operand2 = expression.getOp2();

    JimpleLocal op1Local = (JimpleLocal) operand1;

    // Local localOperand = Jimple.v().newLocal("op1", operand1.getType());
    // b.getLocals().add(localOperand);

    // We need to use these operand as Locals or constants
    /**
     * JimpleLocal test; if(operand1 instanceof soot.jimple.internal.JimpleLocal) test =
     * (JimpleLocal)operand1; else test = null;
     */
    String op = expression.getClass().toString();

    Chain<Unit> resultUnits = new HashChain<Unit>();
    Local tmpRef;
    // Add locals directely on the top of the body, java.io.printStream tmpRef
    tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("java.io.PrintStream"));
    b.getLocals().addFirst(tmpRef);

    // add "tmpRef = java.lang.System.out"
    resultUnits.add(
        Jimple.v()
            .newAssignStmt(
                tmpRef,
                Jimple.v()
                    .newStaticFieldRef(
                        Scene.v()
                            .getField("<java.lang.System: java.io.PrintStream out>")
                            .makeRef())));
    {
      SootMethod toCall =
          Scene.v().getMethod("<java.io.PrintStream: void println(java.lang.String)>");
      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operande 1: "))));
      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef,
                          toCall.makeRef(),
                          StringConstant.v(operand1.getClass().toString()))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operande 2:"))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef,
                          toCall.makeRef(),
                          StringConstant.v(operand2.getClass().toString()))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operateur: "))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), StringConstant.v(op))));
    }

    return resultUnits;
  }
Пример #19
0
  private Value generateCorrectObject(Body body, Value value, List<Unit> generated) {
    if (value.getType() instanceof PrimType) {
      // in case of a primitive type, we use boxing (I know it is not nice, but it works...) in
      // order to use the Object type
      if (value.getType() instanceof BooleanType) {
        Local booleanLocal = generateFreshLocal(body, RefType.v("java.lang.Boolean"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Boolean");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Boolean valueOf(boolean)");
        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(booleanLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return booleanLocal;
      } else if (value.getType() instanceof ByteType) {
        Local byteLocal = generateFreshLocal(body, RefType.v("java.lang.Byte"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Byte");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Byte valueOf(byte)");
        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(byteLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return byteLocal;
      } else if (value.getType() instanceof CharType) {
        Local characterLocal = generateFreshLocal(body, RefType.v("java.lang.Character"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Character");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Character valueOf(char)");
        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(characterLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return characterLocal;
      } else if (value.getType() instanceof DoubleType) {
        Local doubleLocal = generateFreshLocal(body, RefType.v("java.lang.Double"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Double");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Double valueOf(double)");

        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(doubleLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return doubleLocal;
      } else if (value.getType() instanceof FloatType) {
        Local floatLocal = generateFreshLocal(body, RefType.v("java.lang.Float"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Float");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Float valueOf(float)");
        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(floatLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return floatLocal;
      } else if (value.getType() instanceof IntType) {
        Local integerLocal = generateFreshLocal(body, RefType.v("java.lang.Integer"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Integer");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Integer valueOf(int)");
        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(integerLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return integerLocal;
      } else if (value.getType() instanceof LongType) {
        Local longLocal = generateFreshLocal(body, RefType.v("java.lang.Long"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Long");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Long valueOf(long)");
        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(longLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return longLocal;
      } else if (value.getType() instanceof ShortType) {
        Local shortLocal = generateFreshLocal(body, RefType.v("java.lang.Short"));

        SootClass sootClass = Scene.v().getSootClass("java.lang.Short");
        SootMethod valueOfMethod = sootClass.getMethod("java.lang.Short valueOf(short)");
        StaticInvokeExpr staticInvokeExpr =
            Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), value);

        Unit newAssignStmt = Jimple.v().newAssignStmt(shortLocal, staticInvokeExpr);
        generated.add(newAssignStmt);

        return shortLocal;
      } else throw new RuntimeException("Ooops, something went all wonky!");
    } else
      // just return the value, there is nothing to box
      return value;
  }