use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMMsrTranslator method translateCore.
@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
final IOperandTreeNode sourceOperand = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
final String sourceRegister = (sourceOperand.getValue());
final OperandSize bt = OperandSize.BYTE;
final OperandSize dw = OperandSize.DWORD;
final String tmpZ = environment.getNextVariableString();
final String tmpC = environment.getNextVariableString();
final String tmpV = environment.getNextVariableString();
final String tmpQ = environment.getNextVariableString();
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-31), bt, "N"));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-30), bt, tmpZ));
instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpZ, bt, String.valueOf(1L), bt, "Z"));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-29), bt, tmpC));
instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpC, bt, String.valueOf(1L), bt, "C"));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-28), bt, tmpV));
instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpV, bt, String.valueOf(1L), bt, "C"));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, sourceRegister, dw, String.valueOf(-29), bt, tmpQ));
instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpQ, bt, String.valueOf(1L), bt, "C"));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMMulTranslator 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 IOperandTreeNode registerOperand3 = instruction.getOperands().get(2).getRootNode().getChildren().get(0);
final String targetRegister = (registerOperand1.getValue());
final String multRegister1 = (registerOperand2.getValue());
final String multRegister2 = (registerOperand3.getValue());
final String tmpVar1 = environment.getNextVariableString();
final OperandSize bt = OperandSize.BYTE;
final OperandSize dw = OperandSize.DWORD;
final OperandSize qw = OperandSize.QWORD;
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
instructions.add(ReilHelpers.createMul(baseOffset++, dw, multRegister1, dw, multRegister2, qw, tmpVar1));
instructions.add(ReilHelpers.createAnd(baseOffset++, qw, tmpVar1, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
if (instruction.getMnemonic().endsWith("S") && (instruction.getMnemonic().length() != 5)) {
// 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();
// N Flag Rd[31]
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, targetRegister, 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, targetRegister, bt, "Z"));
}
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMOrrTranslator 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 registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
final IOperandTreeNode shifter = instruction.getOperands().get(2).getRootNode();
final String targetRegister = registerOperand1.getValue();
final String sourceRegister = registerOperand2.getValue();
final OperandSize bt = OperandSize.BYTE;
final OperandSize dw = OperandSize.DWORD;
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
// 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();
final String shifterCarryOut = shifterPair.second();
// Rd = Rn OR shifter_operand
instructions.add(ReilHelpers.createOr(baseOffset++, dw, sourceRegister, dw, shifterOperand, dw, targetRegister));
if (instruction.getMnemonic().endsWith("S") && (instruction.getMnemonic().length() != 5)) {
// 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();
// N Flag Rd[31]
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, targetRegister, 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, targetRegister, bt, "Z"));
// C Flag shifter_carryout
instructions.add(ReilHelpers.createStr(baseOffset++, bt, shifterCarryOut, bt, "C"));
}
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMPkhbtTranslator 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 registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
final IOperandTreeNode shifter = instruction.getOperands().get(2).getRootNode();
final String targetRegister = registerOperand1.getValue();
final String sourceRegister = registerOperand2.getValue();
final OperandSize dw = OperandSize.DWORD;
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
// 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();
final String tmpResult1 = environment.getNextVariableString();
final String tmpResult2 = environment.getNextVariableString();
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, shifterOperand, dw, String.valueOf(0xFFFF0000L), dw, tmpResult1));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister, dw, String.valueOf(0xFFFFL), dw, tmpResult2));
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpResult1, dw, tmpResult2, dw, targetRegister));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMBlxTranslator method translateCore.
@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
final String[] meta = new String[] { "isCall", "true" };
final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
final String sourceRegister1 = registerOperand1.getValue();
final OperandSize dw = OperandSize.DWORD;
final OperandSize bt = OperandSize.BYTE;
final String jumpOperand = environment.getNextVariableString();
long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
instructions.add(ReilHelpers.createStr(baseOffset++, dw, String.valueOf(instruction.getAddress().toLong() + 0x4), dw, "LR"));
if (registerOperand1.getType() == ExpressionType.REGISTER) {
/**
* instruction TYPE (2)
*
* BLX{<cond>} <Rm>
*
* if ConditionPassed(cond) then target = Rm LR = address of instruction after the BLX
* instruction CPSR T bit = target[0] PC = target AND 0xFFFFFFFE
*
*/
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));
} else {
/**
* instruction TYPE (1)
*
* BLX <target_addr>
*
* LR = address of the instruction after the BLX instruction CPSR T bit = 1 PC = PC +
* (SignExtend(signed_immed_24) << 2) + (H << 1)
*/
instructions.add(ReilHelpers.createStr(baseOffset++, bt, String.valueOf(1), bt, "T"));
instructions.add(ReilHelpers.createStr(baseOffset++, dw, sourceRegister1, dw, jumpOperand));
}
instructions.add(ReilHelpers.createJcc(baseOffset++, bt, String.valueOf(1L), dw, jumpOperand, meta));
}
Aggregations