mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 00:16:16 +00:00
Fixed semantics, added documentation.:
This commit is contained in:
parent
69890a75cb
commit
aa4736fafa
@ -500,16 +500,13 @@ public class HashDbManager implements PropertyChangeListener {
|
||||
private void loadHashsetsConfiguration() {
|
||||
try {
|
||||
HashLookupSettings settings = HashLookupSettings.readSettings();
|
||||
if (settings != null) {
|
||||
this.configureSettings(settings);
|
||||
}
|
||||
this.configureSettings(settings);
|
||||
} catch (HashLookupSettings.HashLookupSettingsException ex) {
|
||||
Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Could not read Hash lookup settings from disk.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Messages({"# {0} - database name", "HashDbManager.noDbPath.message=Couldn't get valid database path for: {0}",
|
||||
"HashDbManager.noOverwrite.message=Could not overwrite hash database settings."})
|
||||
@Messages({"# {0} - database name", "HashDbManager.noDbPath.message=Couldn't get valid database path for: {0}"})
|
||||
private void configureSettings(HashLookupSettings settings) {
|
||||
boolean dbInfoRemoved = false;
|
||||
List<HashDbInfo> hashDbInfoList = settings.getHashDbInfo();
|
||||
@ -536,7 +533,7 @@ public class HashDbManager implements PropertyChangeListener {
|
||||
try {
|
||||
HashLookupSettings.writeSettings(new HashLookupSettings(this.knownHashSets, this.knownBadHashSets));
|
||||
} catch (HashLookupSettings.HashLookupSettingsException ex) {
|
||||
logger.log(Level.SEVERE, "Could not overwrite hash database settings.");
|
||||
logger.log(Level.SEVERE, "Could not overwrite hash database settings.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,11 @@ final class HashLookupSettings implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final List<HashDbInfo> hashDbInfoList;
|
||||
|
||||
/**
|
||||
* Constructs a settings object to be serialized for hash lookups
|
||||
*
|
||||
* @param hashDbInfoList The list of hash db info.
|
||||
*/
|
||||
HashLookupSettings(List<HashDbInfo> hashDbInfoList) {
|
||||
this.hashDbInfoList = hashDbInfoList;
|
||||
}
|
||||
@ -68,8 +73,8 @@ final class HashLookupSettings implements Serializable {
|
||||
/**
|
||||
* Constructs a settings object to be serialized for hash lookups
|
||||
*
|
||||
* @param knownHashSets
|
||||
* @param knownBadHashSets
|
||||
* @param knownHashSets The list known hash sets for the settings.
|
||||
* @param knownBadHashSets The list of known bad hash sets for the settings.
|
||||
*/
|
||||
HashLookupSettings(List<HashDbManager.HashDb> knownHashSets, List<HashDbManager.HashDb> knownBadHashSets) throws HashLookupSettingsException {
|
||||
hashDbInfoList = new ArrayList<>();
|
||||
@ -77,6 +82,13 @@ final class HashLookupSettings implements Serializable {
|
||||
this.addHashesToList(knownBadHashSets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds each HashDb to the settings.
|
||||
*
|
||||
* @param hashSetList The list of HashDb to add to the settings
|
||||
*
|
||||
* @throws * pacannot be obtained
|
||||
*/
|
||||
private void addHashesToList(List<HashDbManager.HashDb> hashSetList) throws HashLookupSettingsException {
|
||||
for (HashDbManager.HashDb hashDb : hashSetList) {
|
||||
try {
|
||||
@ -96,12 +108,20 @@ final class HashLookupSettings implements Serializable {
|
||||
/**
|
||||
* Gets the list of hash db info that this settings contains
|
||||
*
|
||||
* @return the hashDbInfoList
|
||||
* @return The list of hash databse info
|
||||
*/
|
||||
List<HashDbInfo> getHashDbInfo() {
|
||||
return hashDbInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the settings from the disk.
|
||||
*
|
||||
* @return The settings object representing what was read.
|
||||
*
|
||||
* @throws HashLookupSettingsException When there is a problem reading the
|
||||
* settings.
|
||||
*/
|
||||
static HashLookupSettings readSettings() throws HashLookupSettingsException {
|
||||
File fileSetFile = new File(SERIALIZATION_FILE_PATH);
|
||||
if (fileSetFile.exists()) {
|
||||
@ -111,6 +131,15 @@ final class HashLookupSettings implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the serialization settings from the disk
|
||||
*
|
||||
* @return Settings object representing what is saved in the serialization
|
||||
* file.
|
||||
*
|
||||
* @throws HashLookupSettingsException If there's a problem importing the
|
||||
* settings
|
||||
*/
|
||||
private static HashLookupSettings readSerializedSettings() throws HashLookupSettingsException {
|
||||
try {
|
||||
try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(SERIALIZATION_FILE_PATH))) {
|
||||
@ -122,6 +151,15 @@ final class HashLookupSettings implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the xml settings from the disk
|
||||
*
|
||||
* @return Settings object representing what is saved in the xml file, or an
|
||||
* empty settings if there is no xml file.
|
||||
*
|
||||
* @throws HashLookupSettingsException If there's a problem importing the
|
||||
* settings
|
||||
*/
|
||||
private static HashLookupSettings readXmlSettings() throws HashLookupSettingsException {
|
||||
File xmlFile = new File(configFilePath);
|
||||
if (xmlFile.exists()) {
|
||||
@ -130,26 +168,22 @@ final class HashLookupSettings implements Serializable {
|
||||
// Open the XML document that implements the configuration file.
|
||||
final Document doc = XMLUtil.loadDoc(HashDbManager.class, configFilePath);
|
||||
if (doc == null) {
|
||||
return null;
|
||||
throw new HashLookupSettingsException("Could not open xml document.");
|
||||
}
|
||||
|
||||
// Get the root element.
|
||||
Element root = doc.getDocumentElement();
|
||||
if (root == null) {
|
||||
logger.log(Level.SEVERE, "Error loading hash sets: invalid file format."); //NON-NLS
|
||||
return null;
|
||||
throw new HashLookupSettingsException("Error loading hash sets: invalid file format.");
|
||||
}
|
||||
|
||||
// Get the hash set elements.
|
||||
NodeList setsNList = root.getElementsByTagName(SET_ELEMENT);
|
||||
int numSets = setsNList.getLength();
|
||||
if (numSets == 0) {
|
||||
logger.log(Level.WARNING, "No element hash_set exists."); //NON-NLS
|
||||
}
|
||||
|
||||
// Create HashDbInfo objects for each hash set element. Throws on malformed xml.
|
||||
String attributeErrorMessage = " attribute was not set for hash_set at index {0}, cannot make instance of HashDb class"; //NON-NLS
|
||||
String elementErrorMessage = " element was not set for hash_set at index {0}, cannot make instance of HashDb class"; //NON-NLS
|
||||
String attributeErrorMessage = "Missing %s attribute"; //NON-NLS
|
||||
String elementErrorMessage = "Empty %s element"; //NON-NLS
|
||||
List<String> hashSetNames = new ArrayList<>();
|
||||
List<HashDbInfo> hashDbInfoList = new ArrayList<>();
|
||||
for (int i = 0; i < numSets; ++i) {
|
||||
@ -157,7 +191,7 @@ final class HashLookupSettings implements Serializable {
|
||||
|
||||
String hashSetName = setEl.getAttribute(SET_NAME_ATTRIBUTE);
|
||||
if (hashSetName.isEmpty()) {
|
||||
throw new HashLookupSettingsException(SEND_INGEST_MESSAGES_ATTRIBUTE + attributeErrorMessage);
|
||||
throw new HashLookupSettingsException(String.format(attributeErrorMessage, SET_NAME_ATTRIBUTE));
|
||||
}
|
||||
|
||||
// Handle configurations saved before duplicate hash set names were not permitted.
|
||||
@ -168,9 +202,7 @@ final class HashLookupSettings implements Serializable {
|
||||
++suffix;
|
||||
newHashSetName = hashSetName + suffix;
|
||||
} while (hashSetNames.contains(newHashSetName));
|
||||
logger.log(Level.INFO, NbBundle.getMessage(HashLookupSettings.class,
|
||||
"HashDbManager.replacingDuplicateHashsetNameMsg",
|
||||
hashSetName, newHashSetName));
|
||||
logger.log(Level.INFO, "Duplicate hash set name " + hashSetName + " found.\nReplacing with " + newHashSetName + ".");
|
||||
if (RuntimeProperties.coreComponentsAreActive()) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
NbBundle.getMessage(HashLookupSettings.class,
|
||||
@ -184,7 +216,7 @@ final class HashLookupSettings implements Serializable {
|
||||
|
||||
String knownFilesType = setEl.getAttribute(SET_TYPE_ATTRIBUTE);
|
||||
if (knownFilesType.isEmpty()) {
|
||||
throw new HashLookupSettingsException(SEND_INGEST_MESSAGES_ATTRIBUTE + attributeErrorMessage);
|
||||
throw new HashLookupSettingsException(String.format(attributeErrorMessage, SET_TYPE_ATTRIBUTE));
|
||||
}
|
||||
|
||||
// Handle legacy known files types.
|
||||
@ -195,13 +227,13 @@ final class HashLookupSettings implements Serializable {
|
||||
|
||||
final String searchDuringIngest = setEl.getAttribute(SEARCH_DURING_INGEST_ATTRIBUTE);
|
||||
if (searchDuringIngest.isEmpty()) {
|
||||
throw new HashLookupSettingsException(SEND_INGEST_MESSAGES_ATTRIBUTE + attributeErrorMessage);
|
||||
throw new HashLookupSettingsException(String.format(attributeErrorMessage, SEND_INGEST_MESSAGES_ATTRIBUTE));
|
||||
}
|
||||
Boolean searchDuringIngestFlag = Boolean.parseBoolean(searchDuringIngest);
|
||||
|
||||
final String sendIngestMessages = setEl.getAttribute(SEND_INGEST_MESSAGES_ATTRIBUTE);
|
||||
if (searchDuringIngest.isEmpty()) {
|
||||
throw new HashLookupSettingsException(SEND_INGEST_MESSAGES_ATTRIBUTE + attributeErrorMessage);
|
||||
throw new HashLookupSettingsException(String.format(attributeErrorMessage, SEND_INGEST_MESSAGES_ATTRIBUTE));
|
||||
}
|
||||
Boolean sendIngestMessagesFlag = Boolean.parseBoolean(sendIngestMessages);
|
||||
|
||||
@ -218,10 +250,10 @@ final class HashLookupSettings implements Serializable {
|
||||
|
||||
dbPath = pathEl.getTextContent();
|
||||
if (dbPath.isEmpty()) {
|
||||
throw new HashLookupSettingsException(SEND_INGEST_MESSAGES_ATTRIBUTE + attributeErrorMessage);
|
||||
throw new HashLookupSettingsException(String.format(elementErrorMessage, PATH_ELEMENT));
|
||||
}
|
||||
} else {
|
||||
throw new HashLookupSettingsException(SEND_INGEST_MESSAGES_ATTRIBUTE + attributeErrorMessage);
|
||||
throw new HashLookupSettingsException(String.format(elementErrorMessage, PATH_ELEMENT));
|
||||
}
|
||||
hashDbInfoList.add(new HashDbInfo(hashSetName, HashDbManager.HashDb.KnownFilesType.valueOf(knownFilesType),
|
||||
searchDuringIngestFlag, sendIngestMessagesFlag, dbPath));
|
||||
@ -236,9 +268,7 @@ final class HashLookupSettings implements Serializable {
|
||||
"HashDbManager.baseMessage.updatedFormatHashDbConfig");
|
||||
try {
|
||||
FileUtils.copyFile(new File(configFilePath), new File(backupFilePath));
|
||||
logger.log(Level.INFO, NbBundle.getMessage(HashLookupSettings.class,
|
||||
"HashDbManager.savedBackupOfOldConfigMsg",
|
||||
baseMessage, backupFilePath));
|
||||
logger.log(Level.INFO, baseMessage + "\nA backup copy of the old configuration has been saved as\n" + backupFilePath);
|
||||
if (RuntimeProperties.coreComponentsAreActive()) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
NbBundle.getMessage(HashLookupSettings.class,
|
||||
@ -292,6 +322,16 @@ final class HashLookupSettings implements Serializable {
|
||||
private final boolean sendIngestMessages;
|
||||
private final String path;
|
||||
|
||||
/**
|
||||
* Constructs a HashDbInfo object
|
||||
*
|
||||
* @param hashSetName The name of the hash set
|
||||
* @param knownFilesType The known files type
|
||||
* @param searchDuringIngest Whether or not the db is searched during
|
||||
* ingest
|
||||
* @param sendIngestMessages Whether or not ingest messages are sent
|
||||
* @param path The path to the db
|
||||
*/
|
||||
HashDbInfo(String hashSetName, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages, String path) {
|
||||
this.hashSetName = hashSetName;
|
||||
this.knownFilesType = knownFilesType;
|
||||
|
Loading…
x
Reference in New Issue
Block a user