Search in sources :

Example 41 with IOperandTreeNode

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

the class SubfoTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "subfo");
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final IOperandTreeNode registerOperand2 = instruction.getOperands().get(2).getRootNode().getChildren().get(0);
    SubGenerator.generate(instruction.getAddress().toLong() * 0x100, environment, instruction, instructions, "subfo", registerOperand2.getValue(), registerOperand1.getValue(), false, true, false, false);
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode)

Example 42 with IOperandTreeNode

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

the class SubfzeDotTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "subfze.");
    final IOperandTreeNode registerOperand1 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    SubGenerator.generate(instruction.getAddress().toLong() * 0x100, environment, instruction, instructions, "subfze.", registerOperand1.getValue(), String.valueOf(0x0L), true, false, true, true);
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode)

Example 43 with IOperandTreeNode

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

the class SlwDotTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "slw.");
    final IOperandTreeNode targetRegister = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode sourceRegister = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final IOperandTreeNode shiftRegister = instruction.getOperands().get(2).getRootNode().getChildren().get(0);
    Long baseOffset = instruction.getAddress().toLong() * 0x100;
    final OperandSize bt = OperandSize.BYTE;
    final OperandSize dw = OperandSize.DWORD;
    final String shiftAmmount = environment.getNextVariableString();
    final String tmpResult = environment.getNextVariableString();
    final String crTemp = environment.getNextVariableString();
    /**
     * n <- rB[27-31] r <- ROTL(rS, n) if rB[26] = 0 then m <- MASK(0, 31 - n) else m <- (32)0 rA <-
     * r & m
     */
    // n <- rB[27-31]
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shiftRegister.getValue(), dw, String.valueOf(0x3FL), dw, shiftAmmount));
    // r <- ROTL(rS, n)
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister.getValue(), dw, shiftAmmount, dw, tmpResult));
    // if rB[26] = 0
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister.getValue()));
    // EQ CR0
    instructions.add(ReilHelpers.createBisz(baseOffset++, dw, targetRegister.getValue(), bt, Helpers.CR0_EQUAL));
    // LT CR0
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, targetRegister.getValue(), dw, "-31", bt, Helpers.CR0_LESS_THEN));
    // GT CR0
    instructions.add(ReilHelpers.createOr(baseOffset++, bt, Helpers.CR0_EQUAL, bt, Helpers.CR0_LESS_THEN, bt, crTemp));
    instructions.add(ReilHelpers.createBisz(baseOffset++, bt, crTemp, bt, Helpers.CR0_GREATER_THEN));
    // SO CR0
    instructions.add(ReilHelpers.createStr(baseOffset, bt, Helpers.XER_SUMMARY_OVERFLOW, bt, Helpers.CRO_SUMMARY_OVERFLOW));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 44 with IOperandTreeNode

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

the class SrawTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "sraw");
    final IOperandTreeNode targetRegister = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode sourceRegister = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final IOperandTreeNode shiftRegister = instruction.getOperands().get(2).getRootNode().getChildren().get(0);
    Long baseOffset = instruction.getAddress().toLong() * 0x100;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize bt = OperandSize.BYTE;
    final String shiftAmmount = environment.getNextVariableString();
    final String tmpResult1 = environment.getNextVariableString();
    final String tmpResult2 = environment.getNextVariableString();
    final String tmpResult3 = environment.getNextVariableString();
    final String tmpResult4 = environment.getNextVariableString();
    final String oneComp = environment.getNextVariableString();
    final String twoComp = environment.getNextVariableString();
    final String signBit = environment.getNextVariableString();
    final String isZeroIfEqual = environment.getNextVariableString();
    final String noBitsShiftedOut = environment.getNextVariableString();
    final String bitsShiftedOut = environment.getNextVariableString();
    // save sign value before shift for CA Flag
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister.getValue(), dw, String.valueOf(-31L), dw, signBit));
    // n <- rB[26-31]
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shiftRegister.getValue(), dw, String.valueOf(0x3FL), dw, shiftAmmount));
    // computer two's complement for shift amount == - (original value)
    instructions.add(ReilHelpers.createXor(baseOffset++, dw, shiftRegister.getValue(), dw, String.valueOf(0xFFFFFFFFL), dw, oneComp));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, oneComp, dw, String.valueOf(1L), dw, twoComp));
    // t = 0x8000 0000 >> n
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, String.valueOf(0x80000000L), dw, twoComp, dw, tmpResult1));
    // x >> n
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister.getValue(), dw, twoComp, dw, tmpResult2));
    // ( x >> n ) XOR t
    instructions.add(ReilHelpers.createXor(baseOffset++, dw, tmpResult2, dw, tmpResult1, dw, tmpResult3));
    // ( ( x >> n ) XOR t ) - t
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, tmpResult3, dw, tmpResult1, dw, targetRegister.getValue()));
    // compute XER[CA] Flag
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpResult2, dw, shiftRegister.getValue(), dw, tmpResult4));
    instructions.add(ReilHelpers.createXor(baseOffset++, dw, sourceRegister.getValue(), dw, tmpResult4, dw, isZeroIfEqual));
    instructions.add(ReilHelpers.createBisz(baseOffset++, dw, isZeroIfEqual, dw, noBitsShiftedOut));
    instructions.add(ReilHelpers.createBisz(baseOffset++, dw, noBitsShiftedOut, dw, bitsShiftedOut));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, bitsShiftedOut, dw, signBit, bt, Helpers.XER_CARRY_BIT));
}
Also used : IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) OperandSize(com.google.security.zynamics.reil.OperandSize)

