Search in sources :

Example 41 with ReilInstruction

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

the class BackwardRegisterTrackingTransformationProviderTest method testTransformUndef.

@Test
public void testTransformUndef() {
    final RegisterTrackingTransformationProvider transformationProvider = new RegisterTrackingTransformationProvider(new RegisterTrackingOptions(false, new TreeSet<String>(), false, AnalysisDirection.UP));
    final ReilInstruction instruction = ReilHelpers.createUndef(0, OperandSize.DWORD, "eax");
    final Pair<RegisterSetLatticeElement, RegisterSetLatticeElement> transformationResult = transformationProvider.transformUndef(instruction, createTaintedState("eax"));
    Assert.assertNull(transformationResult.second());
    transformationResult.first().onInstructionExit();
    Assert.assertTrue(transformationResult.first().getTaintedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getReadRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getUntaintedRegisters().contains("eax"));
    Assert.assertTrue(transformationResult.first().getNewlyTaintedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getUpdatedRegisters().isEmpty());
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 42 with ReilInstruction

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

the class BackwardRegisterTrackingTransformationProviderTest method testTransformMulFirstZero.

@Test
public void testTransformMulFirstZero() {
    final RegisterTrackingTransformationProvider transformationProvider = new RegisterTrackingTransformationProvider(new RegisterTrackingOptions(false, new TreeSet<String>(), false, AnalysisDirection.UP));
    final ReilInstruction instruction = ReilHelpers.createMul(0, OperandSize.DWORD, "ecx", OperandSize.DWORD, String.valueOf("0"), OperandSize.DWORD, "eax");
    final Pair<RegisterSetLatticeElement, RegisterSetLatticeElement> transformationResult = transformationProvider.transformMul(instruction, createTaintedState("eax"));
    Assert.assertNull(transformationResult.second());
    transformationResult.first().onInstructionExit();
    Assert.assertTrue(transformationResult.first().getTaintedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getReadRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getNewlyTaintedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getUpdatedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getUntaintedRegisters().contains("eax"));
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 43 with ReilInstruction

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

the class BackwardRegisterTrackingTransformationProviderTest method testTransformMulSecondZero.

@Test
public void testTransformMulSecondZero() {
    final RegisterTrackingTransformationProvider transformationProvider = new RegisterTrackingTransformationProvider(new RegisterTrackingOptions(false, new TreeSet<String>(), false, AnalysisDirection.UP));
    final ReilInstruction instruction = ReilHelpers.createMul(0, OperandSize.DWORD, String.valueOf("0"), OperandSize.DWORD, "ecx", OperandSize.DWORD, "eax");
    final Pair<RegisterSetLatticeElement, RegisterSetLatticeElement> transformationResult = transformationProvider.transformMul(instruction, createTaintedState("eax"));
    Assert.assertNull(transformationResult.second());
    transformationResult.first().onInstructionExit();
    Assert.assertTrue(transformationResult.first().getTaintedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getReadRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getNewlyTaintedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getUpdatedRegisters().isEmpty());
    Assert.assertTrue(transformationResult.first().getUntaintedRegisters().contains("eax"));
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 44 with ReilInstruction

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

the class BackwardRegisterTrackingTransformationProviderTest method testTransformAddEmptyState.

@Test
public void testTransformAddEmptyState() {
    final RegisterTrackingTransformationProvider transformationProvider = new RegisterTrackingTransformationProvider(new RegisterTrackingOptions(false, new TreeSet<String>(), false, AnalysisDirection.UP));
    final ReilInstruction instruction = ReilHelpers.createAdd(0, OperandSize.DWORD, "eax", OperandSize.DWORD, "ebx", OperandSize.DWORD, "ecx");
    final Pair<RegisterSetLatticeElement, RegisterSetLatticeElement> transformationResult = transformationProvider.transformAdd(instruction, new RegisterSetLatticeElement());
    Assert.assertNull(transformationResult.second());
    Assert.assertTrue(transformationResult.first().getTaintedRegisters().isEmpty());
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 45 with ReilInstruction

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

the class BsfTranslatorTest method testSecond.

@Test
public void testSecond() throws InternalTranslationException, InterpreterException {
    interpreter.setRegister("eax", BigInteger.valueOf(0xFFFFFFFFL), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
    interpreter.setRegister("ebx", BigInteger.valueOf(0x00000002L), 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(1), interpreter.getVariableValue("eax"));
    assertEquals(BigInteger.valueOf(0x00000002L), 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)

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