Ejemplo n.º 1
0
 @Before
 public void setUp() {
   interpreter.setRegister("CR0EQ", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
   interpreter.setRegister("CR0LT", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
   interpreter.setRegister("CR0GT", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
   interpreter.setRegister("CR0SO", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
   interpreter.setRegister("XERCA", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
   interpreter.setRegister("XEROV", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
   interpreter.setRegister("XERSO", BigInteger.ZERO, OperandSize.BYTE, ReilRegisterStatus.DEFINED);
 }
Ejemplo n.º 2
0
  @Test
  public void testPushEsp() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister(
        "esp", BigInteger.valueOf(0x12345678), OperandSize.DWORD, ReilRegisterStatus.DEFINED);

    final MockOperandTree operandTree = new MockOperandTree();
    operandTree.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "esp"));

    final List<MockOperandTree> operands = Lists.newArrayList(operandTree);

    final IInstruction instruction = new MockInstruction("push", operands);

    translator.translate(environment, instruction, instructions);

    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));

    assertEquals(BigInteger.valueOf(4L), BigInteger.valueOf(interpreter.getMemorySize()));
    assertEquals(0x12345678, interpreter.readMemoryDword(0x12345674));
    assertEquals(2, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
  }
Ejemplo n.º 3
0
  @Test
  public void testPushL32() throws InternalTranslationException, InterpreterException {
    final MockOperandTree operandTree = new MockOperandTree();
    operandTree.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree.root.m_children.add(
        new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "12345678"));

    final List<MockOperandTree> operands = Lists.newArrayList(operandTree);

    final IInstruction instruction = new MockInstruction("push", operands);

    translator.translate(environment, instruction, instructions);

    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));

    assertEquals(BigInteger.valueOf(0x1FFC), interpreter.getVariableValue("esp"));

    assertEquals(BigInteger.valueOf(4L), BigInteger.valueOf(interpreter.getMemorySize()));
    assertEquals(12345678, interpreter.readMemoryDword(0x1FFC));
    assertEquals(2, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
  }
Ejemplo n.º 4
0
  @Test
  public void testLaOne() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("$v1", BigInteger.ZERO, OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister(
        "$v2", BigInteger.valueOf(0x11223344L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);

    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$v1"));

    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "$v2"));

    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);

    final IInstruction instruction = new MockInstruction("move", operands);

    translator.translate(environment, instruction, instructions);

    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));

    // check correct outcome

    assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(0x11223344L), interpreter.getVariableValue("$v1"));
    assertEquals(BigInteger.valueOf(0x11223344L), interpreter.getVariableValue("$v2"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
  }
Ejemplo n.º 5
0
  @Test
  public void testNegativeToPositive() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister(
        "%r2", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister(
        "%r1", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("%r0", BigInteger.ZERO, OperandSize.DWORD, ReilRegisterStatus.DEFINED);

    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "%r0"));

    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "%r1"));

    final MockOperandTree operandTree3 = new MockOperandTree();
    operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "%r2"));

    final List<MockOperandTree> operands =
        Lists.newArrayList(operandTree1, operandTree2, operandTree3);

    final IInstruction instruction = new MockInstruction("nand", operands);

    translator.translate(environment, instruction, instructions);

    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100L));

    assertEquals(BigInteger.valueOf(0x7FFFFFFFL), interpreter.getVariableValue("%r0"));
    assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("%r1"));
    assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("%r2"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("CR0EQ"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("CR0LT"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("CR0GT"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("CR0SO"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
    assertEquals(8, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
  }
Ejemplo n.º 6
0
 @Before
 public void setUp() {
   interpreter.setRegister(
       "esp", BigInteger.valueOf(0x2000), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
 }
Ejemplo n.º 7
0
  @Test
  public void testLdrEPostIndexedASR() throws InternalTranslationException, InterpreterException {
    // LDRBT r7,[r1],r3, ASR #2

    interpreter.setRegister("R0", BigInteger.valueOf(0x07FFFFDCL), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R1", BigInteger.valueOf(0x00008125L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R2", BigInteger.valueOf(0x00000046L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R3", BigInteger.valueOf(0x00452A02L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R4", BigInteger.valueOf(0x00008124L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R5", BigInteger.valueOf(0x000096A4L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R6", BigInteger.valueOf(0x00000000L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R7", BigInteger.valueOf(0x00000000L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R8", BigInteger.valueOf(0x00000000L), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("R9", BigInteger.valueOf(0x000000FFL), dw, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("C", BigInteger.ONE, bt, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("N", BigInteger.ZERO, bt, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("Z", BigInteger.ONE, bt, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("V", BigInteger.ZERO, bt, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("Q", BigInteger.ZERO, bt, ReilRegisterStatus.DEFINED);
    interpreter.setMemory(0x8125L, 0x74737269L, 4);

    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "R7"));

    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "b4");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.OPERATOR, ","));

    operandTree2
        .root
        .getChildren()
        .get(0)
        .m_children
        .add(new MockOperandTreeNode(ExpressionType.MEMDEREF, "["));
    operandTree2
        .root
        .getChildren()
        .get(0)
        .getChildren()
        .get(0)
        .m_children
        .add(new MockOperandTreeNode(ExpressionType.REGISTER, "R1"));

    operandTree2
        .root
        .getChildren()
        .get(0)
        .m_children
        .add(new MockOperandTreeNode(ExpressionType.OPERATOR, "ASR"));
    operandTree2
        .root
        .getChildren()
        .get(0)
        .getChildren()
        .get(1)
        .m_children
        .add(new MockOperandTreeNode(ExpressionType.REGISTER, "R3"));
    operandTree2
        .root
        .getChildren()
        .get(0)
        .getChildren()
        .get(1)
        .m_children
        .add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, String.valueOf(2)));

    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);

    final IInstruction instruction = new MockInstruction("LDRBT", operands);

    translator.translate(environment, instruction, instructions);

    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100L));

    assertEquals(BigInteger.valueOf(0x07FFFFDCL), interpreter.getVariableValue("R0"));
    assertEquals(BigInteger.valueOf(0x0011CBA5L), interpreter.getVariableValue("R1"));
    assertEquals(BigInteger.valueOf(0x00000046L), interpreter.getVariableValue("R2"));
    assertEquals(BigInteger.valueOf(0x00452A02L), interpreter.getVariableValue("R3"));
    assertEquals(BigInteger.valueOf(0x00008124L), interpreter.getVariableValue("R4"));
    assertEquals(BigInteger.valueOf(0x000096A4L), interpreter.getVariableValue("R5"));
    assertEquals(BigInteger.valueOf(0x00000000L), interpreter.getVariableValue("R6"));
    assertEquals(BigInteger.valueOf(0x00000069L), interpreter.getVariableValue("R7"));
    assertEquals(BigInteger.valueOf(0x00000000L), interpreter.getVariableValue("R8"));
    assertEquals(BigInteger.valueOf(0x000000FFL), interpreter.getVariableValue("R9"));

    assertEquals(BigInteger.ONE, interpreter.getVariableValue("C"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("N"));
    assertEquals(BigInteger.ONE, interpreter.getVariableValue("Z"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("V"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("Q"));

    assertEquals(BigInteger.valueOf(4), BigInteger.valueOf(interpreter.getMemorySize()));
    assertEquals(16, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
  }