Example #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)));
  }
Example #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)));
  }
  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;
  }
 public void caseLongConstant(LongConstant arg0) {
   m_output.append(" " + replaceNumber(arg0.toString()) + " ");
 }