Beispiel #1
0
  /*
    case_label =
    {constant} case minus? integer_constant |
    {default}  default;
  */
  public void outAConstantCaseLabel(AConstantCaseLabel node) {
    String s = (String) mProductions.removeLast();
    int sign = 1;
    if (node.getMinus() != null) sign = -1;

    if (s.endsWith("L")) {
      mProductions.addLast(LongConstant.v(sign * Long.parseLong(s.substring(0, s.length() - 1))));
    } else mProductions.addLast(IntConstant.v(sign * Integer.parseInt(s)));
  }
Beispiel #2
0
  public void outAIntegerConstant(AIntegerConstant node) {
    String s = (String) mProductions.removeLast();

    StringBuffer buf = new StringBuffer();
    if (node.getMinus() != null) buf.append('-');
    buf.append(s);

    s = buf.toString();
    if (s.endsWith("L")) {
      mProductions.addLast(LongConstant.v(Long.parseLong(s.substring(0, s.length() - 1))));
    } else mProductions.addLast(IntConstant.v(Integer.parseInt(s)));
  }
Beispiel #3
0
  public void defaultCase(Node node) {
    if (node instanceof TQuotedName
        || node instanceof TFullIdentifier
        || node instanceof TIdentifier
        || node instanceof TStringConstant
        || node instanceof TIntegerConstant
        || node instanceof TFloatConstant
        || node instanceof TAtIdentifier) {

      if (debug) G.v().out.println("Default case -pushing token:" + ((Token) node).getText());
      String tokenString = ((Token) node).getText();
      if (node instanceof TStringConstant || node instanceof TQuotedName) {
        tokenString = tokenString.substring(1, tokenString.length() - 1);
      }

      if (node instanceof TIdentifier
          || node instanceof TFullIdentifier
          || node instanceof TQuotedName
          || node instanceof TStringConstant) {
        try {
          tokenString = StringTools.getUnEscapedStringOf(tokenString);

        } catch (RuntimeException e) {
          G.v().out.println(tokenString);
          throw e;
        }
      }

      mProductions.addLast(tokenString);
    }
  }
Beispiel #4
0
  public void outAAssignStatement(AAssignStatement node) {
    Value rvalue = (Value) mProductions.removeLast();
    Value variable = (Value) mProductions.removeLast();

    Unit u = Jimple.v().newAssignStmt(variable, rvalue);
    mProductions.addLast(u);
  }
Beispiel #5
0
  public void outAInvokeStatement(AInvokeStatement node) {
    Value op = (Value) mProductions.removeLast();

    Unit u = Jimple.v().newInvokeStmt(op);

    mProductions.addLast(u);
  }
Beispiel #6
0
  public void outANonstaticInvokeExpr(ANonstaticInvokeExpr node) {
    List args;

    if (node.getArgList() != null) args = (List) mProductions.removeLast();
    else args = new ArrayList();

    SootMethodRef method = (SootMethodRef) mProductions.removeLast();

    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);

    Node invokeType = (Node) node.getNonstaticInvoke();
    Expr invokeExpr;

    if (invokeType instanceof ASpecialNonstaticInvoke) {
      invokeExpr = Jimple.v().newSpecialInvokeExpr(l, method, args);
    } else if (invokeType instanceof AVirtualNonstaticInvoke) {
      invokeExpr = Jimple.v().newVirtualInvokeExpr(l, method, args);
    } else {
      if (debug)
        if (!(invokeType instanceof AInterfaceNonstaticInvoke))
          throw new RuntimeException("expected interface invoke.");
      invokeExpr = Jimple.v().newInterfaceInvokeExpr(l, method, args);
    }

    mProductions.addLast(invokeExpr);
  }
Beispiel #7
0
  public void outALocalImmediate(ALocalImmediate node) {
    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);
    mProductions.addLast(l);
  }
Beispiel #8
0
 public void outAFullIdentNonvoidType(AFullIdentNonvoidType node) {
   String typeName = (String) mProductions.removeLast();
   Type t = RefType.v(typeName);
   int dim = node.getArrayBrackets().size();
   if (dim > 0) t = ArrayType.v(t, dim);
   mProductions.addLast(t);
 }
