use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class CGraphDebuggerTest method testToggleBreakpoint3.
@Test
public void testToggleBreakpoint3() {
final MockModule module = new MockModule();
module.getConfiguration().setDebugger(m_debugger);
m_debugger.setAddressTranslator(module, m_fileBase, m_imageBase);
final DebugTargetSettings target = new ModuleTargetSettings(module);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
debuggerProvider.addDebugger(m_debugger);
final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
assertEquals(0x124, m_debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, 0).getAddress().getAddress().getAddress().toLong());
assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_debugger.getBreakpointManager().getBreakpointStatus(BreakpointType.REGULAR, 0));
CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class CGraphDebuggerTest method testToggleBreakpoint2.
@Test
public void testToggleBreakpoint2() {
final MockModule module = new MockModule();
module.getConfiguration().setDebugger(m_debugger);
m_debugger.setAddressTranslator(module, m_fileBase, m_imageBase);
final DebugTargetSettings target = new ModuleTargetSettings(module);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
debuggerProvider.addDebugger(m_debugger);
final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
final CFunctionNode functionNode = new CFunctionNode(0, function, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), m_provider);
CGraphDebugger.toggleBreakpoint(debuggerProvider, functionNode);
assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
assertEquals(0x123, m_debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, 0).getAddress().getAddress().getAddress().toLong());
assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_debugger.getBreakpointManager().getBreakpointStatus(BreakpointType.REGULAR, 0));
CGraphDebugger.toggleBreakpoint(debuggerProvider, functionNode);
assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLViewsLoader method getNodeTags.
/**
* Loads the node tags of the views of a module.
*
* @param connection Provides the connection to the database.
* @param module The module whose node-tagged views are determined.
* @param nodeTagManager Provides the available node tags.
*
* @return Maps view ID -> node tags used in the view.
*
* @throws SQLException Thrown if the data could not be loaded.
*/
private static Map<Integer, Set<CTag>> getNodeTags(final CConnection connection, final INaviModule module, final ITagManager nodeTagManager) throws SQLException {
final Map<Integer, Set<CTag>> tagMap = new HashMap<Integer, Set<CTag>>();
final String query = "SELECT * FROM load_module_node_tags(?)";
final PreparedStatement statement = connection.getConnection().prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final int viewId = resultSet.getInt(1);
final int tagId = resultSet.getInt(2);
if (!tagMap.containsKey(viewId)) {
tagMap.put(viewId, new HashSet<CTag>());
}
final CTag tag = CTagHelpers.findTag(nodeTagManager.getRootTag(), tagId);
if (tag != null) {
tagMap.get(viewId).add(tag);
}
}
} finally {
resultSet.close();
}
return tagMap;
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLFunctionNodeLoader method load.
/**
* Loads the function nodes of a view.
*
* @param provider The connection to the database.
* @param view The view whose function nodes are loaded.
* @param nodes The loaded nodes are stored here.
*
* @throws CPartialLoadException Thrown if loading the nodes failed because a necessary module was
* not loaded.
* @throws CouldntLoadDataException
*/
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CPartialLoadException, CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02510: provider argument can not be null");
Preconditions.checkNotNull(view, "IE02511: view argument can not be null");
Preconditions.checkNotNull(nodes, "IE02512: nodes argument can not be null");
// TODO (timkornau): query needs to go into the database.
final String query = "SELECT nodes.view_id, nodes.id, functions.module_id, " + " function, fnodes.comment_id as local_comment, x, y, width, height, " + " color, selected, visible FROM " + CTableNames.NODES_TABLE + " AS nodes JOIN " + CTableNames.FUNCTION_NODES_TABLE + " AS fnodes " + " ON nodes.id = fnodes.node_id JOIN " + CTableNames.FUNCTIONS_TABLE + " AS functions ON functions.address = fnodes.function " + " AND functions.module_id = fnodes.module_id WHERE view_id = ?";
final Map<Integer, INaviFunctionNode> commentIdToFunctionNode = new HashMap<Integer, INaviFunctionNode>();
try {
final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
statement.setInt(1, view.getConfiguration().getId());
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final int moduleId = resultSet.getInt("module_id");
final INaviModule module = provider.findModule(moduleId);
if (!module.isLoaded()) {
try {
module.load();
} catch (final CouldntLoadDataException e) {
throw new CPartialLoadException("E00064: The view could not be loaded because not all modules that form the view are loaded", module);
} catch (final LoadCancelledException e) {
throw new CPartialLoadException("E00065: The view could not be loaded because not all modules that form the view are loaded", module);
}
}
final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "function");
final INaviFunction function = module.getContent().getFunctionContainer().getFunction(address);
final int nodeId = resultSet.getInt("id");
Integer commentId = resultSet.getInt("local_comment");
if (resultSet.wasNull()) {
commentId = null;
}
final double posX = resultSet.getDouble("x");
final double posY = resultSet.getDouble("y");
final double width = resultSet.getDouble("width");
final double height = resultSet.getDouble("height");
final Color color = new Color(resultSet.getInt("color"));
final boolean selected = resultSet.getBoolean("selected");
final boolean visible = resultSet.getBoolean("visible");
final INaviFunctionNode functionNode = new CFunctionNode(nodeId, function, posX, posY, width, height, color, selected, visible, null, new HashSet<CTag>(), provider);
nodes.add(functionNode);
if (commentId != null) {
commentIdToFunctionNode.put(commentId, functionNode);
}
}
} finally {
resultSet.close();
}
if (!commentIdToFunctionNode.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdsToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunctionNode.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdsToComments.entrySet()) {
commentIdToFunctionNode.get(commentIdToComment.getKey()).initializeLocalFunctionComment(commentIdToComment.getValue());
}
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.
the class PostgreSQLTextNodeLoader method load.
/**
* Loads the text nodes of a view.
*
* @param provider The connection to the database.
* @param view The view whose text nodes are loaded.
* @param nodes The loaded nodes are stored here.
*
* @throws CouldntLoadDataException
*/
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02516: provider argument can not be null");
Preconditions.checkNotNull(view, "IE02517: view argument can not be null");
Preconditions.checkNotNull(nodes, "IE02518: nodes argument can not be null");
final Map<Integer, INaviTextNode> commentIdToTextNode = new HashMap<Integer, INaviTextNode>();
final String query = "SELECT id, comment_id, x, y, width, height, color, selected, visible " + " FROM " + CTableNames.NODES_TABLE + " JOIN " + CTableNames.TEXT_NODES_TABLE + " ON id = node_id " + " WHERE view_id = " + view.getConfiguration().getId();
try {
final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final int nodeId = resultSet.getInt("id");
Integer commentId = resultSet.getInt("comment_id");
if (resultSet.wasNull()) {
commentId = null;
}
final double xPos = resultSet.getDouble("x");
final double yPos = resultSet.getDouble("y");
final double width = resultSet.getDouble("width");
final double height = resultSet.getDouble("height");
final Color color = new Color(resultSet.getInt("color"));
final boolean selected = resultSet.getBoolean("selected");
final boolean visible = resultSet.getBoolean("visible");
final INaviTextNode textNode = new CTextNode(nodeId, xPos, yPos, width, height, color, selected, visible, new HashSet<CTag>(), null, provider);
if (commentId != null) {
commentIdToTextNode.put(commentId, textNode);
}
nodes.add(textNode);
}
} finally {
resultSet.close();
}
if (!commentIdToTextNode.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToTextNode.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
commentIdToTextNode.get(commentIdToComment.getKey()).initializeComment(commentIdToComment.getValue());
}
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
Aggregations