Search in sources :

Example 26 with Address

use of com.google.security.zynamics.binnavi.API.disassembly.Address 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)

Example 27 with Address

use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.

the class InstructionGraphTest method testRemoveEdge.

@Test
public void testRemoveEdge() {
    final List<InstructionGraphNode> nodes = new ArrayList<InstructionGraphNode>();
    final List<InstructionGraphEdge> edges = new ArrayList<InstructionGraphEdge>();
    final InstructionGraphNode node1 = new InstructionGraphNode(new ReilInstruction(new Address(0), "nop", ReilOperand.EMPTY_OPERAND, ReilOperand.EMPTY_OPERAND, ReilOperand.EMPTY_OPERAND));
    final InstructionGraphNode node2 = new InstructionGraphNode(new ReilInstruction(new Address(1), "nop", ReilOperand.EMPTY_OPERAND, ReilOperand.EMPTY_OPERAND, ReilOperand.EMPTY_OPERAND));
    final InstructionGraphEdge edge1 = new InstructionGraphEdge(node1, node2, EdgeType.JumpUnconditional);
    InstructionGraphNode.link(node1, node2, edge1);
    nodes.add(node1);
    nodes.add(node2);
    edges.add(edge1);
    final InstructionGraph graph = new InstructionGraph(nodes, edges);
    assertEquals(graph.edgeCount(), 1);
    assertEquals(1, node2.getParents().size());
    assertEquals(1, node1.getChildren().size());
    graph.removeEdge(edge1);
    InstructionGraphNode.unlink(node1, node2, edge1);
    assertEquals(0, node2.getParents().size());
    assertEquals(0, node1.getChildren().size());
}
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) ArrayList(java.util.ArrayList) InstructionGraph(com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraph) InstructionGraphNode(com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraphNode) Test(org.junit.Test)

Example 28 with Address

use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.

the class DebuggerTest method testRelocation1.

@Test
public void testRelocation1() {
    final INaviModule nativeModule = new MockModule();
    mockDebugger.setAddressTranslator(nativeModule, new CAddress(100), new CAddress(200));
    final Module module = ModuleFactory.get(nativeModule);
    assertEquals(250, debugger.toImagebase(module, new Address(150)).toLong());
    assertEquals(150, debugger.toFilebase(module, new Address(250)).toLong());
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 29 with Address

use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.

the class DebuggerTest method testReadMemory2.

@Test
public void testReadMemory2() throws DebugException {
    debugger.connect();
    debugger.readMemory(new Address(0), 0x100);
    assertEquals("CONNECT;READMEM/00000000/256;", mockDebugger.requests);
}
Also used : RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) Test(org.junit.Test)

Example 30 with Address

use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.

the class DebuggerTest method writeMemory4.

@Test
public void writeMemory4() throws DebugException {
    debugger.connect();
    debugger.writeMemory(new Address(0), new byte[10]);
}
Also used : RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) Test(org.junit.Test)

Aggregations

Address (com.google.security.zynamics.binnavi.API.disassembly.Address)44 Test (org.junit.Test)32 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)30 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)19 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)17 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)7 Trace (com.google.security.zynamics.binnavi.API.disassembly.Trace)5 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)5 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)4 TracePoint (com.google.security.zynamics.binnavi.API.disassembly.TracePoint)4 ArrayList (java.util.ArrayList)4 MemoryModule (com.google.security.zynamics.binnavi.API.debug.MemoryModule)3 ReilInstruction (com.google.security.zynamics.binnavi.API.reil.ReilInstruction)2 InstructionGraph (com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraph)2 InstructionGraphEdge (com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraphEdge)2 InstructionGraphNode (com.google.security.zynamics.binnavi.API.reil.mono.InstructionGraphNode)2 EchoBreakpointHitReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply)2 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)2 RegisterValues (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues)2 ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)2