use of com.google.security.zynamics.zylib.disassembly.IOperandTreeNode 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.zylib.disassembly.IOperandTreeNode 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.zylib.disassembly.IOperandTreeNode 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.zylib.disassembly.IOperandTreeNode in project binnavi by google.
the class ARMQadd16Translator 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 sourceRegister1 = registerOperand2.getValue();
final String sourceRegister2 = registerOperand3.getValue();
final String addOperation = "ADD";
final long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
new Processor() {
@Override
protected int getResultShiftDelta() {
return 0;
}
@Override
protected String[] process(final long offset, final String[] firstTwo, final String[] secondTwo) {
final String sum1 = environment.getNextVariableString();
final String sum2 = environment.getNextVariableString();
final String sum1Sat = environment.getNextVariableString();
final String sum2Sat = environment.getNextVariableString();
long baseOffset = offset - instructions.size();
// do the adds
instructions.add(ReilHelpers.createAdd(baseOffset + instructions.size(), dw, firstTwo[0], dw, secondTwo[0], dw, sum1));
instructions.add(ReilHelpers.createAdd(baseOffset + instructions.size(), dw, firstTwo[1], dw, secondTwo[1], dw, sum2));
// Do the Sat
Helpers.signedSat(baseOffset + instructions.size(), environment, instruction, instructions, dw, firstTwo[0], dw, secondTwo[0], dw, sum1, addOperation, sum1Sat, 16L, "");
Helpers.signedSat(baseOffset + instructions.size(), environment, instruction, instructions, dw, firstTwo[1], dw, secondTwo[1], dw, sum2, addOperation, sum2Sat, 16L, "");
return new String[] { sum1Sat, sum2Sat };
}
}.generate(environment, baseOffset, 16, sourceRegister1, sourceRegister2, targetRegister, instructions);
}
use of com.google.security.zynamics.zylib.disassembly.IOperandTreeNode 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