Search in sources :

Example 51 with ReilInstruction

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

the class ShldTranslatorTest method testNull.

@Test
public void testNull() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("eax", BigInteger.valueOf(0x2000), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("ebx", BigInteger.valueOf(0xFFFF), 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, "0"));
    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));
    System.out.println(instructions);
    long counter = 0x10000;
    for (final ReilInstruction inst : instructions) {
        assertEquals(counter, inst.getAddress().toLong());
        counter++;
    }
    assertEquals(3, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    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 52 with ReilInstruction

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

the class ShldTranslatorTest method testProperMemory.

@Test
public void testProperMemory() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("ebx", BigInteger.valueOf(0x80000000L), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setMemory(100, 0xF0, 4);
    final MockOperandTree operandTree1 = new MockOperandTree();
    operandTree1.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.MEMDEREF, "["));
    operandTree1.root.m_children.get(0).m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "100"));
    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, "2"));
    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));
    System.out.println(instructions);
    long counter = 0x10000;
    for (final ReilInstruction inst : instructions) {
        assertEquals(counter, inst.getAddress().toLong());
        counter++;
    }
    assertEquals(5, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(0x3C2, interpreter.getMemory().load(100, 4));
    assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
    assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.ZERO_FLAG));
    assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.CARRY_FLAG));
    assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.SIGN_FLAG));
    assertEquals(BigInteger.valueOf(4L), BigInteger.valueOf(interpreter.getMemorySize()));
    assertEquals(BigInteger.valueOf(4L), 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 53 with ReilInstruction

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

the class ShldTranslatorTest method testTooLarge.

@Test
public void testTooLarge() 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, "word");
    operandTree1.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "ax"));
    final MockOperandTree operandTree2 = new MockOperandTree();
    operandTree2.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "word");
    operandTree2.root.m_children.add(new MockOperandTreeNode(ExpressionType.REGISTER, "bx"));
    final MockOperandTree operandTree3 = new MockOperandTree();
    operandTree3.root = new MockOperandTreeNode(ExpressionType.SIZE_PREFIX, "dword");
    operandTree3.root.m_children.add(new MockOperandTreeNode(ExpressionType.IMMEDIATE_INTEGER, "17"));
    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));
    System.out.println(instructions);
    long counter = 0x10000;
    for (final ReilInstruction inst : instructions) {
        assertEquals(counter, inst.getAddress().toLong());
        counter++;
    }
    assertEquals(2, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    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 54 with ReilInstruction

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

the class ShldTranslatorTest method testProper.

@Test
public void testProper() 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, "2"));
    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));
    System.out.println(instructions);
    long counter = 0x10000;
    for (final ReilInstruction inst : instructions) {
        assertEquals(counter, inst.getAddress().toLong());
        counter++;
    }
    assertEquals(6, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
    assertEquals(BigInteger.valueOf(2L), interpreter.getVariableValue("eax"));
    assertEquals(BigInteger.valueOf(0x80000000L), interpreter.getVariableValue("ebx"));
    assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.ZERO_FLAG));
    assertEquals(BigInteger.valueOf(0L), interpreter.getVariableValue(Helpers.CARRY_FLAG));
    assertEquals(BigInteger.valueOf(0), 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)

Example 55 with ReilInstruction

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

the class StateCombiner method combine.

private static ValueTrackerElement combine(final ValueTrackerElement state1, final ValueTrackerElement state2) {
    final Map<IAloc, IValueElement> values1 = state1.getStates();
    final Map<IAloc, IValueElement> values2 = state2.getStates();
    final Map<IAloc, IValueElement> combinedState = new HashMap<IAloc, IValueElement>();
    final Set<ReilInstruction> combinedInfluences = state1.getInfluences();
    combinedInfluences.addAll(state2.getInfluences());
    final Map<String, Set<IAddress>> combinedWritten = new HashMap<String, Set<IAddress>>();
    combinedWritten.putAll(state1.getLastWritten());
    for (final Map.Entry<String, Set<IAddress>> lastWritten : state2.getLastWritten().entrySet()) {
        if (combinedWritten.containsKey(lastWritten.getKey())) {
            combinedWritten.get(lastWritten.getKey()).addAll(lastWritten.getValue());
        } else {
            combinedWritten.put(lastWritten.getKey(), new HashSet<IAddress>(lastWritten.getValue()));
        }
    }
    for (final Map.Entry<IAloc, IValueElement> entry : values1.entrySet()) {
        final IAloc aloc = entry.getKey();
        if (values2.containsKey(aloc)) {
            final IValueElement lhs = entry.getValue();
            final IValueElement rhs = values2.get(aloc);
            combinedState.put(aloc, combine(lhs, rhs));
        } else {
            combinedState.put(aloc, new Undefined());
        }
    }
    for (final Map.Entry<IAloc, IValueElement> entry : values2.entrySet()) {
        final IAloc aloc = entry.getKey();
        if (!values1.containsKey(aloc)) {
            combinedState.put(aloc, new Undefined());
        }
    }
    if ((combinedState.size() < state1.getStates().size()) || (combinedState.size() < state2.getStates().size())) {
        throw new IllegalStateException();
    }
    return new ValueTrackerElement(combinedInfluences, combinedState, combinedWritten);
}
Also used : Undefined(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.Undefined) ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ValueTrackerElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.ValueTrackerElement) IAloc(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IAloc) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) IValueElement(com.google.security.zynamics.reil.algorithms.mono.valuetracking.elements.IValueElement) HashMap(java.util.HashMap) Map(java.util.Map)

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