Search in sources :

Example 16 with IOperandTreeNode

use of com.google.security.zynamics.zylib.disassembly.IOperandTreeNode in project binnavi by google.

the class ARMBxTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final String sourceRegister1 = (registerOperand1.getValue());
    final String[] meta_false = new String[] { "isCall", "false" };
    final String[] meta_true = new String[] { "isCall", "true" };
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize bt = OperandSize.BYTE;
    final String jumpOperand = environment.getNextVariableString();
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, bt, String.valueOf(1), bt, "T"));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0xFFFFFFFEL), dw, jumpOperand));
    if (sourceRegister1.equalsIgnoreCase("LR")) {
        instructions.add(ReilHelpers.createJcc(baseOffset++, bt, String.valueOf(1), dw, jumpOperand, meta_false));
    } else {
        instructions.add(ReilHelpers.createJcc(baseOffset++, bt, String.valueOf(1), dw, jumpOperand, meta_true));
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 17 with IOperandTreeNode

use of com.google.security.zynamics.zylib.disassembly.IOperandTreeNode in project binnavi by google.

the class ARMCmnTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode shifter = instruction.getOperands().get(1).getRootNode();
    final String sourceRegister = (registerOperand1.getValue());
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize wd = OperandSize.WORD;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize qw = OperandSize.QWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String tmpVar1 = environment.getNextVariableString();
    final String aluOut = environment.getNextVariableString();
    // compute <shifter_operand>
    final Pair<String, String> shifterPair = AddressingModeOneGenerator.generate(baseOffset, environment, instruction, instructions, shifter);
    baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    final String shifterOperand = shifterPair.first();
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, sourceRegister, dw, shifterOperand, qw, tmpVar1));
    instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpVar1, dw, String.valueOf(0xFFFFFFFFL), dw, aluOut));
    // match the case where we have to set flags this does not handle the S == 1 and Rd == R15 case
    // !!!
    final String tmpVar3 = environment.getNextVariableString();
    final String tmpVar4 = environment.getNextVariableString();
    final String msbVar1 = environment.getNextVariableString();
    final String msbVar2 = environment.getNextVariableString();
    // N Flag Rd[31]
    instructions.add(ReilHelpers.createBsh(baseOffset++, qw, tmpVar1, dw, String.valueOf(-31L), bt, tmpVar3));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar3, bt, String.valueOf(1L), bt, "N"));
    // Z Flag if Rd == 0 then 1 else 0
    instructions.add(ReilHelpers.createBisz(baseOffset++, dw, aluOut, bt, "Z"));
    // C Flag CarryFrom(Rn + shifter_operand)
    instructions.add(ReilHelpers.createBsh(baseOffset++, qw, tmpVar1, wd, String.valueOf(-32L), bt, tmpVar4));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar4, bt, String.valueOf(1L), bt, "C"));
    // V Flag OverflowFrom(Rn + shifter_operand)
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, shifterOperand, wd, String.valueOf(-31L), bt, msbVar1));
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, wd, String.valueOf(-31L), bt, msbVar2));
    // ( msbA XOR msbR ) AND ( msbB XOR msbR ) == OF
    instructions.add(ReilHelpers.createXor(baseOffset++, bt, msbVar1, bt, "N", bt, tmpVar4));
    instructions.add(ReilHelpers.createXor(baseOffset++, bt, msbVar2, bt, "N", bt, tmpVar3));
    instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar4, bt, tmpVar3, bt, "V"));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 18 with IOperandTreeNode

use of com.google.security.zynamics.zylib.disassembly.IOperandTreeNode in project binnavi by google.

