use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class Helpers method reverseUnsignedInteger.
public static String reverseUnsignedInteger(final ITranslationEnvironment environment, final long offset, final String inputRegister, final List<ReilInstruction> instructions) {
/**
* x = (x & 0x55555555) << 1 | (x >> 1) & 0x55555555 x = (x & 0x33333333) << 2 | (x >> 2) &
* 0x33333333 x = (x & 0x0F0F0F0F) << 4 | (x >> 4) & 0x0F0F0F0F x = (x << 24) | ((x & 0xFF00 )
* << 8) | ((x >> 8) & 0xFF00 | (x >> 24)
*/
long baseOffset = offset;
final OperandSize dw = OperandSize.DWORD;
final String tempVar10 = environment.getNextVariableString();
final String tempVar11 = environment.getNextVariableString();
final String tempVar12 = environment.getNextVariableString();
final String tempVar13 = environment.getNextVariableString();
final String tempVar1x = environment.getNextVariableString();
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, inputRegister, dw, String.valueOf(0x55555555L), dw, tempVar10));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar10, dw, String.valueOf(1L), dw, tempVar11));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, inputRegister, dw, String.valueOf(-1L), dw, tempVar12));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tempVar12, dw, String.valueOf(0x55555555L), dw, tempVar13));
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tempVar11, dw, tempVar13, dw, tempVar1x));
final String tempVar20 = environment.getNextVariableString();
final String tempVar21 = environment.getNextVariableString();
final String tempVar22 = environment.getNextVariableString();
final String tempVar23 = environment.getNextVariableString();
final String tempVar2x = environment.getNextVariableString();
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tempVar1x, dw, String.valueOf(0x33333333L), dw, tempVar20));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar20, dw, String.valueOf(2L), dw, tempVar21));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar1x, dw, String.valueOf(-2L), dw, tempVar22));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tempVar22, dw, String.valueOf(0x33333333L), dw, tempVar23));
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tempVar21, dw, tempVar23, dw, tempVar2x));
final String tempVar30 = environment.getNextVariableString();
final String tempVar31 = environment.getNextVariableString();
final String tempVar32 = environment.getNextVariableString();
final String tempVar33 = environment.getNextVariableString();
final String tempVar3x = environment.getNextVariableString();
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tempVar2x, dw, String.valueOf(0x0F0F0F0FL), dw, tempVar30));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar30, dw, String.valueOf(4L), dw, tempVar31));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar2x, dw, String.valueOf(-4L), dw, tempVar32));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tempVar32, dw, String.valueOf(0x0F0F0F0FL), dw, tempVar33));
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tempVar31, dw, tempVar33, dw, tempVar3x));
final String tempVar40 = environment.getNextVariableString();
final String tempVar41 = environment.getNextVariableString();
final String tempVar42 = environment.getNextVariableString();
final String tempVar4x = environment.getNextVariableString();
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar3x, dw, String.valueOf(24), dw, tempVar40));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tempVar3x, dw, String.valueOf(0xFF00L), dw, tempVar41));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar41, dw, String.valueOf(8L), dw, tempVar42));
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tempVar42, dw, tempVar40, dw, tempVar4x));
final String tempVar50 = environment.getNextVariableString();
final String tempVar51 = environment.getNextVariableString();
final String tempVar52 = environment.getNextVariableString();
final String tempVar5x = environment.getNextVariableString();
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar3x, dw, String.valueOf(-8L), dw, tempVar50));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, tempVar50, dw, String.valueOf(0xFF00L), dw, tempVar51));
instructions.add(ReilHelpers.createBsh(baseOffset++, dw, tempVar3x, dw, String.valueOf(-24L), dw, tempVar52));
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tempVar51, dw, tempVar52, dw, tempVar5x));
final String result = environment.getNextVariableString();
instructions.add(ReilHelpers.createOr(baseOffset++, dw, tempVar4x, dw, tempVar5x, dw, result));
return result;
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class THUMB2CbnzTranslator 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 labelOperand1 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
final String sourceRegister1 = (registerOperand1.getValue());
final String realJumpLabel = (labelOperand1.getValue());
final OperandSize dw = OperandSize.DWORD;
long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
final String jmpGoal = String.format("%d.%d", instruction.getAddress().toLong(), 3);
final String jumpCondition = environment.getNextVariableString();
instructions.add(ReilHelpers.createBisz(baseOffset++, dw, sourceRegister1, dw, jumpCondition));
instructions.add(ReilHelpers.createJcc(baseOffset++, dw, jumpCondition, dw, jmpGoal));
instructions.add(ReilHelpers.createJcc(baseOffset++, dw, String.valueOf(1), dw, realJumpLabel));
instructions.add(ReilHelpers.createNop(baseOffset++));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class THUMB2LDRDTranslator 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);
final IOperandTreeNode registerOperand2 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
final IOperandTreeNode rootNode = instruction.getOperands().get(2).getRootNode();
final String registerNodeValue1 = registerOperand1.getValue();
final String registerNodeValue2 = registerOperand2.getValue();
final OperandSize bt = OperandSize.BYTE;
final OperandSize dw = OperandSize.DWORD;
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
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(registerNodeValue1);
if (((registerNum % 2) == 0) && (registerNum != 14)) {
instructions.add(ReilHelpers.createLdm(baseOffset++, dw, tmpAddress, dw, registerNodeValue1));
instructions.add(ReilHelpers.createAdd(baseOffset++, dw, tmpAddress, bt, String.valueOf(4), dw, tmpAddress2));
instructions.add(ReilHelpers.createLdm(baseOffset++, dw, tmpAddress2, dw, registerNodeValue2));
if (writeBack) {
instructions.add(ReilHelpers.createStr(baseOffset++, dw, tmpAddress2, dw, registerNodeValue1));
}
} else {
instructions.add(ReilHelpers.createUnknown(baseOffset++));
}
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class THUMB2MlsTranslator method translateCore.
/**
* MLS<c><q><Rd>, <Rn>, <Rm>, <Ra> if ConditionPassed() then EncodingSpecificOperations();
* operand1 = SInt(R[n]); // operand1 = UInt(R[n]) produces the same final results operand2 =
* SInt(R[m]); // operand2 = UInt(R[m]) produces the same final results addend = SInt(R[a]); //
* addend = UInt(R[a]) produces the same final results result = addend - operand1 * operand2; R[d]
* = result<31:0>;
*/
@Override
protected void translateCore(final ITranslationEnvironment environment, final IInstruction instruction, final List<ReilInstruction> instructions) {
final OperandSize qw = OperandSize.QWORD;
final OperandSize dw = OperandSize.DWORD;
long baseOffset = ReilHelpers.nextReilAddress(instruction, instructions);
final IOperandTreeNode targetOperand = instruction.getOperands().get(0).getRootNode().getChildren().get(0);
final IOperandTreeNode sourceOperand1 = instruction.getOperands().get(1).getRootNode().getChildren().get(0);
final IOperandTreeNode sourceOperand2 = instruction.getOperands().get(2).getRootNode().getChildren().get(0);
final IOperandTreeNode sourceOperand3 = instruction.getOperands().get(3).getRootNode().getChildren().get(0);
final String targetRegister = targetOperand.getValue();
final String sourceRegister1 = sourceOperand1.getValue();
final String sourceRegister2 = sourceOperand2.getValue();
final String sourceRegister3 = sourceOperand3.getValue();
final String multiplicationResult = environment.getNextVariableString();
final String subtractionResult = environment.getNextVariableString();
instructions.add(ReilHelpers.createMul(baseOffset++, dw, sourceRegister1, dw, sourceRegister2, qw, multiplicationResult));
instructions.add(ReilHelpers.createSub(baseOffset++, dw, sourceRegister3, qw, multiplicationResult, qw, subtractionResult));
instructions.add(ReilHelpers.createAnd(baseOffset++, qw, subtractionResult, dw, String.valueOf(0xFFFFFFFFL), dw, targetRegister));
}
use of com.google.security.zynamics.reil.OperandSize in project binnavi by google.
the class THUMBBxTranslator 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 String sourceRegister1 = (registerOperand1.getValue());
final OperandSize bt = OperandSize.BYTE;
final OperandSize dw = OperandSize.DWORD;
long baseOffset = (instruction.getAddress().toLong() * 0x100) + instructions.size();
final String tmpVar1 = environment.getNextVariableString();
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, bt, String.valueOf(1L), bt, "T"));
instructions.add(ReilHelpers.createAnd(baseOffset++, dw, sourceRegister1, dw, String.valueOf(0xFFFFFFFEL), dw, tmpVar1));
instructions.add(ReilHelpers.createJcc(baseOffset++, dw, String.valueOf(1), dw, tmpVar1));
}
Aggregations