mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 16:06:15 +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
@ -1782,6 +1782,46 @@ abstract class AbstractSqlEamDb implements EamDb {
|
|||||||
* Process the Artifact instance in the EamDb
|
* Process the Artifact instance in the EamDb
|
||||||
*
|
*
|
||||||
* @param type EamArtifact.Type to search for
|
* @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
|
||||||
|
*
|
||||||
|
* @param type EamArtifact.Type to search for
|
||||||
* @param correlationCase CorrelationCase to filter by
|
* @param correlationCase CorrelationCase to filter by
|
||||||
* @param instanceTableCallback callback to process the instance
|
* @param instanceTableCallback callback to process the instance
|
||||||
* @throws EamDbException
|
* @throws EamDbException
|
||||||
|
@ -686,6 +686,16 @@ public interface EamDb {
|
|||||||
*/
|
*/
|
||||||
void processInstanceTable(CorrelationAttribute.Type type, InstanceTableCallback instanceTableCallback) throws EamDbException;
|
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
|
* Process the Artifact md5s in the EamDb for matches of case files which are not known
|
||||||
* @param type EamArtifact.Type to search for
|
* @param type EamArtifact.Type to search for
|
||||||
@ -693,5 +703,5 @@ public interface EamDb {
|
|||||||
* @param instanceTableCallback callback to process the instance
|
* @param instanceTableCallback callback to process the instance
|
||||||
* @throws EamDbException
|
* @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();
|
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
|
* Process the Artifact md5s in the EamDb for matches of case files which are not known
|
||||||
* @param type EamArtifact.Type to search for
|
* @param type EamArtifact.Type to search for
|
||||||
|
@ -27,13 +27,15 @@ import java.util.logging.Level;
|
|||||||
import org.openide.util.Exceptions;
|
import org.openide.util.Exceptions;
|
||||||
import org.sleuthkit.autopsy.casemodule.Case;
|
import org.sleuthkit.autopsy.casemodule.Case;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute;
|
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.EamDb;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.InstanceTableCallback;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.InstanceTableCallback;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
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 {
|
class EamDbAttributeInstancesAlgorithm {
|
||||||
|
|
||||||
@ -42,12 +44,29 @@ class EamDbAttributeInstancesAlgorithm {
|
|||||||
private final Map<Integer, String> intercaseCommonValuesMap = new HashMap<>();
|
private final Map<Integer, String> intercaseCommonValuesMap = new HashMap<>();
|
||||||
private final Map<Integer, String> intercaseCommonDatasourcesMap = new HashMap<>();
|
private final Map<Integer, String> intercaseCommonDatasourcesMap = new HashMap<>();
|
||||||
|
|
||||||
|
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) {
|
void processCorrelationCaseAttributeValues(Case currentCase) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EamDbAttributeInstancesCallback instancetableCallback = new EamDbAttributeInstancesCallback();
|
EamDbAttributeInstancesCallback instancetableCallback = new EamDbAttributeInstancesCallback();
|
||||||
EamDb DbManager = EamDb.getInstance();
|
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);
|
DbManager.processCaseInstancesTable(fileType, DbManager.getCase(currentCase), instancetableCallback);
|
||||||
|
|
||||||
intercaseCommonValuesMap.putAll(instancetableCallback.getCorrelationIdValueMap());
|
intercaseCommonValuesMap.putAll(instancetableCallback.getCorrelationIdValueMap());
|
||||||
@ -97,4 +116,38 @@ class EamDbAttributeInstancesAlgorithm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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