コード例 #1
0
ファイル: ShTranslator.java プロジェクト: rhmoult/binnavi
  @Override
  public void translate(
      final ITranslationEnvironment environment,
      final IInstruction instruction,
      final List<ReilInstruction> instructions)
      throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "sh");

    final String rt =
        instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue();

    final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
    long offset = baseOffset;

    final String address =
        SignExtendGenerator.extendAndAdd(
            offset, environment, instruction.getOperands().get(1), instructions);
    offset = baseOffset + instructions.size();

    final OperandSize dw = OperandSize.DWORD;
    final OperandSize wd = OperandSize.WORD;

    final String isolatedHalfword = environment.getNextVariableString();

    instructions.add(
        ReilHelpers.createAnd(offset++, dw, rt, wd, String.valueOf(0xFFFFL), wd, isolatedHalfword));
    instructions.add(ReilHelpers.createStm(offset++, wd, isolatedHalfword, dw, address));
  }
コード例 #2
0
 @Override
 public void translate(
     final ITranslationEnvironment environment,
     final IInstruction instruction,
     final List<ReilInstruction> instructions)
     throws InternalTranslationException {
   SignExtendGenerator.generate(
       instruction.getAddress().toLong() * 0x100,
       environment,
       instruction,
       instructions,
       "extsb",
       OperandSize.BYTE,
       false);
 }
コード例 #3
0
ファイル: LwrTranslator.java プロジェクト: rhmoult/binnavi
  @Override
  public void translate(
      final ITranslationEnvironment environment,
      final IInstruction instruction,
      final List<ReilInstruction> instructions)
      throws InternalTranslationException {
    // TODO final String todo64 = "";
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "lwr");

    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;

    final String lastTwoAddressBits = environment.getNextVariableString();
    final String shiftValue = environment.getNextVariableString();
    final String memoryShiftAmount = environment.getNextVariableString();
    final String registerMaskShiftAmount = environment.getNextVariableString();
    final String shiftedMemoryContent = environment.getNextVariableString();
    final String shiftedMemoryMask = environment.getNextVariableString();
    final String maskedRegisterContent = environment.getNextVariableString();
    final String temporaryResult = environment.getNextVariableString();
    final String memoryContent = environment.getNextVariableString();
    final String address = environment.getNextVariableString();

    final IOperandTreeNode targetRegister =
        instruction.getOperands().get(0).getRootNode().getChildren().get(0);

    final long baseOffset = ReilHelpers.toReilAddress(instruction.getAddress()).toLong();
    long offset = baseOffset;

    final String extendedValue =
        SignExtendGenerator.extendAndAdd(
            offset, environment, instruction.getOperands().get(1), instructions);

    offset = baseOffset + instructions.size();

    instructions.add(
        ReilHelpers.createAnd(
            offset++, dw, extendedValue, dw, String.valueOf(0xFFFFFFFCL), dw, address));
    instructions.add(ReilHelpers.createLdm(offset, dw, address, dw, memoryContent));

    instructions.add(
        ReilHelpers.createAnd(
            offset++, dw, extendedValue, dw, String.valueOf(3L), dw, lastTwoAddressBits));
    instructions.add(
        ReilHelpers.createBsh(
            offset++, dw, lastTwoAddressBits, dw, String.valueOf(3L), dw, shiftValue));

    final String endianess = "little";

    if (endianess.equalsIgnoreCase("little")) {
      // little endian case

      // address bits 1:0 00
      // memory content 0x11223344 shifted right by 0 -> 0x11223344
      // register content 0xAABBCCDD masked with 0x00000000 -> 0x00000000
      // both ored -> 0x11223344
      // anded with register mask 0xFFFFFFFF -> 0x11223344

      instructions.add(
          ReilHelpers.createSub(
              offset++, dw, String.valueOf(0L), dw, shiftValue, dw, memoryShiftAmount));
      instructions.add(
          ReilHelpers.createSub(
              offset++, dw, String.valueOf(32L), dw, shiftValue, dw, registerMaskShiftAmount));
    } else if (endianess.equalsIgnoreCase("big")) {
      // big endian case

      // address bits 1:0 00
      // memory content 0x11223344 shifted right by 24 -> 0x00000011
      // register contents 0xAABBCCDD masked with 0xFFFFFF00 -> 0xAABBCC00
      // both ored -> 0xAABBCC11
      // anded with register mask 0xFFFFFFF -> 0xAABBCC11

      instructions.add(
          ReilHelpers.createAdd(
              offset++, dw, String.valueOf(-24L), dw, shiftValue, dw, memoryShiftAmount));
      instructions.add(
          ReilHelpers.createAdd(
              offset++, dw, String.valueOf(8L), dw, shiftValue, dw, registerMaskShiftAmount));
    }

    // bring the loaded memory into the correct position for register transfer
    instructions.add(
        ReilHelpers.createBsh(
            offset++, dw, memoryContent, dw, memoryShiftAmount, qw, shiftedMemoryContent));

    // bring the register content into the correct form
    instructions.add(
        ReilHelpers.createBsh(
            offset++,
            dw,
            String.valueOf(0xFFFFFFFFL),
            dw,
            registerMaskShiftAmount,
            dw,
            shiftedMemoryMask));
    instructions.add(
        ReilHelpers.createAnd(
            offset++,
            dw,
            targetRegister.getValue(),
            dw,
            shiftedMemoryMask,
            dw,
            maskedRegisterContent));

    // combine the extracted information and adjust the size to machine register size
    instructions.add(
        ReilHelpers.createOr(
            offset++, dw, maskedRegisterContent, qw, shiftedMemoryContent, qw, temporaryResult));
    instructions.add(
        ReilHelpers.createAnd(
            offset++,
            qw,
            temporaryResult,
            dw,
            String.valueOf(0xFFFFFFFFL),
            dw,
            targetRegister.getValue()));
  }