Search in sources :

Example 1 with COperandTreeNode

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

the class CModuleTest method testCreateOperand.

@Test
public void testCreateOperand() throws CouldntLoadDataException, LoadCancelledException {
    m_module.load();
    final List<IReference> references = new ArrayList<IReference>();
    final COperandTreeNode node = new COperandTreeNode(1, 2, "2", new CStringReplacement("bar"), references, m_sql, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    assertNotNull(m_module.createOperand(node));
}
Also used : COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) ArrayList(java.util.ArrayList) CStringReplacement(com.google.security.zynamics.binnavi.disassembly.CStringReplacement) IReference(com.google.security.zynamics.zylib.disassembly.IReference) Test(org.junit.Test)

Example 2 with COperandTreeNode

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

the class ZyGraphFactory method generateTestGraph.

public static ZyGraph generateTestGraph() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final MockDatabase database = new MockDatabase();
    final SQLProvider provider = new MockSqlProvider();
    final CModule module = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
    settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
    database.getContent().addModule(module);
    final MockDatabaseManager manager = new MockDatabaseManager();
    manager.addDatabase(database);
    module.load();
    final CView m_view = module.getContent().getViewContainer().createView("name", "description");
    final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
    final ZyGraph2DView g2dView = new ZyGraph2DView();
    final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
    final Node node1 = g2dView.getGraph2D().createNode();
    final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode1, childNode1);
    final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode2, childNode2);
    final COperandTree operand1 = new COperandTree(rootNode1, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final ArrayList<COperandTree> operands1 = Lists.newArrayList(operand1, operand2);
    final List<INaviInstruction> instructions1 = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", operands1, null, module));
    final INaviCodeNode rawNode1 = m_view.getContent().createCodeNode(null, instructions1);
    final ZyLabelContent content = ZyCodeNodeBuilder.buildContent(rawNode1, settings, null);
    nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(content), rawNode1));
    final Node node2 = g2dView.getGraph2D().createNode();
    final List<INaviInstruction> instructions2 = Lists.newArrayList((INaviInstruction) new MockInstruction());
    final INaviCodeNode rawNode2 = m_view.getContent().createCodeNode(null, instructions2);
    final ZyLabelContent content2 = ZyCodeNodeBuilder.buildContent(rawNode2, settings, null);
    nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(content2), rawNode2));
    rawNode2.setColor(Color.RED);
    rawNode2.setVisible(false);
    final CTag tag = new CTag(0, "Tag", "Description", TagType.NODE_TAG, new MockSqlProvider());
    rawNode2.tagNode(tag);
    final Node node3 = g2dView.getGraph2D().createNode();
    final String mnemonicName = "call";
    final List<COperandTree> operandTrees = new ArrayList<COperandTree>();
    final int type = ExpressionType.REGISTER.ordinal();
    final CReference reference = new CReference(new CAddress(0x123), ReferenceType.CALL_DIRECT);
    final List<IReference> referencea = new ArrayList<IReference>();
    referencea.add(reference);
    final COperandTreeNode root = new COperandTreeNode(0, type, "eax", null, referencea, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTree operandTree = new COperandTree(root, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    operandTrees.add(0, operandTree);
    final List<INaviInstruction> instructions3 = Lists.newArrayList((INaviInstruction) new MockInstruction(mnemonicName, operandTrees, m_globalComment));
    final INaviCodeNode rawNode3 = m_view.getContent().createCodeNode(null, instructions3);
    final ZyLabelContent content3 = ZyCodeNodeBuilder.buildContent(rawNode3, settings, null);
    nodeMap.put(node3, new NaviNode(node3, new ZyNormalNodeRealizer<NaviNode>(content3), rawNode3));
    final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
    final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, EdgeType.JUMP_UNCONDITIONAL);
    edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
    final Edge edge2 = g2dView.getGraph2D().createEdge(node2, node3);
    final INaviEdge rawEdge2 = m_view.getContent().createEdge(rawNode2, rawNode3, EdgeType.JUMP_UNCONDITIONAL);
    edgeMap.put(edge2, new NaviEdge(nodeMap.get(node2), nodeMap.get(node3), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge2));
    return new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
}
Also used : CallGraphSettingsConfigItem(com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) Node(y.base.Node) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) CReference(com.google.security.zynamics.binnavi.disassembly.CReference) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) LinkedHashMap(java.util.LinkedHashMap) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) ZyGraph2DView(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) Date(java.util.Date) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) MockDatabaseManager(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabaseManager) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 3 with COperandTreeNode

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

the class BreakpointHelpersTest method setUp.

@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
    final Database apiDatabase = new Database(database);
    final SQLProvider mockProvider = new MockSqlProvider();
    final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
    final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
    final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
    final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
    final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
    final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
    m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
    m_module.load();
    m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
    m_mockDebugger.connect();
    m_debugger = new Debugger(m_mockDebugger);
    final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
    m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
    final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
    final INaviView naviView = new MockView(mockProvider);
    final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
    final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
    final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
    m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
    m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
    setM_functionNode(m_view.createFunctionNode(apiFunction));
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) ViewContainer(com.google.security.zynamics.binnavi.API.disassembly.ViewContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Function(com.google.security.zynamics.binnavi.API.disassembly.Function) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) View(com.google.security.zynamics.binnavi.API.disassembly.View) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 4 with COperandTreeNode

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

the class OperandTest method testConstructor.

@Test
public void testConstructor() {
    final MockModule mockModule = new MockModule();
    final COperandTreeNode rootNode = new COperandTreeNode(1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode, childNode);
    final COperandTree tree = new COperandTree(rootNode, new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final Operand operand = new Operand(tree);
    assertEquals("dword", operand.getRootNode().getValue());
    assertEquals(1, operand.getRootNode().getChildren().size());
    assertEquals("eax", operand.getRootNode().getChildren().get(0).getValue());
    assertEquals("eax", operand.toString());
}
Also used : MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) IReference(com.google.security.zynamics.zylib.disassembly.IReference) Test(org.junit.Test)

Example 5 with COperandTreeNode

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

the class InstructionTest method testConstructor.

@Test
public void testConstructor() throws CouldntLoadDataException, LoadCancelledException {
    final SQLProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTree operand1 = new COperandTree(rootNode1, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
    final CInstruction internalInstruction = new CInstruction(false, internalModule, new CAddress(0x123), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", provider);
    final Instruction instruction = new Instruction(internalInstruction);
    assertEquals(0x123, instruction.getAddress().toLong());
    assertEquals(null, instruction.getComment());
    assertArrayEquals(new byte[] { 1, 2, 3 }, instruction.getData());
    assertEquals("mov", instruction.getMnemonic());
    assertEquals(2, instruction.getOperands().size());
    assertEquals("eax", instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue());
    assertEquals("ebx", instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue());
    assertEquals("123  mov eax, ebx", instruction.toString());
    assertEquals("x86-32", instruction.getArchitecture());
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Aggregations

COperandTreeNode (com.google.security.zynamics.binnavi.disassembly.COperandTreeNode)17 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)11 IReference (com.google.security.zynamics.zylib.disassembly.IReference)10 Test (org.junit.Test)10 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)9 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)8 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)6 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)6 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)5 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)4 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)3 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)3 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 CInstructionResult (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CInstructionResult)2 CTrackingResult (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CTrackingResult)2 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)2