Beispiel #9
0
  public void outALookupswitchStatement(ALookupswitchStatement node) {
    List lookupValues = new ArrayList();
    List targets = new ArrayList();
    UnitBox defaultTarget = null;

    if (node.getCaseStmt() != null) {
      int size = node.getCaseStmt().size();

      for (int i = 0; i < size; i++) {
        Object valueTargetPair = mProductions.removeLast();
        if (valueTargetPair instanceof UnitBox) {
          if (defaultTarget != null)
            throw new RuntimeException("error: can't ;have more than 1 default stmt");

          defaultTarget = (UnitBox) valueTargetPair;
        } else {
          Object[] pair = (Object[]) valueTargetPair;

          lookupValues.add(0, pair[0]);
          targets.add(0, pair[1]);
        }
      }
    } else {
      throw new RuntimeException("error: switch stmt has no case stmts");
    }

    Value key = (Value) mProductions.removeLast();
    Unit switchStmt = Jimple.v().newLookupSwitchStmt(key, lookupValues, targets, defaultTarget);

    mProductions.addLast(switchStmt);
  }
Beispiel #10
0
  public void outAIdentityNoTypeStatement(AIdentityNoTypeStatement node) {
    mProductions.removeLast(); // get rid of @caughtexception string presently on top of the stack
    Value local =
        (Value) mLocals.get(mProductions.removeLast()); // the local ref from it's identifier

    Unit u = Jimple.v().newIdentityStmt(local, Jimple.v().newCaughtExceptionRef());
    mProductions.addLast(u);
  }
Beispiel #11
0
  public void outABinopExpr(ABinopExpr node) {
    Value right = (Value) mProductions.removeLast();
    BinopExpr expr = (BinopExpr) mProductions.removeLast();
    Value left = (Value) mProductions.removeLast();

    expr.setOp1(left);
    expr.setOp2(right);
    mProductions.addLast(expr);
  }
Beispiel #12
0
  public void outAArrayRef(AArrayRef node) {
    Value immediate = (Value) mProductions.removeLast();
    String identifier = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(identifier);
    if (l == null) throw new RuntimeException("did not find local: " + identifier);

    mProductions.addLast(Jimple.v().newArrayRef(l, immediate));
  }
Beispiel #13
0
  public void outAGotoStatement(AGotoStatement node) {
    String targetLabel = (String) mProductions.removeLast();

    UnitBox box = Jimple.v().newStmtBox(null);
    Unit branch = Jimple.v().newGotoStmt(box);

    addBoxToPatch(targetLabel, box);

    mProductions.addLast(branch);
  }
Beispiel #14
0
  public void outALocalFieldRef(ALocalFieldRef node) {
    SootFieldRef field = (SootFieldRef) mProductions.removeLast();

    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);

    mProductions.addLast(Jimple.v().newInstanceFieldRef(l, field));
  }
Beispiel #15
0
  /*
    case_stmt =
    case_label colon goto_stmt;
  */
  public void outACaseStmt(ACaseStmt node) {
    String labelName = (String) mProductions.removeLast();
    UnitBox box = Jimple.v().newStmtBox(null);

    addBoxToPatch(labelName, box);

    Value labelValue = null;
    if (node.getCaseLabel() instanceof AConstantCaseLabel)
      labelValue = (Value) mProductions.removeLast();

    // if labelValue == null, this is the default label.
    if (labelValue == null) mProductions.addLast(box);
    else {
      Object[] valueTargetPair = new Object[2];
      valueTargetPair[0] = labelValue;
      valueTargetPair[1] = box;
      mProductions.addLast(valueTargetPair);
    }
  }
Beispiel #16
0
  public void outAIfStatement(AIfStatement node) {
    String targetLabel = (String) mProductions.removeLast();
    Value condition = (Value) mProductions.removeLast();

    UnitBox box = Jimple.v().newStmtBox(null);
    Unit u = Jimple.v().newIfStmt(condition, box);

    addBoxToPatch(targetLabel, box);

    mProductions.addLast(u);
  }
Beispiel #17
0
  public void outAReturnStatement(AReturnStatement node) {
    Value v;
    Stmt s = null;
    if (node.getImmediate() != null) {
      v = (Value) mProductions.removeLast();
      s = Jimple.v().newReturnStmt(v);
    } else {
      s = Jimple.v().newReturnVoidStmt();
    }

    mProductions.addLast(s);
  }
Beispiel #18
0
  public void outADeclaration(ADeclaration node) {
    List localNameList = (List) mProductions.removeLast();
    Type type = (Type) mProductions.removeLast();
    Iterator it = localNameList.iterator();
    List localList = new ArrayList();

    while (it.hasNext()) {
      Local l = Jimple.v().newLocal((String) it.next(), type);
      mLocals.put(l.getName(), l);
      localList.add(l);
    }
    mProductions.addLast(localList);
  }
