commenting, formatting, and imports

This commit is contained in:
Greg DiCristofaro 2020-08-07 14:15:46 -04:00
parent 59430a06af
commit f56b66a8ed
2 changed files with 107 additions and 66 deletions

View File

@ -19,13 +19,10 @@
package org.sleuthkit.autopsy.casemodule.datasourcesummary; package org.sleuthkit.autopsy.casemodule.datasourcesummary;
import java.io.File; import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
@ -37,12 +34,8 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import org.apache.commons.lang3.tuple.Pair;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
@ -61,7 +54,6 @@ final class DataSourceInfoUtilities {
private static final Logger logger = Logger.getLogger(DataSourceInfoUtilities.class.getName()); private static final Logger logger = Logger.getLogger(DataSourceInfoUtilities.class.getName());
/** /**
* Gets a count of files for a particular datasource where it is not a * Gets a count of files for a particular datasource where it is not a
* virtual directory and has a name. * virtual directory and has a name.
@ -276,6 +268,7 @@ final class DataSourceInfoUtilities {
/** /**
* Main constructor. * Main constructor.
*
* @param programName The name of the program. * @param programName The name of the program.
* @param programPath The path of the program. * @param programPath The path of the program.
* @param runTimes The number of runs. * @param runTimes The number of runs.
@ -316,7 +309,9 @@ final class DataSourceInfoUtilities {
} }
} }
/**
* A SQL join type.
*/
private enum JoinType { private enum JoinType {
LEFT, LEFT,
RIGHT, RIGHT,
@ -324,32 +319,68 @@ final class DataSourceInfoUtilities {
OUTER OUTER
} }
/**
* A blackboard attribute value column.
*/
private enum AttributeColumn { private enum AttributeColumn {
value_text, value_text,
value_int32, value_int32,
value_int64 value_int64
} }
/**
* The suffix joined to a key name for use as an identifier of a query.
*/
private static final String QUERY_SUFFIX = "_query"; private static final String QUERY_SUFFIX = "_query";
/**
* Creates a sql statement querying the blackboard attributes table for a
* particular attribute type and returning a specified value. That query
* also joins with the blackboard artifact table.
*
* @param joinType The type of join statement to create.
* @param attributeColumn The blackboard attribute column that should be
* returned.
* @param attrType The attribute type to query for.
* @param keyName The aliased name of the attribute to return. This
* is also used to calculate the alias of the query
* same as getFullKey.
* @param bbaName The blackboard artifact table alias.
*
* @return The generated sql statement.
*/
private static String getAttributeJoin(JoinType joinType, AttributeColumn attributeColumn, ATTRIBUTE_TYPE attrType, String keyName, String bbaName) { private static String getAttributeJoin(JoinType joinType, AttributeColumn attributeColumn, ATTRIBUTE_TYPE attrType, String keyName, String bbaName) {
String queryName = keyName + QUERY_SUFFIX; String queryName = keyName + QUERY_SUFFIX;
String innerQueryName = "inner_attribute_" + queryName; String innerQueryName = "inner_attribute_" + queryName;
return return "\n" + joinType + " JOIN (\n"
"\n" + joinType + " JOIN (\n" + + " SELECT \n"
" SELECT \n" + + " " + innerQueryName + ".artifact_id,\n"
" " + innerQueryName + ".artifact_id,\n" + + " " + innerQueryName + "." + attributeColumn + " AS " + keyName + "\n"
" " + innerQueryName + "." + attributeColumn + " AS " + keyName + "\n" + + " FROM blackboard_attributes " + innerQueryName + "\n"
" FROM blackboard_attributes " + innerQueryName + "\n" + + " WHERE " + innerQueryName + ".attribute_type_id = " + attrType.getTypeID() + " -- " + attrType.name() + "\n"
" WHERE " + innerQueryName + ".attribute_type_id = " + attrType.getTypeID() + " -- " + attrType.name() + "\n" + + ") " + queryName + " ON " + queryName + ".artifact_id = " + bbaName + ".artifact_id\n";
") " + queryName + " ON " + queryName + ".artifact_id = " + bbaName + ".artifact_id\n";
} }
/**
* Given a column key, creates the full name for the column key.
*
* @param key The column key.
*
* @return The full identifier for the column key.
*/
private static String getFullKey(String key) { private static String getFullKey(String key) {
return key + QUERY_SUFFIX + "." + key; return key + QUERY_SUFFIX + "." + key;
} }
/**
* Constructs a SQL 'where' statement from a list of clauses and puts
* parenthesis around each clause.
*
* @param clauses The clauses
*
* @return The generated 'where' statement.
*/
private static String getWhereString(List<String> clauses) { private static String getWhereString(List<String> clauses) {
if (clauses.size() <= 0) { if (clauses.size() <= 0) {
return ""; return "";
@ -362,11 +393,19 @@ final class DataSourceInfoUtilities {
return "\nWHERE " + String.join("\n AND ", parenthesized) + "\n"; return "\nWHERE " + String.join("\n AND ", parenthesized) + "\n";
} }
/**
* Generates a [column] LIKE sql clause.
*
* @param column The column identifier.
* @param likeString The string that will be used as column comparison.
* @param isLike if false, the statement becomes NOT LIKE.
*
* @return The generated statement.
*/
private static String getLikeClause(String column, String likeString, boolean isLike) { private static String getLikeClause(String column, String likeString, boolean isLike) {
return column + (isLike ? "" : " NOT") + " LIKE '" + likeString + "'"; return column + (isLike ? "" : " NOT") + " LIKE '" + likeString + "'";
} }
/** /**
* Retrieves a list of the top programs used on the data source. Currently * Retrieves a list of the top programs used on the data source. Currently
* determines this based off of which prefetch results return the highest * determines this based off of which prefetch results return the highest
@ -456,10 +495,9 @@ final class DataSourceInfoUtilities {
return getBaseQueryResult(query, handler, errorMessage); return getBaseQueryResult(query, handler, errorMessage);
} }
/** /**
* Functions that determine the folder name of a list of path elements. If not matched, function returns null. * Functions that determine the folder name of a list of path elements. If
* not matched, function returns null.
*/ */
private static final List<Function<List<String>, String>> SHORT_FOLDER_MATCHERS = Arrays.asList( private static final List<Function<List<String>, String>> SHORT_FOLDER_MATCHERS = Arrays.asList(
// handle Program Files and Program Files (x86) - if true, return the next folder // handle Program Files and Program Files (x86) - if true, return the next folder
@ -489,7 +527,9 @@ final class DataSourceInfoUtilities {
/** /**
* Determines a short folder name if any. Otherwise, returns empty string. * Determines a short folder name if any. Otherwise, returns empty string.
*
* @param strPath The string path. * @param strPath The string path.
*
* @return The short folder name or empty string if not found. * @return The short folder name or empty string if not found.
*/ */
static String getShortFolderName(String strPath, String applicationName) { static String getShortFolderName(String strPath, String applicationName) {

View File

@ -44,6 +44,7 @@ import org.sleuthkit.datamodel.DataSource;
"DataSourceSummaryUserActivityPanel_TopProgramsTableModel_lastrun_header=Last Run" "DataSourceSummaryUserActivityPanel_TopProgramsTableModel_lastrun_header=Last Run"
}) })
public class DataSourceSummaryUserActivityPanel extends javax.swing.JPanel { public class DataSourceSummaryUserActivityPanel extends javax.swing.JPanel {
private static final DateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); private static final DateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
private static final int TOP_PROGS_COUNT = 10; private static final int TOP_PROGS_COUNT = 10;
private static final DefaultTableCellRenderer RIGHT_ALIGNED_RENDERER = new DefaultTableCellRenderer(); private static final DefaultTableCellRenderer RIGHT_ALIGNED_RENDERER = new DefaultTableCellRenderer();