Search in sources :

Example 1 with ReilOperand

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

the class ReilOperandTest method testAddressSize.

@Test
public void testAddressSize() {
    // Motivated by Case 1415
    final ReilOperand operand = new ReilOperand(OperandSize.OPERAND_SIZE_ADDRESS, "100.200");
    assertEquals(OperandSize.OPERAND_SIZE_ADDRESS, operand.getSize());
}
Also used : ReilOperand(com.google.security.zynamics.binnavi.API.reil.ReilOperand) Test(org.junit.Test)

Example 2 with ReilOperand

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

the class GraphAlgorithmsTest method testDominatorTree.

@Test
public void testDominatorTree() throws MalformedGraphException {
    final InstructionGraphNode node1 = new InstructionGraphNode(new ReilInstruction(new Address(0x100), "nop", new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, "")));
    final InstructionGraphNode node2 = new InstructionGraphNode(new ReilInstruction(new Address(0x100), "nop", new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, "")));
    final InstructionGraphNode node3 = new InstructionGraphNode(new ReilInstruction(new Address(0x100), "nop", new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, "")));
    final InstructionGraphNode node4 = new InstructionGraphNode(new ReilInstruction(new Address(0x100), "nop", new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, "")));
    final InstructionGraphNode node5 = new InstructionGraphNode(new ReilInstruction(new Address(0x100), "nop", new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, ""), new ReilOperand(OperandSize.OPERAND_SIZE_EMPTY, "")));
    final List<InstructionGraphNode> nodes = Lists.newArrayList(node1, node2, node3, node4, node5);
    final InstructionGraphEdge edge1 = new InstructionGraphEdge(node1, node2, EdgeType.JumpUnconditional);
    final InstructionGraphEdge edge2 = new InstructionGraphEdge(node1, node3, EdgeType.JumpUnconditional);
    final InstructionGraphEdge edge3 = new InstructionGraphEdge(node2, node4, EdgeType.JumpUnconditional);
    final InstructionGraphEdge edge4 = new InstructionGraphEdge(node3, node4, EdgeType.JumpUnconditional);
    final InstructionGraphEdge edge5 = new InstructionGraphEdge(node4, node5, EdgeType.JumpUnconditional);
    InstructionGraphNode.link(node1, node2, edge1);
    InstructionGraphNode.link(node1, node3, edge2);
    InstructionGraphNode.link(node2, node4, edge3);
    InstructionGraphNode.link(node3, node4, edge4);
    InstructionGraphNode.link(node4, node5, edge5);
    final List<InstructionGraphEdge> edges = Lists.newArrayList(edge1, edge2, edge3, edge4, edge5);
    final InstructionGraph graph = new InstructionGraph(nodes, edges);
    final Tree<InstructionGraphNode> tree = GraphAlgorithms.getDominatorTree(graph, node1, null);
    assertEquals(node1, tree.getRootNode().getObject());
    assertEquals(3, tree.getRootNode().getChildren().size());
    final TreeNode<InstructionGraphNode> firstChild = tree.getRootNode().getChildren().get(0);
    final TreeNode<InstructionGraphNode> secondChild = tree.getRootNode().getChildren().get(1);
    final TreeNode<InstructionGraphNode> thirdChild = tree.getRootNode().getChildren().get(2);
    // All children are different
    assertTrue(firstChild.getObject() != secondChild.getObject());
    assertTrue(firstChild.getObject() != thirdChild.getObject());
    assertTrue(secondChild.getObject() != thirdChild.getObject());
    assertTrue((firstChild.getObject() == node4) || (firstChild.getChildren().size() == 0));
    assertTrue((firstChild.getObject() == node2) || (firstChild.getObject() == node3) || ((firstChild.getChildren().size() == 1) && (firstChild.getChildren().get(0).getObject() == node5)));
    assertTrue((secondChild.getObject() == node4) || (secondChild.getChildren().size() == 0));
    assertTrue((secondChild.getObject() == node2) || (secondChild.getObject() == node3) || ((secondChild.getChildren().size() == 1) && (secondChild.getChildren().get(0).getObject() == node5)));
    assertTrue((thirdChild.getObject() == node4) || (thirdChild.getChildren().size() == 0));
    assertTrue((thirdChild.getObject() == node2) || (thirdChild.getObject() == node3) || ((thirdChild.getChildren().size() == 1) && (thirdChild.getChildren().get(0).getObject() == node5)));
}
Also used : ReilInstruction(com.google.security.zynamics.binnavi.API.reil.ReilInstruction) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) InstructionGraphEdge(com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraphEdge) ReilOperand(com.google.security.zynamics.binnavi.API.reil.ReilOperand) InstructionGraph(com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraph) InstructionGraphNode(com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraphNode) Test(org.junit.Test)

Aggregations

ReilOperand (com.google.security.zynamics.binnavi.API.reil.ReilOperand)2 Test (org.junit.Test)2 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)1 ReilInstruction (com.google.security.zynamics.binnavi.API.reil.ReilInstruction)1 InstructionGraph (com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraph)1 InstructionGraphEdge (com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraphEdge)1 InstructionGraphNode (com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraphNode)1