use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMStmTranslator method translateCore.
/**
* STM{<cond>}<addressing_mode> <Rn>{!}, <registers
*/
@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
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;
long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
String tmpAddress = AddressingModeFourGenerator.generate(baseOffset, environment, instruction, instructions, typeValue, registerNodeValue, wBit, rootNodeOfRegisterList);
baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
for (int i = 0; i < registerListLength; i++) {
// STM Ri, addi
// ADD addi, 4, addi+1
final String nextAddress = environment.getNextVariableString();
instructions.add(ReilHelpers.createStm(baseOffset++, dw, (rootNodeOfRegisterList.getChildren().get(i).getValue()), dw, tmpAddress));
instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpAddress, bt, String.valueOf(4L), dw, nextAddress));
tmpAddress = nextAddress;
}
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMStrdTranslator method translateCore.
@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) throws InternalTranslationException {
final Boolean writeBack = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().size() == 1 ? true : false;
final IOperandTreeNode registerOperand1 = instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().size() == 1 ? instruction.getOperands().get(0).getRootNode().getChildren().get(0).getChildren().get(0) : instruction.getOperands().get(0).getRootNode().getChildren().get(0);
final IOperandTreeNode rootNode = instruction.getOperands().get(1).getRootNode();
final String registerNodeValue = (registerOperand1.getValue());
final OperandSize bt = OperandSize.BYTE;
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 tmpAddress2 = environment.getNextVariableString();
final int registerNum = Helpers.getRegisterIndex(registerNodeValue);
baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
if (((registerNum % 2) == 0) && (registerNum != 14)) {
instructions.add(ReilHelpers.createStm(baseOffset++, dw, registerNodeValue, dw, tmpAddress));
instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpAddress, bt, String.valueOf(4), dw, tmpAddress2));
instructions.add(ReilHelpers.createStm(baseOffset++, dw, "R" + String.valueOf(registerNum + 1), dw, tmpAddress2));
if (writeBack) {
instructions.add(ReilHelpers.createStr(baseOffset++, dw, tmpAddress2, dw, registerNodeValue));
}
} else {
instructions.add(ReilHelpers.createUnknown(baseOffset++));
}
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMStrtTranslator 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();
baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
instructions.add(ReilHelpers.createStm(baseOffset++, dw, registerNodeValue, dw, tmpAddress));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMSubTranslator 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 wd = OperandSize.WORD;
final OperandSize dw = OperandSize.DWORD;
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
final String tmpVar1 = 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();
// final String shifterCarryOut = shifterPair.second();
instructions.add(ReilHelpers.createSub(baseOffset++, dw, sourceRegister, dw, shifterOperand, dw, tmpVar1));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpVar1, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
if (instruction.getMnemonic().endsWith("S")) {
// 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 tmpVar5 = 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 NOT BorrowFrom(Rn - shifter_operand)
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVar1, wd, String.valueOf(-31L), bt, tmpVar4));
instructions.add(ReilHelpers.createAnd(baseOffset++, bt, tmpVar4, bt, String.valueOf(1L), bt, tmpVar5));
instructions.add(ReilHelpers.createBisz(baseOffset++, bt, tmpVar5, bt, "C"));
// V Flag OverflowFrom(Rn - shifter_operand)
Helpers.subOverflow(baseOffset, environment, instruction, instructions, dw, shifterOperand, dw, sourceRegister, dw, tmpVar1, "V", 32);
}
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class ARMSwpTranslator 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).getChildren().get(0);
final String targetRegister = (registerOperand1.getValue());
final String sourceRegister1 = (registerOperand2.getValue());
final String memoryRegister2 = (registerOperand3.getValue());
final OperandSize dw = OperandSize.DWORD;
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
final String negRotVal2 = environment.getNextVariableString();
final String rotVal1 = environment.getNextVariableString();
final String rotVal2 = environment.getNextVariableString();
final String tmpResult = environment.getNextVariableString();
final String tmpRotate1 = environment.getNextVariableString();
final String tmpRotate2 = environment.getNextVariableString();
final String tmpVal1 = environment.getNextVariableString();
// load
instructions.add(ReilHelpers.createLdm(baseOffset++, dw, memoryRegister2, dw, tmpVal1));
// rotate
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, memoryRegister2, dw, String.valueOf(0x3), dw, rotVal1));
instructions.add(ReilHelpers.createMul(baseOffset++, dw, rotVal1, dw, String.valueOf(8), dw, rotVal2));
instructions.add(ReilHelpers.createSub(baseOffset++, dw, String.valueOf(0), dw, rotVal2, dw, negRotVal2));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVal1, dw, negRotVal2, dw, tmpRotate1));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tmpVal1, dw, rotVal2, dw, tmpRotate2));
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tmpRotate1, dw, tmpRotate2, dw, tmpResult));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tmpResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
// store
instructions.add(ReilHelpers.createStm(baseOffset++, dw, sourceRegister1, dw, memoryRegister2));
}
Aggregations