use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.
the class ViewTest method setUp.
@SuppressWarnings("deprecation")
@Before
public void setUp() throws LoadCancelledException, com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException, FileReadException, CouldntLoadDataException {
ConfigManager.instance().read();
final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
final CTagManager internalTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, m_provider))), TagType.VIEW_TAG, m_provider);
m_viewTagManager = new TagManager(internalTagManager);
final Database database = new Database(new MockDatabase());
internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, m_provider);
internalModule.load();
module = new Module(database, internalModule, tagManager, m_viewTagManager);
final Calendar cal = Calendar.getInstance();
cal.setTime(module.getModificationDate());
cal.add(Calendar.DATE, 1);
m_modificationDate = cal.getTime();
m_creationDate = new Date();
final ITreeNode<CTag> tag = internalTagManager.addTag(internalTagManager.getRootTag(), "foo");
final CModuleViewGenerator generator = new CModuleViewGenerator(m_provider, internalModule);
final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, m_creationDate, m_modificationDate, 1, 2, Sets.newHashSet(tag.getObject()), new HashSet<CTag>(), false);
m_view = new View(module, internalView, tagManager, m_viewTagManager);
}
use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.
the class CViewContainer method createView.
/**
* Creates a new empty view in the module.
*
* @param name The name of the new view.
* @param description The description of the new view.
*
* @return The new view.
*/
public CView createView(final String name, final String description) {
Preconditions.checkNotNull(name, "IE00164: Name argument can not be null");
Preconditions.checkNotNull(description, "IE00165: Name description can not be null");
final Date date = new Date();
final CModuleViewGenerator generator = new CModuleViewGenerator(m_provider, m_module);
final CView view = generator.generate(-1, name, description, ViewType.NonNative, GraphType.MIXED_GRAPH, date, date, 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
try {
view.load();
} catch (CouldntLoadDataException | CPartialLoadException | LoadCancelledException e) {
CUtilityFunctions.logException(e);
}
addView(view);
return view;
}
use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator 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.CModuleViewGenerator in project binnavi by google.
the class PostgreSQLViewsLoader method processQueryResults.
/**
* Processes the results of a view loading query.
*
* @param resultSet Contains the results of the SQL query.
* @param module The module the views were loaded for.
* @param tags Map that contains the tags the views are tagged with.
* @param nodeTagManager Provides the node tags.
* @param provider The connection to the database.
* @param views The loaded views are stored in this list.
* @param viewType View type of the loaded views.
* @param graphType Graph type of the loaded views.
*
* @return The loaded views.
*
* @throws SQLException Thrown if the views could not be loaded.
*/
protected static final List<CView> processQueryResults(final ResultSet resultSet, final INaviModule module, final Map<Integer, Set<CTag>> tags, final ITagManager nodeTagManager, final SQLProvider provider, final List<CView> views, final ViewType viewType, final GraphType graphType) throws SQLException {
final Map<Integer, Set<CTag>> nodeTagMap = getNodeTags(provider.getConnection(), module, nodeTagManager);
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt("view_id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final Timestamp creationDate = resultSet.getTimestamp("creation_date");
final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
final boolean starState = resultSet.getBoolean("stared");
final int nodeCount = resultSet.getInt("bbcount");
final int edgeCount = resultSet.getInt("edgecount");
final Set<CTag> viewTags = tags.containsKey(viewId) ? tags.get(viewId) : new HashSet<CTag>();
final Set<CTag> nodeTags = nodeTagMap.containsKey(viewId) ? nodeTagMap.get(viewId) : new HashSet<CTag>();
final CModuleViewGenerator generator = new CModuleViewGenerator(provider, module);
views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
}
return views;
} finally {
resultSet.close();
}
}
use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.
the class PostgreSQLViewCreator method createView.
/**
* Creates a new view by copying an existing view.
*
* @param provider The connection to the database.
* @param module The module the view is added to.
* @param view The view to be copied.
* @param name The name of the new view.
* @param description The description of the new view.
* @return The new view.
* @throws CouldntSaveDataException Thrown if the view could not be saved.
*/
public static CView createView(final AbstractSQLProvider provider, final INaviModule module, final INaviView view, final String name, final String description) throws CouldntSaveDataException {
Preconditions.checkNotNull(provider, "IE02268: Provider argument can not be null");
Preconditions.checkNotNull(module, "IE02269: Module argument can not be null");
Preconditions.checkNotNull(view, "IE02270: View argument can not be null");
Preconditions.checkNotNull(name, "IE02271: Name argument can not be null");
Preconditions.checkState(module.inSameDatabase(provider), "Error: Module is not part of this database");
Preconditions.checkState(view.inSameDatabase(provider), "Error: View is not part of this database");
return createView(provider, module.getConfiguration().getId(), view, name, description, "" + CTableNames.MODULES_TABLE + "", "" + CTableNames.MODULE_VIEWS_TABLE + "", new CModuleViewGenerator(provider, module));
}
Aggregations