mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 07:56:16 +00:00
added callback and wrapper to process single row of file instance table by id.
This commit is contained in:
parent
69e6f47d38
commit
dba86cd11e
@ -1778,6 +1778,46 @@ abstract class AbstractSqlEamDb implements EamDb {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the Artifact instance in the EamDb
|
||||
*
|
||||
* @param type EamArtifact.Type to search for
|
||||
* @param instanceTableCallback callback to process the instance
|
||||
* @throws EamDbException
|
||||
*/
|
||||
@Override
|
||||
public void processInstanceTableRow(CorrelationAttribute.Type type, int id, InstanceTableCallback instanceTableCallback) throws EamDbException {
|
||||
if (type == null) {
|
||||
throw new EamDbException("Correlation type is null");
|
||||
}
|
||||
|
||||
if (instanceTableCallback == null) {
|
||||
throw new EamDbException("Callback interface is null");
|
||||
}
|
||||
|
||||
Connection conn = connect();
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
String tableName = EamDbUtil.correlationTypeToInstanceTableName(type);
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("select * from ");
|
||||
sql.append(tableName);
|
||||
sql.append("WHERE id = ?");
|
||||
|
||||
try {
|
||||
preparedStatement = conn.prepareStatement(sql.toString());
|
||||
preparedStatement.setInt(1, id);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
instanceTableCallback.process(resultSet);
|
||||
} catch (SQLException ex) {
|
||||
throw new EamDbException("Error getting all artifact instances from instances table", ex);
|
||||
} finally {
|
||||
EamDbUtil.closeStatement(preparedStatement);
|
||||
EamDbUtil.closeResultSet(resultSet);
|
||||
EamDbUtil.closeConnection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the Artifact instance in the EamDb
|
||||
*
|
||||
|
@ -686,6 +686,16 @@ public interface EamDb {
|
||||
*/
|
||||
void processInstanceTable(CorrelationAttribute.Type type, InstanceTableCallback instanceTableCallback) throws EamDbException;
|
||||
|
||||
/**
|
||||
* Process a single Artifact instance in the EamDb
|
||||
*
|
||||
* @param type EamArtifact.Type to search for
|
||||
* @param id the id of the row to return
|
||||
* @param instanceTableCallback callback to process the instance
|
||||
* @throws EamDbException
|
||||
*/
|
||||
void processInstanceTableRow(CorrelationAttribute.Type type, int id, InstanceTableCallback instanceTableCallback) throws EamDbException;
|
||||
|
||||
/**
|
||||
* Process the Artifact md5s in the EamDb for matches of case files which are not known
|
||||
* @param type EamArtifact.Type to search for
|
||||
@ -693,5 +703,5 @@ public interface EamDb {
|
||||
* @param instanceTableCallback callback to process the instance
|
||||
* @throws EamDbException
|
||||
*/
|
||||
public void processCaseInstancesTable(CorrelationAttribute.Type type, CorrelationCase correlationCase, InstanceTableCallback instanceTableCallback) throws EamDbException;
|
||||
void processCaseInstancesTable(CorrelationAttribute.Type type, CorrelationCase correlationCase, InstanceTableCallback instanceTableCallback) throws EamDbException;
|
||||
}
|
||||
|
@ -695,6 +695,25 @@ final class SqliteEamDb extends AbstractSqlEamDb {
|
||||
releaseSharedLock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a single Artifact instance row in the EamDb
|
||||
*
|
||||
* @param type EamArtifact.Type to search for
|
||||
* @param id the id of the row to return
|
||||
* @param instanceTableCallback callback to process the instance
|
||||
* @throws EamDbException
|
||||
*/
|
||||
@Override
|
||||
public void processInstanceTableRow(CorrelationAttribute.Type type, int id, InstanceTableCallback instanceTableCallback) throws EamDbException {
|
||||
try {
|
||||
acquireSharedLock();
|
||||
super.processInstanceTableRow(type, id, instanceTableCallback);
|
||||
} finally {
|
||||
releaseSharedLock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the Artifact md5s in the EamDb for matches of case files which are not known
|
||||
* @param type EamArtifact.Type to search for
|
||||
|
@ -27,27 +27,46 @@ import java.util.logging.Level;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.sleuthkit.autopsy.casemodule.Case;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationCase;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.InstanceTableCallback;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
|
||||
/**
|
||||
* Used to process and return CorrelationCase md5s from the EamDB for CommonFilesSearch.
|
||||
* Used to process and return CorrelationCase md5s from the EamDB for
|
||||
* CommonFilesSearch.
|
||||
*/
|
||||
class EamDbAttributeInstancesAlgorithm {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(CommonFilesPanel.class.getName());
|
||||
|
||||
private final Map<Integer, String> intercaseCommonValuesMap = new HashMap<>();
|
||||
private final Map<Integer, String> intercaseCommonDatasourcesMap = new HashMap<>();
|
||||
|
||||
private final Map<Integer, String> intercaseCommonValuesMap = new HashMap<>();
|
||||
private final Map<Integer, String> intercaseCommonDatasourcesMap = new HashMap<>();
|
||||
|
||||
void processCorrelationCaseAttributeValues(Case currentCase) {
|
||||
CorrelationAttribute processCorrelationCaseSingleAttribute(int attrbuteId) {
|
||||
try {
|
||||
EamDbAttributeInstanceRowCallback instancetableCallback = new EamDbAttributeInstanceRowCallback();
|
||||
EamDb DbManager = EamDb.getInstance();
|
||||
CorrelationAttribute.Type fileType = DbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
|
||||
DbManager.processInstanceTableRow(fileType, attrbuteId, instancetableCallback);
|
||||
|
||||
return instancetableCallback.getCorrelationAttribute();
|
||||
|
||||
} catch (EamDbException ex) {
|
||||
logger.log(Level.SEVERE, "Error accessing EamDb processing InstanceTable row.", ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
void processCorrelationCaseAttributeValues(Case currentCase) {
|
||||
|
||||
try {
|
||||
EamDbAttributeInstancesCallback instancetableCallback = new EamDbAttributeInstancesCallback();
|
||||
EamDb DbManager = EamDb.getInstance();
|
||||
CorrelationAttribute.Type fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
|
||||
CorrelationAttribute.Type fileType = DbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
|
||||
DbManager.processCaseInstancesTable(fileType, DbManager.getCase(currentCase), instancetableCallback);
|
||||
|
||||
intercaseCommonValuesMap.putAll(instancetableCallback.getCorrelationIdValueMap());
|
||||
@ -55,14 +74,14 @@ class EamDbAttributeInstancesAlgorithm {
|
||||
} catch (EamDbException ex) {
|
||||
logger.log(Level.SEVERE, "Error accessing EamDb processing CaseInstancesTable.", ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Map<Integer, String> getIntercaseCommonValuesMap() {
|
||||
return Collections.unmodifiableMap(intercaseCommonValuesMap);
|
||||
}
|
||||
|
||||
Map<Integer, String> getIntercaseCommonDatasourcesMap() {
|
||||
|
||||
Map<Integer, String> getIntercaseCommonDatasourcesMap() {
|
||||
return Collections.unmodifiableMap(intercaseCommonDatasourcesMap);
|
||||
}
|
||||
|
||||
@ -91,10 +110,44 @@ class EamDbAttributeInstancesAlgorithm {
|
||||
Map<Integer, String> getCorrelationIdValueMap() {
|
||||
return Collections.unmodifiableMap(correlationIdToValueMap);
|
||||
}
|
||||
|
||||
|
||||
Map<Integer, String> getCorrelationIdDatasourceMap() {
|
||||
return Collections.unmodifiableMap(correlationIdToDatasourceMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to use with processCaseInstancesTable which generates a list of
|
||||
* md5s for common files search
|
||||
*/
|
||||
private class EamDbAttributeInstanceRowCallback implements InstanceTableCallback {
|
||||
|
||||
CorrelationAttribute correlationAttribute = null;
|
||||
|
||||
@Override
|
||||
public void process(ResultSet resultSet) {
|
||||
try {
|
||||
EamDb DbManager = EamDb.getInstance();
|
||||
CorrelationAttribute.Type fileType = DbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
|
||||
|
||||
while (resultSet.next()) {
|
||||
CorrelationCase correlationCase = DbManager.getCaseByUUID(String.valueOf(InstanceTableCallback.getCaseId(resultSet)));
|
||||
correlationAttribute = DbManager.getCorrelationAttribute(fileType,
|
||||
correlationCase,
|
||||
DbManager.getDataSource(correlationCase, String.valueOf(InstanceTableCallback.getDataSourceId(resultSet))),
|
||||
InstanceTableCallback.getValue(resultSet),
|
||||
InstanceTableCallback.getFilePath(resultSet));
|
||||
|
||||
}
|
||||
} catch (SQLException | EamDbException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
}
|
||||
}
|
||||
|
||||
CorrelationAttribute getCorrelationAttribute() {
|
||||
return correlationAttribute;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user