use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class ZyCodeNodeBuilder method buildFunctionLine.
/**
* Builds the function line of a code node. This line gives information about the function from
* where the code node originally came from.
*
* @param node The node that provides the raw data.
* @param content The node content where the function line is added.
* @param modifier Calculates the address strings. This argument can be null.
*/
private static void buildFunctionLine(final INaviCodeNode node, final ZyLabelContent content, final INodeModifier modifier) {
try {
final INaviFunction parentFunction = node.getParentFunction();
final String address = modifier == null ? parentFunction.getAddress().toHexString() : modifier.getAddress(parentFunction.getModule(), new UnrelocatedAddress(parentFunction.getAddress()), true);
final String name = parentFunction.getName();
content.addLineContent(new ZyLineContent(address + PADDING_AFTER_FUNCTION_ADDRESS + parentFunction.getModule().getConfiguration().getName() + "::" + name, BOLD_FONT, Lists.newArrayList(new CStyleRunData(0, -1, Color.BLACK)), null));
} catch (final MaybeNullException exception) {
// If there is no parent function, the parent function is not shown in the code node.
}
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class CDebuggerPainter method updateDebuggerHighlighting.
/**
* Updates the program counter highlighting in a whole graph.
*
* @param graph The graph where the highlighting is updated.
* @param address The address of the program counter to be highlighted.
* @param module The module in which the address is located.
*/
public static void updateDebuggerHighlighting(final ZyGraph graph, final UnrelocatedAddress address, final INaviModule module) {
Preconditions.checkNotNull(graph, "IE02187: Graph argument can not be null");
Preconditions.checkNotNull(address, "IE02188: Address argument can not be null");
graph.iterate(new INodeCallback<NaviNode>() {
@Override
public IterationMode next(final NaviNode node) {
final INaviViewNode rawNode = node.getRawNode();
if (rawNode instanceof ICodeNode) {
final INaviCodeNode codeNode = (INaviCodeNode) rawNode;
try {
if (module.equals(codeNode.getParentFunction().getModule())) {
updateDebuggerHighlighting(graph, address, node, codeNode);
}
} catch (final MaybeNullException exception) {
CUtilityFunctions.logException(exception);
}
} else if (rawNode instanceof INaviFunctionNode) {
final INaviFunctionNode functionNode = (INaviFunctionNode) rawNode;
if (module.equals(functionNode.getFunction().getModule())) {
updateDebuggerHighlighting(address, node, functionNode);
}
}
return IterationMode.CONTINUE;
}
});
ZyZoomHelpers.zoomToAddress(graph, address.getAddress(), module, false);
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException 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.Exceptions.MaybeNullException in project binnavi by google.
the class ZyOperandBuilder method isVariableAccess.
/**
* Determines whether a given node represents variable access.
*
* @param node The node to check.
*
* @return True, if the node represents an expression that accesses a variable. False, otherwise.
*/
private static boolean isVariableAccess(final INaviOperandTreeNode node) {
try {
final INaviOperandTreeNode memoryAccessNode = getMemoryAccessNode(node);
final List<INaviOperandTreeNode> children = memoryAccessNode.getChildren();
if (children.size() == 1) {
final INaviOperandTreeNode child = children.get(0);
switch(child.getType()) {
case SIZE_PREFIX:
return isVariable(child.getChildren().get(0));
case IMMEDIATE_INTEGER:
return isVariable(child);
case OPERATOR:
return isOperatorVariableAccess(child);
default:
return false;
}
} else {
throw new IllegalStateException("IE00703: Invalid tree shape");
}
} catch (final MaybeNullException e) {
return false;
}
}
use of com.google.security.zynamics.binnavi.Exceptions.MaybeNullException in project binnavi by google.
the class PostgreSQLNodeFunctions method appendGlobalCodeNodeComment.
/**
* Appends a comment as global code node comment to a code node.
*
* @param provider The SQL provider used to access the database.
* @param codeNode The code node to which the global comment will be appended.
* @param commentText The text of the comment which will be appended.
* @param userId The user id of the currently active user.
*
* @throws CouldntSaveDataException Thrown if the global code node comment could not be saved to
* the database.
*/
public static int appendGlobalCodeNodeComment(final SQLProvider provider, final INaviCodeNode codeNode, final String commentText, final Integer userId) throws CouldntSaveDataException {
Preconditions.checkNotNull(provider, "IE02445: provider argument can not be null");
Preconditions.checkNotNull(codeNode, "IE02446: codeNode argument can not be null");
Preconditions.checkNotNull(commentText, "IE02447: commentText argument can not be null");
Preconditions.checkNotNull(userId, "IE02448: userId argument can not be null");
final Connection connection = provider.getConnection().getConnection();
Integer moduleId = null;
final int nodeId = codeNode.getId();
final BigInteger nodeAddress = codeNode.getAddress().toBigInteger();
try {
moduleId = codeNode.getParentFunction().getModule().getConfiguration().getId();
} catch (final MaybeNullException exception) {
throw new CouldntSaveDataException("Error: Can not append global code node comments for nodes without a parent function");
}
final String function = "{ ? = call append_global_code_node_comment( ?, ?, ?, ?, ?) }";
try {
final CallableStatement appendCommentFunction = connection.prepareCall(function);
try {
appendCommentFunction.registerOutParameter(1, Types.INTEGER);
appendCommentFunction.setInt(2, moduleId);
appendCommentFunction.setInt(3, nodeId);
appendCommentFunction.setObject(4, nodeAddress, java.sql.Types.BIGINT);
appendCommentFunction.setInt(5, userId);
appendCommentFunction.setString(6, commentText);
appendCommentFunction.execute();
final int commentId = appendCommentFunction.getInt(1);
if (appendCommentFunction.wasNull()) {
throw new CouldntSaveDataException("Error: Got an comment id of null from the database");
}
return commentId;
} finally {
appendCommentFunction.close();
}
} catch (final SQLException exception) {
throw new CouldntSaveDataException(exception);
}
}
Aggregations