GP-667 fix XmlImport bookmark overwrite existing

This commit is contained in:
dev747368 2021-02-05 13:22:26 -05:00 committed by ghidra1
parent 01b6027c77
commit 3d36d914be

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,9 +15,18 @@
*/ */
package ghidra.app.util.xml; package ghidra.app.util.xml;
import org.xml.sax.SAXParseException;
import ghidra.app.util.importer.MessageLog; import ghidra.app.util.importer.MessageLog;
import ghidra.program.model.address.*; import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*; import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.address.AddressFormatException;
import ghidra.program.model.address.AddressIterator;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Bookmark;
import ghidra.program.model.listing.BookmarkManager;
import ghidra.program.model.listing.BookmarkType;
import ghidra.program.model.listing.Program;
import ghidra.util.XmlProgramUtilities; import ghidra.util.XmlProgramUtilities;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
@ -27,8 +35,6 @@ import ghidra.util.xml.XmlWriter;
import ghidra.xml.XmlElement; import ghidra.xml.XmlElement;
import ghidra.xml.XmlPullParser; import ghidra.xml.XmlPullParser;
import org.xml.sax.SAXParseException;
class BookmarksXmlMgr { class BookmarksXmlMgr {
private BookmarkManager bookmarkMgr; private BookmarkManager bookmarkMgr;
private AddressFactory factory; private AddressFactory factory;
@ -97,14 +103,14 @@ class BookmarksXmlMgr {
} }
try { try {
if (!overwrite) { boolean hasExistingBookmark = bookmarkMgr.getBookmark(addr, type, category) != null;
if (bookmarkMgr.getBookmark(addr, type, category) != null) { if (overwrite || !hasExistingBookmark) {
log.appendMsg("Conflicting '" + type + "' BOOKMARK ignored at: " + addr);
return;
}
}
bookmarkMgr.setBookmark(addr, type, category, comment); bookmarkMgr.setBookmark(addr, type, category, comment);
} }
if (!overwrite && hasExistingBookmark) {
log.appendMsg("Conflicting '" + type + "' BOOKMARK ignored at: " + addr);
}
}
catch (Exception e) { catch (Exception e) {
log.appendException(e); log.appendException(e);
parser.discardSubTree(element); parser.discardSubTree(element);