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);
}
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);
}
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));
}
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));
}
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));
}
Aggregations