use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class PostgreSQLInstructionFunctions method createInstructions.
/**
* Saves an instruction to the database.
*
* @param provider The provider used to access the database.
* @param instructions The instruction to save.
*
* @throws SQLException Thrown if the instruction could not be created.
*/
public static void createInstructions(final SQLProvider provider, final Iterable<INaviInstruction> instructions) throws SQLException {
Preconditions.checkNotNull(provider, "IE01550: Provider argument can not be null");
Preconditions.checkNotNull(instructions, "IE01554: Instruction argument can not be null");
final String query = "INSERT INTO " + CTableNames.INSTRUCTIONS_TABLE + "(module_id, address, mnemonic, data, native, architecture, comment_id) " + "VALUES(?, ?, ?, ?, ?, ?, ?)";
final PreparedStatement insertStatement = provider.getConnection().getConnection().prepareStatement(query);
final ArrayList<INaviInstruction> instructionsWithUnsavedComments = new ArrayList<INaviInstruction>();
final List<List<COperandTree>> operands = new ArrayList<List<COperandTree>>();
for (final INaviInstruction instruction : instructions) {
final String mnemonic = instruction.getMnemonic();
final byte[] data = instruction.getData();
operands.add(instruction.getOperands());
final INaviModule module = instruction.getModule();
final IAddress address = instruction.getAddress();
final int moduleID = module.getConfiguration().getId();
final List<IComment> comments = instruction.getGlobalComment();
final Integer commentId = comments == null ? null : comments.size() == 0 ? null : Iterables.getLast(comments).getId();
if ((comments != null) && (comments.size() != 0) && (commentId == null)) {
instructionsWithUnsavedComments.add(instruction);
}
try {
insertStatement.setInt(1, moduleID);
insertStatement.setObject(2, address.toBigInteger(), Types.BIGINT);
insertStatement.setString(3, mnemonic);
insertStatement.setBytes(4, data);
insertStatement.setBoolean(5, false);
insertStatement.setObject(6, instruction.getArchitecture(), Types.OTHER);
if (commentId == null) {
insertStatement.setNull(7, Types.INTEGER);
} else {
insertStatement.setInt(7, commentId);
}
insertStatement.execute();
} finally {
insertStatement.close();
}
}
// unsaved comments.
for (final INaviInstruction instruction : instructionsWithUnsavedComments) {
final ArrayList<IComment> instructionComments = new ArrayList<IComment>();
for (final IComment comment : instruction.getGlobalComment()) {
try {
final Integer commentId = PostgreSQLInstructionFunctions.appendGlobalInstructionComment(provider, instruction, comment.getComment(), comment.getUser().getUserId());
final IComment newComment = new CComment(commentId, comment.getUser(), comment.getParent(), comment.getComment());
instructionComments.add(newComment);
} catch (final CouldntSaveDataException exception) {
CUtilityFunctions.logException(exception);
}
}
instruction.initializeGlobalComment(instructionComments);
}
for (final List<COperandTree> operand : operands) {
int position = 0;
for (final COperandTree operandTree : operand) {
createOperandTree(provider, operandTree, position);
position++;
}
}
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class TypeInstanceContainerBackend method loadTypeInstance.
/**
* Loads a single type instance from the database.
*
* @param typeInstanceId The {@link Integer} id of the {@link TypeInstance type instance} to load.
* @return A {@link TypeInstance instance} if present in the database.
*
* @throws CouldntLoadDataException Thrown if the {@link TypeInstance type instance} could not be
* loaded from the database.
*/
public TypeInstance loadTypeInstance(final Integer typeInstanceId) throws CouldntLoadDataException {
Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
final RawTypeInstance rawTypeInstance = provider.loadTypeInstance(module, typeInstanceId);
final BaseType baseType = typeManager.getBaseType(rawTypeInstance.getTypeId());
final Section section = sectionContainer.getSection(rawTypeInstance.getSectionId());
final TypeInstance typeInstance = new TypeInstance(rawTypeInstance.getId(), rawTypeInstance.getName(), baseType, section, rawTypeInstance.getSectionOffset(), module);
instancesById.put(typeInstance.getId(), typeInstance);
if (rawTypeInstance.getCommentId() != null) {
final CommentManager manager = CommentManager.get(provider);
final List<IComment> comments = provider.loadCommentById(rawTypeInstance.getCommentId());
manager.initializeTypeInstanceComment(typeInstance, comments);
}
return typeInstance;
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class CommentManager method unloadComment.
/**
* Unloads a comment and removes the items it references from the internal storage.
*
* @param strategy The {@link CommentingStrategy} which holds the function forwarders.
* @param comments The List of {@link IComment} to be unloaded.
*/
private synchronized void unloadComment(final CommentingStrategy strategy, final List<IComment> comments) {
Preconditions.checkNotNull(strategy, "Error: strategy argument can not be null");
if (comments == null) {
return;
}
strategy.removeComments(comments);
for (final IComment comment : comments) {
commentIdToComment.remove(comment.getId());
}
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class CommentManager method appendComment.
/**
* This function provides the append comment functionality for any given Implementation of a
* {@link CommentingStrategy}. It uses the methods of the interface to only have one algorithm
* with different objects that can be commented.
*
* @param strategy The {@link CommentingStrategy} which holds the function forwarders.
* @param commentText The commenting text to append.
*
* @return The generated comment.
*
* @throws CouldntSaveDataException if the comment could not be stored in the database.
* @throws CouldntLoadDataException if the list of comments now associated with the commented
* object could not be loaded from the database.
*/
private synchronized List<IComment> appendComment(final CommentingStrategy strategy, final String commentText) throws CouldntSaveDataException, CouldntLoadDataException {
final IUser user = CUserManager.get(provider).getCurrentActiveUser();
final List<IComment> currentComments = new ArrayList<IComment>();
if (strategy.isStored()) {
currentComments.addAll(strategy.appendComment(commentText, user.getUserId()));
} else {
currentComments.addAll(strategy.getComments() == null ? new ArrayList<IComment>() : Lists.newArrayList(strategy.getComments()));
final IComment parent = currentComments.isEmpty() ? null : Iterables.getLast(currentComments);
final IComment newComment = new CComment(null, user, parent, commentText);
currentComments.add(newComment);
}
strategy.saveComments(currentComments);
for (final IComment comment : currentComments) {
commentIdToComment.put(comment.getId(), comment);
}
for (final CommentListener listener : listeners) {
try {
strategy.sendAppendedCommentNotifcation(listener, Iterables.getLast(currentComments));
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return currentComments;
}
use of com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment in project binnavi by google.
the class GroupNodeTest method testSetCollapsed.
@Test
public void testSetCollapsed() {
final Database database = new Database(new MockDatabase());
final MockModule mockModule = new MockModule();
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 MockView mockView = new MockView();
final View view = new View(module, mockView, nodeTagManager, viewTagManager);
final INaviGroupNode internalGroupNode = new CGroupNode(0, 0, 0, 0, 0, Color.RED, false, false, new HashSet<CTag>(), new ArrayList<IComment>(), false, new MockSqlProvider());
final GroupNode node = new GroupNode(view, internalGroupNode, viewTagManager);
final MockGroupNodeListener listener = new MockGroupNodeListener();
node.addListener(listener);
node.setCollapsed(true);
assertEquals("changedState;", listener.events);
assertTrue(node.isCollapsed());
node.removeListener(listener);
}
Aggregations