Search in sources :

Example 46 with ReilInstruction

use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.

the class BsfTranslatorTest method testInputZero.

@Test
public void testInputZero() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("eax", BigInteger.valueOf(0xFFFFFFFFL), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("ebx", BigInteger.valueOf(0x00000000L), 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, "eax"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ebx"));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);
    final IInstruction instruction = new MockInstruction("bsf", operands);
    translator.translate(environment, instruction, instructions);
    for (final ReilInstruction mockOperandTree : instructions) {
        System.out.println(mockOperandTree);
    }
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(0x00000000L), interpreter.getVariableValue("ebx"));
    assertEquals(BigInteger.valueOf(0x00000001L), interpreter.getVariableValue("ZF"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Example 47 with ReilInstruction

use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.

the class BsfTranslatorTest method testLast.

@Test
public void testLast() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("eax", BigInteger.valueOf(0xFFFFFFFFL), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), 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, "eax"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ebx"));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);
    final IInstruction instruction = new MockInstruction("bsf", operands);
    translator.translate(environment, instruction, instructions);
    for (final ReilInstruction mockOperandTree : instructions) {
        System.out.println(mockOperandTree);
    }
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    assertEquals(4, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(31), interpreter.getVariableValue("eax"));
    assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Example 48 with ReilInstruction

use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.

the class BsrTranslatorTest method testFirst.

@Test
public void testFirst() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("eax", BigInteger.valueOf(0xFFFFFFFFL), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), 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, "eax"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ebx"));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2);
    final IInstruction instruction = new MockInstruction("bsr", operands);
    translator.translate(environment, instruction, instructions);
    for (final ReilInstruction mockOperandTree : instructions) {
        System.out.println(mockOperandTree);
    }
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    assertEquals(4, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(31), interpreter.getVariableValue("eax"));
    assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Example 49 with ReilInstruction

use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.

the class LoopeTranslatorTest method testSimple.

@Test
public void testSimple() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("eax", BigInteger.valueOf(3), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("ecx", BigInteger.valueOf(5), 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, "eax"));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1);
    final IInstruction instruction = new MockInstruction("dec", operands);
    final ArrayList<ReilInstruction> instructionsDec = new ArrayList<ReilInstruction>();
    decTranslator.translate(environment, instruction, instructionsDec);
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "256"));
    final MockInstruction instruction2 = new MockInstruction("loope", Lists.newArrayList(operandTree2));
    instruction2.address = new CAddress(0x101);
    translator.translate(environment, instruction2, instructions);
    final HashMap<BigInteger, List<ReilInstruction>> mapping = new HashMap<BigInteger, List<ReilInstruction>>();
    mapping.put(BigInteger.valueOf(instructions.get(0).getAddress().toLong()), instructions);
    mapping.put(BigInteger.valueOf(instructionsDec.get(0).getAddress().toLong()), instructionsDec);
    interpreter.interpret(mapping, BigInteger.valueOf(0x100));
    assertEquals(6, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(2), interpreter.getVariableValue("eax"));
    assertEquals(BigInteger.valueOf(4), interpreter.getVariableValue("ecx"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("ZF"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("SF"));
    assertEquals(BigInteger.ZERO, interpreter.getVariableValue("OF"));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 50 with ReilInstruction

use of com.google.security.zynamics.reil.ReilInstruction in project binnavi by google.

the class ShldTranslatorTest method testOne.

@Test
public void testOne() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("eax", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), 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.IMMEDIATE_INTEGER, "eax"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "ebx"));
    final MockOperandTree operandTree3 = new MockOperandTree();
    operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "1"));
    final List<MockOperandTree> operands = Lists.newArrayList(operandTree1, operandTree2, operandTree3);
    final IInstruction instruction = new MockInstruction("shld", operands);
    translator.translate(environment, instruction, instructions);
    interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
    long counter = 0x10000;
    for (final ReilInstruction inst : instructions) {
        assertEquals(counter, inst.getAddress().toLong());
        counter++;
    }
    assertEquals(7, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(1L), interpreter.getVariableValue("eax"));
    assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
    assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.ZERO_FLAG));
    assertEquals(BigInteger.valueOf(1L), interpreter.getVariableValue(Helpers.OVERFLOW_FLAG));
    assertEquals(BigInteger.valueOf(1L), interpreter.getVariableValue(Helpers.CARRY_FLAG));
    assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.SIGN_FLAG));
    assertEquals(BigInteger.ZERO, BigInteger.valueOf(interpreter.getMemorySize()));
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) MockOperandTreeNode(com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode) MockInstruction(com.google.security.zynamics.zylib.disassembly.MockInstruction) MockOperandTree(com.google.security.zynamics.zylib.disassembly.MockOperandTree) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) Test(org.junit.Test)

Aggregations

ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)144 Test (org.junit.Test)102 TreeSet (java.util.TreeSet)73 ArrayList (java.util.ArrayList)35 IInstruction (com.google.security.zynamics.zylib.disassembly.IInstruction)18 OperandSize (com.google.security.zynamics.reil.OperandSize)16 ReilBlock (com.google.security.zynamics.reil.ReilBlock)16 MockInstruction (com.google.security.zynamics.zylib.disassembly.MockInstruction)16 MockOperandTree (com.google.security.zynamics.zylib.disassembly.MockOperandTree)16 MockOperandTreeNode (com.google.security.zynamics.zylib.disassembly.MockOperandTreeNode)16 ReilEdge (com.google.security.zynamics.reil.ReilEdge)12 HashMap (java.util.HashMap)12 TranslationResult (com.google.security.zynamics.reil.translators.TranslationResult)9 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)7 List (java.util.List)7 ReilGraph (com.google.security.zynamics.reil.ReilGraph)6 InternalTranslationException (com.google.security.zynamics.reil.translators.InternalTranslationException)6 BigInteger (java.math.BigInteger)6 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)5 ValueTrackerElement (com.google.security.zynamics.reil.algorithms.mono.valuetracking.ValueTrackerElement)5