Beispiel #19
0
  public void outAFieldSignature(AFieldSignature node) {
    String className, fieldName;
    Type t;

    fieldName = (String) mProductions.removeLast();
    t = (Type) mProductions.removeLast();
    className = (String) mProductions.removeLast();

    SootClass cl = mResolver.makeClassRef(className);
    SootFieldRef field = Scene.v().makeFieldRef(cl, fieldName, t, false);

    mProductions.addLast(field);
  }
Beispiel #20
0
  /*
    throws_clause =
    throws class_name_list;
  */
  public void outAThrowsClause(AThrowsClause node) {
    List l = (List) mProductions.removeLast();

    Iterator it = l.iterator();
    List exceptionClasses = new ArrayList(l.size());

    while (it.hasNext()) {
      String className = (String) it.next();

      exceptionClasses.add(mResolver.makeClassRef(className));
    }

    mProductions.addLast(exceptionClasses);
  }
Beispiel #21
0
  public void outAStringConstant(AStringConstant node) {
    String s = (String) mProductions.removeLast();
    mProductions.addLast(StringConstant.v(s));
    /*
      try {
      String t = StringTools.getUnEscapedStringOf(s);

      mProductions.push(StringConstant.v(t));
      } catch(RuntimeException e) {
      G.v().out.println(s);
      throw e;
      }
    */
  }
Beispiel #22
0
  /*
    method_signature =
    cmplt [class_name]:class_name [first]:colon type [method_name]:name  l_paren parameter_list? r_paren cmpgt;
  */
  public void outAMethodSignature(AMethodSignature node) {
    String className, methodName;
    List parameterList = new ArrayList();
    Type returnType;

    if (node.getParameterList() != null) parameterList = (List) mProductions.removeLast();

    methodName = (String) mProductions.removeLast();
    Type type = (Type) mProductions.removeLast();
    className = (String) mProductions.removeLast();

    SootClass sootClass = mResolver.makeClassRef(className);
    SootMethodRef sootMethod =
        Scene.v().makeMethodRef(sootClass, methodName, parameterList, type, false);

    mProductions.addLast(sootMethod);
  }
Beispiel #23
0
  public void outAStaticInvokeExpr(AStaticInvokeExpr node) {
    List args;

    if (node.getArgList() != null) args = (List) mProductions.removeLast();
    else args = new ArrayList();

    SootMethodRef method = (SootMethodRef) mProductions.removeLast();
    method =
        Scene.v()
            .makeMethodRef(
                method.declaringClass(),
                method.name(),
                method.parameterTypes(),
                method.returnType(),
                true);

    mProductions.addLast(Jimple.v().newStaticInvokeExpr(method, args));
  }
Beispiel #24
0
  public void outACatchClause(ACatchClause node) {
    String exceptionName;
    UnitBox withUnit, fromUnit, toUnit;

    withUnit = Jimple.v().newStmtBox(null);
    addBoxToPatch((String) mProductions.removeLast(), withUnit);

    toUnit = Jimple.v().newStmtBox(null);
    addBoxToPatch((String) mProductions.removeLast(), toUnit);

    fromUnit = Jimple.v().newStmtBox(null);
    addBoxToPatch((String) mProductions.removeLast(), fromUnit);

    exceptionName = (String) mProductions.removeLast();

    Trap trap =
        Jimple.v().newTrap(mResolver.makeClassRef(exceptionName), fromUnit, toUnit, withUnit);
    mProductions.addLast(trap);
  }
Beispiel #25
0
  public void outAMultiNewExpr(AMultiNewExpr node) {

    LinkedList arrayDesc = node.getArrayDescriptor();

    int descCnt = arrayDesc.size();
    List sizes = new LinkedList();

    Iterator it = arrayDesc.iterator();
    while (it.hasNext()) {
      AArrayDescriptor o = (AArrayDescriptor) it.next();
      if (o.getImmediate() != null) sizes.add(0, (Value) mProductions.removeLast());
      else break;
    }

    Type type = (Type) mProductions.removeLast();
    ArrayType arrayType = ArrayType.v(type, descCnt);

    mProductions.addLast(Jimple.v().newNewMultiArrayExpr(arrayType, sizes));
  }
