Search in sources :

Example 1 with CDatabase

use of com.google.security.zynamics.binnavi.Database.CDatabase 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 2 with CDatabase

use of com.google.security.zynamics.binnavi.Database.CDatabase in project binnavi by google.

the class CDatabaseFunctions method addNewDatabase.

/**
 * Adds a new database with default information to the list of known databases.
 *
 * @param projectTree Project tree of the main window.
 */
public static void addNewDatabase(final JTree projectTree) {
    final CDatabase newDatabase = new CDatabase("New Database", CJdbcDriverNames.jdbcPostgreSQLDriverName, "localhost", "new_database", "user", "password", "identity", false, false);
    CDatabaseManager.instance().addDatabase(newDatabase);
    CNodeExpander.setSelectionPath(projectTree, newDatabase);
}
Also used : CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase)

Example 3 with CDatabase

use of com.google.security.zynamics.binnavi.Database.CDatabase in project binnavi by google.

the class PostgreSQLNotificationProviderTest method setUp.

@Before
public void setUp() throws IOException, CouldntLoadDriverException, CouldntConnectException, IllegalStateException, CouldntLoadDataException, InvalidDatabaseException, CouldntInitializeDatabaseException, InvalidExporterDatabaseFormatException, LoadCancelledException, CPartialLoadException, InvalidDatabaseVersionException {
    final String[] parts = CConfigLoader.loadPostgreSQL();
    databaseOne = new CDatabase("DATABASEONE", CJdbcDriverNames.jdbcPostgreSQLDriverName, parts[0], "test_disassembly", parts[1], parts[2], parts[3], false, false);
    databaseOne.connect();
    databaseOne.load();
    databaseOneModuleTwo = databaseOne.getContent().getModule(2);
    databaseOneModuleTwo.load();
    databaseOneFunction = databaseOneModuleTwo.getContent().getFunctionContainer().getFunction(new CAddress("7C880394", 16));
    databaseOneView = databaseOneModuleTwo.getContent().getViewContainer().getView(databaseOneFunction);
    databaseOneView.load();
    databaseTwo = new CDatabase("DATABASETWO", CJdbcDriverNames.jdbcPostgreSQLDriverName, parts[0], "test_disassembly", parts[1], parts[2], parts[3], false, false);
    databaseTwo.connect();
    databaseTwo.load();
    databaseTwoModuleTwo = databaseTwo.getContent().getModule(2);
    databaseTwoModuleTwo.load();
    databaseTwoFunction = databaseTwoModuleTwo.getContent().getFunctionContainer().getFunction(new CAddress("7C880394", 16));
    databaseTwoView = databaseTwoModuleTwo.getContent().getViewContainer().getView(databaseTwoFunction);
    databaseTwoView.load();
}
Also used : CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Before(org.junit.Before)

Example 4 with CDatabase

use of com.google.security.zynamics.binnavi.Database.CDatabase in project binnavi by google.

the class ViewDumper method main.