the class ARMCpyTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final String targetRegister = (registerOperand1.getValue());
    final String sourceRegister = (registerOperand2.getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
    instructions.add(ReilHelpers.createStr(baseOffset++, dw, sourceRegister, dw, targetRegister));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 19 with IOperandTreeNode

use of com.google.security.zynamics.zylib.disassembly.IOperandTreeNode in project binnavi by google.

the class ARMLdmTranslator method translateCore.

/**
   * LDM{<cond>}<addressing_mode> <Rn>{!}, <registers>
   */
/**
   * LDM{<cond>}<addressing_mode> <Rn>, <registers_without_pc>^
   */
@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    /**
     * LDM{<cond>}<addressing_mode> <Rn>{!}, <registers>
     */
    String typeValue = "";
    if (instruction.getMnemonic().endsWith(".W")) {
        typeValue = instruction.getMnemonic().length() == 9 ? instruction.getMnemonic().substring(5, 7) : instruction.getMnemonic().substring(3, 5);
    } else {
        typeValue = instruction.getMnemonic().length() == 7 ? instruction.getMnemonic().substring(5) : instruction.getMnemonic().substring(3);
    }
    IOperandTreeNode registerOperand1;
    String wBit = "1";
    if (instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().size() == 1) {
        wBit = "2";
        registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().get(0);
    } else {
        registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    }
    final IOperandTreeNode rootNodeOfRegisterList = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final String registerNodeValue = (registerOperand1.getValue());
    final int registerListLength = rootNodeOfRegisterList.getChildren().size();
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    final String tmpValue = environment.getNextVariableString();
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final String addressPair = AddressingModeFourGenerator.generate(baseOffset, environment, instruction, instructions, typeValue, registerNodeValue, wBit, rootNodeOfRegisterList);
    final String tmpAddress = addressPair;
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    for (int i = 0; i < registerListLength; i++) {
        if ((rootNodeOfRegisterList.getChildren().get(i).getValue()).equalsIgnoreCase("PC")) {
            /*
         * right now we do assume all code we receive is ARMv5 and above
         */
            instructions.add(ReilHelpers.createLdm(baseOffset++, dw, tmpAddress, dw, tmpValue));
            instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpValue, dw, String.valueOf(0xFFFFFFFEL), dw, ("PC")));
            instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpValue, bt, String.valueOf(1), bt, "T"));
        // if lower
        // instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpValue, dw,
        // String.valueOf(0xFFFFFFFCL), dw, ("PC")));
        } else {
            instructions.add(ReilHelpers.createLdm(baseOffset++, dw, tmpAddress, dw, (rootNodeOfRegisterList.getChildren().get(i).getValue())));
        }
        instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpAddress, bt, String.valueOf(4L), dw, tmpAddress));
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 20 with IOperandTreeNode

use of com.google.security.zynamics.zylib.disassembly.IOperandTreeNode in project binnavi by google.

the class ARMLdrTranslator method translateCore.

@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode rootNode = instruction.getOperands().get(1).getRootNode();
    final String registerNodeValue = (registerOperand1.getValue());
    final OperandSize dw = OperandSize.DWORD;
    long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    final Pair<String, String> resultPair = AddressingModeTwoGenerator.generate(baseOffset, environment, instruction, instructions, rootNode);
    final String tmpAddress = resultPair.first();
    final String tmpData1 = environment.getNextVariableString();
    baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
    instructions.add(ReilHelpers.createLdm(baseOffset++, dw, tmpAddress, dw, tmpData1));
    if ((registerNodeValue).equalsIgnoreCase("PC")) {
        instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpData1, dw, String.valueOf(0xFFFFFFFEL), dw, registerNodeValue));
    } else {
        instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpData1, dw, String.valueOf(0xFFFFFFFFL), dw, registerNodeValue));
    }
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Aggregations

IOperandTreeNode (com.google.security.zynamics.zylib.disassembly.IOperandTreeNode)518 OperandSize (com.google.security.zynamics.reil.OperandSize)257 BigInteger (java.math.BigInteger)5 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)3 InternalTranslationException (com.google.security.zynamics.reil.translators.InternalTranslationException)2 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)2 IReference (com.google.security.zynamics.zylib.disassembly.IReference)2 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)1 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)1 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)1 ReilOperandNode (com.google.security.zynamics.reil.ReilOperandNode)1 TranslationResult (com.google.security.zynamics.reil.translators.TranslationResult)1 IInstruction (com.google.security.zynamics.zylib.disassembly.IInstruction)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1