Beispiel #26
0
  public void outAIdentityStatement(AIdentityStatement node) {
    Type identityRefType = (Type) mProductions.removeLast();
    String atClause = (String) mProductions.removeLast();
    Value local =
        (Value) mLocals.get(mProductions.removeLast()); // the local ref from it's identifier

    Value ref = null;
    if (atClause.startsWith("@this")) {
      ref = Jimple.v().newThisRef((RefType) identityRefType);
    } else if (atClause.startsWith("@parameter")) {
      int index = Integer.parseInt(atClause.substring(10, atClause.length() - 1));

      ref = Jimple.v().newParameterRef(identityRefType, index);
    } else
      throw new RuntimeException(
          "shouldn't @caughtexception be handled by outAIdentityNoTypeStatement: got" + atClause);

    Unit u = Jimple.v().newIdentityStmt(local, ref);
    mProductions.addLast(u);
  }
Beispiel #27
0
  public void outAFile(AFile node) {
    // not not pop members; they have been taken care of.
    List implementsList = null;
    String superClass = null;

    String classType = null;

    if (node.getImplementsClause() != null) {
      implementsList = (List) mProductions.removeLast();
    }
    if (node.getExtendsClause() != null) {
      superClass = (String) mProductions.removeLast();
    }

    classType = (String) mProductions.removeLast();

    int modifierCount = node.getModifier().size();

    int modifierFlags = processModifiers(node.getModifier());

    if (classType.equals("interface")) modifierFlags |= Modifier.INTERFACE;

    mSootClass.setModifiers(modifierFlags);

    if (superClass != null) {
      mSootClass.setSuperclass(mResolver.makeClassRef(superClass));
    }

    if (implementsList != null) {
      Iterator implIt = implementsList.iterator();
      while (implIt.hasNext()) {
        SootClass interfaceClass = mResolver.makeClassRef((String) implIt.next());
        mSootClass.addInterface(interfaceClass);
      }
    }

    mProductions.addLast(mSootClass);
  }
Beispiel #28
0
  /* ('#' (('-'? 'Infinity') | 'NaN') ('f' | 'F')? ) ; */
  public void outAFloatConstant(AFloatConstant node) {
    String s = (String) mProductions.removeLast();

    boolean isDouble = true;
    float value = 0;
    double dvalue = 0;

    if (s.endsWith("f") || s.endsWith("F")) isDouble = false;

    if (s.charAt(0) == '#') {
      if (s.charAt(1) == '-') {
        if (isDouble) dvalue = Double.NEGATIVE_INFINITY;
        else value = Float.NEGATIVE_INFINITY;
      } else if (s.charAt(1) == 'I') {
        if (isDouble) dvalue = Double.POSITIVE_INFINITY;
        else value = Float.POSITIVE_INFINITY;
      } else {
        if (isDouble) dvalue = Double.NaN;
        else value = Float.NaN;
      }
    } else {
      StringBuffer buf = new StringBuffer();
      if (node.getMinus() != null) buf.append('-');
      buf.append(s);
      s = buf.toString();

      if (isDouble) dvalue = Double.parseDouble(s);
      else value = Float.parseFloat(s);
    }

    Object res;
    if (isDouble) res = DoubleConstant.v(dvalue);
    else res = FloatConstant.v(value);

    mProductions.addLast(res);
  }
Beispiel #29
0
  public void outATableswitchStatement(ATableswitchStatement node) {
    List targets = new ArrayList();
    UnitBox defaultTarget = null;

    int lowIndex = 0, highIndex = 0;

    if (node.getCaseStmt() != null) {
      int size = node.getCaseStmt().size();

      for (int i = 0; i < size; i++) {
        Object valueTargetPair = mProductions.removeLast();
        if (valueTargetPair instanceof UnitBox) {
          if (defaultTarget != null)
            throw new RuntimeException("error: can't ;have more than 1 default stmt");

          defaultTarget = (UnitBox) valueTargetPair;
        } else {
          Object[] pair = (Object[]) valueTargetPair;

          if ((i == 0 && defaultTarget == null) || (i == 1 && defaultTarget != null))
            highIndex = ((IntConstant) pair[0]).value;
          if (i == (size - 1)) lowIndex = ((IntConstant) pair[0]).value;

          targets.add(0, pair[1]);
        }
      }
    } else {
      throw new RuntimeException("error: switch stmt has no case stmts");
    }

    Value key = (Value) mProductions.removeLast();
    Unit switchStmt =
        Jimple.v().newTableSwitchStmt(key, lowIndex, highIndex, targets, defaultTarget);

    mProductions.addLast(switchStmt);
  }
Beispiel #30
0
 public void outAClzzConstant(AClzzConstant node) {
   String s = (String) mProductions.removeLast();
   mProductions.addLast(ClassConstant.v(s));
 }