public static void main(final String[] args) throws IOException, FileReadException, CouldntLoadDataException, InvalidDatabaseVersionException, CouldntLoadDriverException, CouldntConnectException, InvalidDatabaseException, CouldntInitializeDatabaseException, InvalidExporterDatabaseFormatException, CPartialLoadException, LoadCancelledException {
    ConfigManager.instance().read();
    final ZyGraphViewSettings viewSettings = ConfigManager.instance().getDefaultFlowGraphSettings();
    final ZyGraphProximitySettings proximitySettings = viewSettings.getProximitySettings();
    proximitySettings.setProximityBrowsingActivationThreshold(50);
    proximitySettings.setProximityBrowsingChildren(2);
    proximitySettings.setProximityBrowsingParents(2);
    ConfigManager.instance().updateFlowgraphSettings(viewSettings);
    @SuppressWarnings("unused") final MockSqlProvider m_provider = new MockSqlProvider();
    final String[] parts = CConfigLoader.loadPostgreSQL();
    final CDatabase m_database = new CDatabase("None", CJdbcDriverNames.jdbcPostgreSQLDriverName, parts[0], "test_disassembly", parts[1], parts[2], parts[3], false, false);
    m_database.connect();
    m_database.load();
    final INaviModule m_module = m_database.getContent().getModules().get(0);
    m_module.load();
    final IFlowgraphView m_view = m_database.getContent().getModules().get(0).getContent().getViewContainer().getNativeFlowgraphViews().get(199);
    m_view.load();
    System.out.println("MockSqlProvider provider = new MockSqlProvider();");
    System.out.println("MockModule module = new MockModule();");
    System.out.println("MockFunction function = new MockFunction();");
    System.out.println("List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();");
    System.out.println("List<INaviEdge> edges = new ArrayList<INaviEdge>();");
    for (final INaviViewNode node : m_view.getGraph()) {
        final CCodeNode oldNode = (CCodeNode) node;
        System.out.printf("CCodeNode node_%d = new CCodeNode(%d, 0, 0, Color.BLUE, Color.BLACK, false, true, \"\", function, new HashSet<CTag>(), provider);\n", node.getId(), node.getId());
        for (final INaviInstruction instruction : oldNode.getInstructions()) {
            System.out.printf("final CInstruction newInstruction_%s = new CInstruction(module, new CAddress(%d), \"%s\", new ArrayList<COperandTree>(), new byte[0], provider);\n", instruction.getAddress(), instruction.getAddress().toLong(), instruction.getMnemonic());
            System.out.printf("node_%d.addInstruction(newInstruction_%s, \"\");\n", oldNode.getId(), instruction.getAddress());
        }
        System.out.printf("nodes.add(node_%d);\n", node.getId());
    }
    for (final INaviEdge edge : m_view.getGraph().getEdges()) {
        System.out.printf("CNaviEdge edge_%d = new CNaviEdge(%s, node_%d, node_%d, EdgeType.%s, 0, 0, 0, 0, Color.BLACK, false, true, \"\", new ArrayList<CBend>(), provider);\n", edge.getId(), edge.getId(), edge.getSource().getId(), edge.getTarget().getId(), edge.getType());
        System.out.printf("edges.add(edge_%d);\n", edge.getId());
        System.out.printf("CNaviViewNode.link(node_%d, node_%d);\n", edge.getSource().getId(), edge.getTarget().getId());
        System.out.printf("node_%d.addOutgoingEdge(edge_%d);\n", edge.getSource().getId(), edge.getId());
        System.out.printf("node_%d.addIncomingEdge(edge_%d);\n", edge.getTarget().getId(), edge.getId());
    }
    System.out.println("final INaviView view = new MockView(nodes, edges);");
    m_database.close();
}
Also used : ZyGraphViewSettings(com.google.security.zynamics.binnavi.ZyGraph.ZyGraphViewSettings) ZyGraphProximitySettings(com.google.security.zynamics.binnavi.ZyGraph.Settings.ZyGraphProximitySettings) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)

Example 5 with CDatabase

use of com.google.security.zynamics.binnavi.Database.CDatabase in project binnavi by google.

the class ExpensiveBaseTest method setUpEnvironment.

// TODO(jannewger): we should probably use the decorator pattern to give deriving classes more
// control over the test setups, e.g. whether to load a project, which modules to load, whether to
// also load a view, etc
@Before
public void setUpEnvironment() throws CouldntLoadDriverException, CouldntConnectException, InvalidDatabaseException, CouldntInitializeDatabaseException, InvalidExporterDatabaseFormatException, LoadCancelledException, CouldntLoadDataException, InvalidDatabaseVersionException, IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, FileReadException {
    setupStartTime = System.nanoTime();
    final String[] parts = CConfigLoader.loadPostgreSQL();
    database = new CDatabase("Expensive base test database", CJdbcDriverNames.jdbcPostgreSQLDriverName, parts[0], "test_disassembly", parts[1], parts[2], parts[3], false, false);
    database.connect();
    database.load();
    final Field privateProviderField = CDatabase.class.getDeclaredField("provider");
    privateProviderField.setAccessible(true);
    provider = ((SQLProvider) privateProviderField.get(database));
    ConfigManager.instance().read();
    modules = provider.loadModules();
    kernel32Module = findModule(Kernel32String);
    notepadModule = findModule(NotepadString);
    setupEndTime = System.nanoTime();
    NaviLogger.info("Setting up took: " + String.valueOf(TimeUnit.SECONDS.convert(setupEndTime - setupStartTime, TimeUnit.NANOSECONDS)) + " seconds");
    testStartTime = System.nanoTime();
}
Also used : Field(java.lang.reflect.Field) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) Before(org.junit.Before)

Aggregations

CDatabase (com.google.security.zynamics.binnavi.Database.CDatabase)19 Before (org.junit.Before)13 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 Database (com.google.security.zynamics.binnavi.API.disassembly.Database)2 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)2 TagManager (com.google.security.zynamics.binnavi.API.disassembly.TagManager)2 CDatabaseManager (com.google.security.zynamics.binnavi.Database.CDatabaseManager)2 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)2 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)2 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)2 Tree (com.google.security.zynamics.zylib.types.trees.Tree)2 Field (java.lang.reflect.Field)2 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)1 Instruction (com.google.security.zynamics.binnavi.API.disassembly.Instruction)1 View (com.google.security.zynamics.binnavi.API.disassembly.View)1 ViewContainer (com.google.security.zynamics.binnavi.API.disassembly.ViewContainer)1 MainWindow (com.google.security.zynamics.binnavi.API.gui.MainWindow)1 PluginInterface (com.google.security.zynamics.binnavi.API.plugins.PluginInterface)1