use of com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider 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));
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider in project binnavi by google.
the class TraceLoggerTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, InvalidDatabaseVersionException {
final SQLProvider mockProvider = new MockSqlProvider();
// CDatabase("", "", "", "", "", false,
final IDatabase internalDatabase = new MockDatabase();
// false);
final Database database = new Database(internalDatabase);
database.load();
final MockProject mockProject = new MockProject();
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));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
final Project project = new Project(database, mockProject, nodeTagManager, viewTagManager);
m_mockModule = new Module(database, mockModule, viewTagManager, nodeTagManager);
m_debugSettings = new ModuleTargetSettings(m_mockModule.getNative());
m_mockDebugger = new MockDebugger(m_debugSettings);
m_mockDebugger.setAddressTranslator(mockModule, new CAddress(0), new CAddress(0x1000));
final Debugger debugger = new Debugger(m_mockDebugger);
m_logger = new TraceLogger(debugger, module);
m_projectLogger = new TraceLogger(debugger, project);
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider 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());
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider in project binnavi by google.
the class GroupNodeTest method testElements.
@Test
public void testElements() throws CouldntLoadDataException, PartialLoadException {
final Database database = new Database(new MockDatabase());
final SQLProvider mockProvider = new MockSqlProvider();
final CModule mockModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
final INaviView mockView = generator.generate(1, "", "", ViewType.NonNative, GraphType.FLOWGRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
final View view = new View(module, mockView, nodeTagManager, viewTagManager);
view.load();
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, mockProvider);
final CodeNode codeNode = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
final CodeNode codeNode2 = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
final GroupNode node = view.createGroupNode("", Lists.newArrayList((ViewNode) codeNode2));
final MockGroupNodeListener listener = new MockGroupNodeListener();
final MockViewNodeListener listener2 = new MockViewNodeListener();
node.addListener(listener);
codeNode.addListener(listener2);
node.addNode(codeNode);
assertEquals(2, node.getElements().size());
assertEquals(codeNode, node.getElements().get(1));
assertEquals(node, codeNode.getParentGroup());
assertEquals("addedElement;", listener.events);
assertEquals("changedParentGroup;", listener2.events);
node.removeNode(codeNode);
assertEquals(1, node.getElements().size());
assertEquals(null, codeNode.getParentGroup());
assertEquals("addedElement;removedElement;", listener.events);
assertEquals("changedParentGroup;changedParentGroup;", listener2.events);
node.removeListener(listener);
}
use of com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider 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();
}
Aggregations