use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class PostgreSQLNodeSaver method saveCodeNodes.
/**
* Saves the code nodes to the database.
*
* @param provider The connection to the database.
* @param nodes The nodes to save.
* @param firstNode The database index of the first node.
* @param codeNodeIndices Index into the nodes list that identifies the code nodes.
*
* @throws SQLException Thrown if saving the code node instructions failed.
*/
protected static void saveCodeNodes(final SQLProvider provider, final List<INaviViewNode> nodes, final int firstNode, final List<Integer> codeNodeIndices) throws SQLException {
if (!codeNodeIndices.isEmpty()) {
final List<Pair<INaviCodeNode, INaviInstruction>> instructionsWithUnsavedLocalComments = PostgreSQLNodeSaver.saveCodeNodeInstructions(provider, nodes, firstNode, codeNodeIndices);
final String query = "INSERT INTO " + CTableNames.CODE_NODES_TABLE + "(module_id, node_id, parent_function, comment_id) VALUES (?, ?, ?, ?)";
final ArrayList<INaviCodeNode> codeNodesWithUnsavedComments = new ArrayList<INaviCodeNode>();
final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query);
try {
for (final int index : codeNodeIndices) {
final INaviCodeNode codeNode = (INaviCodeNode) nodes.get(index);
codeNode.setId(firstNode + index);
INaviFunction function = null;
try {
function = codeNode.getParentFunction();
} catch (final MaybeNullException e) {
}
final int moduleId = Iterables.getLast(codeNode.getInstructions()).getModule().getConfiguration().getId();
final List<IComment> comment = codeNode.getComments().getLocalCodeNodeComment();
final Integer commentId = comment == null ? null : comment.size() == 0 ? null : Iterables.getLast(comment).getId();
if ((comment != null) && (comment.size() != 0) && (commentId == null)) {
codeNodesWithUnsavedComments.add(codeNode);
}
preparedStatement.setInt(1, moduleId);
preparedStatement.setInt(2, firstNode + index);
if (function == null) {
preparedStatement.setNull(3, Types.BIGINT);
} else {
preparedStatement.setObject(3, function.getAddress().toBigInteger(), Types.BIGINT);
}
if (commentId == null) {
preparedStatement.setNull(4, Types.INTEGER);
} else {
preparedStatement.setInt(4, commentId);
}
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
} finally {
preparedStatement.close();
}
// implementation.
for (final INaviCodeNode codeNode : codeNodesWithUnsavedComments) {
final ArrayList<IComment> codeNodecomments = new ArrayList<IComment>();
for (final IComment comment : codeNode.getComments().getLocalCodeNodeComment()) {
try {
final Integer commentId = PostgreSQLNodeFunctions.appendLocalCodeNodeComment(provider, codeNode, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
codeNodecomments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
codeNode.getComments().initializeLocalCodeNodeComment(codeNodecomments);
}
// implementation.
for (final Pair<INaviCodeNode, INaviInstruction> pair : instructionsWithUnsavedLocalComments) {
final ArrayList<IComment> localInstructionComments = new ArrayList<IComment>();
for (final IComment comment : pair.first().getComments().getLocalInstructionComment(pair.second())) {
try {
final int commentId = PostgreSQLInstructionFunctions.appendLocalInstructionComment(provider, pair.first(), pair.second(), comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
localInstructionComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
pair.first().getComments().initializeLocalInstructionComment(pair.second(), localInstructionComments);
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CCodeNodeMenu method addOpenOriginalFunctionMenu.
private void addOpenOriginalFunctionMenu(final CGraphModel model, final NaviNode node) {
final INaviCodeNode rawNode = (INaviCodeNode) node.getRawNode();
try {
final INaviFunction nodeFunction = rawNode.getParentFunction();
final INaviFunction viewFunction = model.getViewContainer().getFunction(model.getGraph().getRawView());
if (nodeFunction != viewFunction) {
add(CActionProxy.proxy(new COpenOriginalFunction(model.getParent(), model.getViewContainer(), nodeFunction)));
}
} catch (final MaybeNullException e) {
// If there is no original function then we can not open it.
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CCodeNodeMenu method addFunctionOperandMenu.
private void addFunctionOperandMenu(final CGraphModel model, final INaviReplacement replacement) {
final INaviFunction function = ((CFunctionReplacement) replacement).getFunction();
final INaviView view = function.getModule().getContent().getViewContainer().getView(function);
add(new CChangeFunctionNameAction(model.getParent(), view));
addSeparator();
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CCodeNodeMenu method addRenameFunctionMenu.
private void addRenameFunctionMenu(final INaviCodeNode codeNode, final CGraphModel model) {
try {
final INaviFunction function = codeNode.getParentFunction();
final INaviView view = function.getModule().getContent().getViewContainer().getView(function);
add(new CChangeFunctionNameAction(model.getParent(), view));
} catch (final MaybeNullException e) {
// no parent function no menu entry we are ok with this.
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CBreakpointPainter method paintBreakpoints.
/**
* Paints breakpoints into a function node.
*
* @param manager The breakpoint manager that provides breakpoint information.
* @param node The visible BinNavi node where the breakpoint is painted.
* @param functionNode The function node that contains the raw data for the BinNavi node.
*/
public static void paintBreakpoints(final BreakpointManager manager, final NaviNode node, final INaviFunctionNode functionNode) {
Preconditions.checkNotNull(manager, "IE02374: Manager argument can not be null");
Preconditions.checkNotNull(node, "IE02375: Node argument can not be null");
Preconditions.checkNotNull(functionNode, "IE02376: Code node argument can not be null");
final INaviFunction function = functionNode.getFunction();
final INaviModule module = function.getModule();
final int FUNCTION_BREAKPOINT_LINE = 1;
final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress()));
if (manager.hasBreakpoint(BreakpointType.REGULAR, address)) {
node.setHighlighting(CHighlightLayers.BREAKPOINT_LAYER, FUNCTION_BREAKPOINT_LINE, BreakpointManager.getBreakpointColor(manager.getBreakpointStatus(address, BreakpointType.REGULAR)));
} else {
// If there is no breakpoint, clear potential older breakpoint line.
node.clearHighlighting(500, FUNCTION_BREAKPOINT_LINE);
}
}
Aggregations