Example 45 with IOperandTreeNode

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

the class SrawiTranslator method translate.

@Override
public void translate(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
    TranslationHelpers.checkTranslationArguments(environment, instruction, instructions, "srawi");
    final IOperandTreeNode targetRegister = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
    final IOperandTreeNode sourceRegister = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
    final IOperandTreeNode shiftRegister = instruction.getOperands().get(2).getRootNode().getChildren().get(0);
    Long baseOffset = instruction.getAddress().toLong() * 0x100;
    final OperandSize dw = OperandSize.DWORD;
    final OperandSize bt = OperandSize.BYTE;
    final String shiftAmmount = environment.getNextVariableString();
    final String tmpResult1 = environment.getNextVariableString();
    final String tmpResult2 = environment.getNextVariableString();
    final String tmpResult3 = environment.getNextVariableString();
    final String tmpResult4 = environment.getNextVariableString();
    final String oneComp = environment.getNextVariableString();
    final String twoComp = environment.getNextVariableString();
    final String signBit = environment.getNextVariableString();
    final String isZeroIfEqual = environment.getNextVariableString();
    final String noBitsShiftedOut = environment.getNextVariableString();
    final String bitsShiftedOut = environment.getNextVariableString();
    // save sign value before shift for CA Flag
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister.getValue(), dw, String.valueOf(-31L), dw, signBit));
    // n <- rB[26-31]
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shiftRegister.getValue(), dw, String.valueOf(0x3FL), dw, shiftAmmount));
    // computer two's complement for shift amount == - (original value)
    instructions.add(ReilHelpers.createXor(baseOffset++, dw, shiftRegister.getValue(), dw, String.valueOf(0xFFFFFFFFL), dw, oneComp));
    instructions.add(ReilHelpers.createAdd(baseOffset++, dw, oneComp, dw, String.valueOf(1L), dw, twoComp));
    // t = 0x8000 0000 >> n
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, String.valueOf(0x80000000L), dw, twoComp, dw, tmpResult1));
    // x >> n
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister.getValue(), dw, twoComp, dw, tmpResult2));
    // ( x >> n ) XOR t
    instructions.add(ReilHelpers.createXor(baseOffset++, dw, tmpResult2, dw, tmpResult1, dw, tmpResult3));
    // ( ( x >> n ) XOR t ) - t
    instructions.add(ReilHelpers.createSub(baseOffset++, dw, tmpResult3, dw, tmpResult1, dw, targetRegister.getValue()));
    // compute XER[CA] Flag
    instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpResult2, dw, shiftRegister.getValue(), dw, tmpResult4));
    instructions.add(ReilHelpers.createXor(baseOffset++, dw, sourceRegister.getValue(), dw, tmpResult4, dw, isZeroIfEqual));
    instructions.add(ReilHelpers.createBisz(baseOffset++, dw, isZeroIfEqual, dw, noBitsShiftedOut));
    instructions.add(ReilHelpers.createBisz(baseOffset++, dw, noBitsShiftedOut, dw, bitsShiftedOut));
    instructions.add(ReilHelpers.createAnd(baseOffset++, dw, bitsShiftedOut, dw, signBit, bt, Helpers.XER_CARRY_BIT));
}
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