コード例 #1
0
ファイル: Walker.java プロジェクト: safdariqbal/soot
  /* ('#' (('-'? '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);
  }
コード例 #2
0
  private NumericConstant getArrayElement(Number element, DexBody body, int arrayRegister) {

    List<DexlibAbstractInstruction> instructions = body.instructionsBefore(this);
    Set<Integer> usedRegisters = new HashSet<Integer>();
    usedRegisters.add(arrayRegister);

    Type elementType = null;
    Outer:
    for (DexlibAbstractInstruction i : instructions) {
      if (usedRegisters.isEmpty()) break;

      for (int reg : usedRegisters)
        if (i instanceof NewArrayInstruction) {
          NewArrayInstruction newArrayInstruction = (NewArrayInstruction) i;
          Instruction22c instruction22c = (Instruction22c) newArrayInstruction.instruction;
          if (instruction22c.getRegisterA() == reg) {
            ArrayType arrayType =
                (ArrayType) DexType.toSoot((TypeReference) instruction22c.getReference());
            elementType = arrayType.getElementType();
            break Outer;
          }
        }

      //        // look for obsolete registers
      //        for (int reg : usedRegisters) {
      //          if (i.overridesRegister(reg)) {
      //            usedRegisters.remove(reg);
      //            break;      // there can't be more than one obsolete
      //          }
      //        }

      // look for new registers
      for (int reg : usedRegisters) {
        int newRegister = i.movesToRegister(reg);
        if (newRegister != -1) {
          usedRegisters.add(newRegister);
          usedRegisters.remove(reg);
          break; // there can't be more than one new
        }
      }
    }

    if (elementType == null) {
      // throw new InternalError("Unable to find array type to type array elements!");
      G.v()
          .out
          .println(
              "Warning: Unable to find array type to type array elements! Array was not defined! (obfuscated bytecode?)");
      return null;
    }

    NumericConstant value;

    if (elementType instanceof BooleanType) {
      value = IntConstant.v(element.intValue());
      IntConstant ic = (IntConstant) value;
      if (!(ic.value == 0 || ic.value == 1)) {
        throw new RuntimeException("ERROR: Invalid value for boolean: " + value);
      }
    } else if (elementType instanceof ByteType) {
      value = IntConstant.v(element.byteValue());
    } else if (elementType instanceof CharType || elementType instanceof ShortType) {
      value = IntConstant.v(element.shortValue());
    } else if (elementType instanceof DoubleType) {
      value = DoubleConstant.v(Double.longBitsToDouble(element.longValue()));
    } else if (elementType instanceof FloatType) {
      value = FloatConstant.v(Float.intBitsToFloat(element.intValue()));
    } else if (elementType instanceof IntType) {
      value = IntConstant.v(element.intValue());
    } else if (elementType instanceof LongType) {
      value = LongConstant.v(element.longValue());
    } else {
      throw new RuntimeException(
          "Invalid Array Type occured in FillArrayDataInstruction: " + elementType);
    }
    Debug.printDbg("array element: ", value);
    return value;
  }
コード例 #3
0
 public void caseDoubleConstant(DoubleConstant arg0) {
   m_output.append(" " + replaceNumber(arg0.toString()) + " ");
 }