19package org.sleuthkit.autopsy.coreutils;
22import java.io.IOException;
23import java.sql.Connection;
24import java.sql.DriverManager;
25import java.sql.PreparedStatement;
26import java.sql.ResultSet;
27import java.sql.ResultSetMetaData;
28import java.sql.SQLException;
29import java.util.ArrayList;
31import java.util.Objects;
32import java.util.function.BooleanSupplier;
33import java.util.function.Consumer;
34import java.util.logging.Level;
35import org.sleuthkit.autopsy.casemodule.Case;
36import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
37import org.sleuthkit.autopsy.casemodule.services.FileManager;
38import org.sleuthkit.autopsy.casemodule.services.Services;
39import org.sleuthkit.autopsy.datamodel.ContentUtils;
40import org.sleuthkit.datamodel.AbstractFile;
41import org.sleuthkit.datamodel.SleuthkitCase;
42import org.sleuthkit.datamodel.TskCoreException;
61 private final AbstractFile
file;
71 static <T> Consumer<T> doNothing() {
83 this.forAllColumnNamesConsumer =
Builder.doNothing();
84 this.forAllStringValuesConsumer =
Builder.doNothing();
85 this.forAllLongValuesConsumer =
Builder.doNothing();
86 this.forAllIntegerValuesConsumer =
Builder.doNothing();
87 this.forAllFloatValuesConsumer =
Builder.doNothing();
88 this.forAllBlobValuesConsumer =
Builder.doNothing();
89 this.forAllTableValuesConsumer =
Builder.doNothing();
101 this.forAllColumnNamesConsumer = action;
114 this.forAllStringValuesConsumer = action;
127 this.forAllIntegerValuesConsumer = action;
140 this.forAllFloatValuesConsumer = action;
153 this.forAllLongValuesConsumer = action;
166 this.forAllBlobValuesConsumer = action;
180 this.forAllTableValuesConsumer = action;
195 private final AbstractFile
file;
233 try (ResultSet tableNameResult =
conn.createStatement()
234 .executeQuery(
"SELECT name FROM sqlite_master "
235 +
" WHERE type= 'table' ")) {
236 List<String> tableNames =
new ArrayList<>();
237 while (tableNameResult.next()) {
238 tableNames.add(tableNameResult.getString(
"name"));
241 }
catch (SQLException ex) {
257 try (ResultSet countResult =
conn.createStatement()
258 .executeQuery(
"SELECT count (*) as count FROM "
259 +
"\"" + tableName +
"\"")) {
260 return countResult.getInt(
"count");
261 }
catch (SQLException ex) {
277 try (ResultSet columnCount =
conn.createStatement()
279 return columnCount.getMetaData().getColumnCount();
280 }
catch (SQLException ex) {
314 +
" OFFSET " + offset, () ->
false);
350 if (condition.getAsBoolean()) {
359 if (condition.getAsBoolean()) {
365 if (item instanceof String) {
366 builder.forAllStringValuesConsumer.accept((String) item);
367 }
else if (item instanceof Integer) {
368 builder.forAllIntegerValuesConsumer.accept((Integer) item);
369 }
else if (item instanceof Double) {
370 builder.forAllFloatValuesConsumer.accept((Double) item);
371 }
else if (item instanceof Long) {
372 builder.forAllLongValuesConsumer.accept((Long) item);
373 }
else if (item instanceof
byte[]) {
374 builder.forAllBlobValuesConsumer.accept((
byte[]) item);
377 builder.forAllTableValuesConsumer.accept(item);
384 }
catch (SQLException ex) {
398 if (Objects.isNull(
conn)) {
400 Class.forName(
"org.sqlite.JDBC");
406 conn = DriverManager.getConnection(
"jdbc:sqlite:" + localDiskPath);
408 | ClassNotFoundException | SQLException ex) {
430 if(sqliteFile.getParentPath().equalsIgnoreCase(
"/$carvedfiles/")) {
439 List<AbstractFile> metaFiles = fileManager.
findFilesExactName(sqliteFile.getParent().getId(), metaFileName);
441 if (metaFiles !=
null) {
442 for (AbstractFile metaFile : metaFiles) {
464 + File.separator + fileId +
file.getName();
465 File localDatabaseFile =
new File(localDiskPath);
466 if (!localDatabaseFile.exists()) {
469 return localDiskPath;
487 }
catch (SQLException ex) {
504 }
catch (SQLException ex) {
505 logger.log(Level.SEVERE,
"Failed to close table resources", ex);
517 if (Objects.nonNull(
conn)) {
520 }
catch (SQLException ex) {
544 logger.log(Level.SEVERE,
"Failed to close reader in finalizer", ex);
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()
String getTempDirectory()
List< AbstractFile > findFilesExactName(long parentId, String name)
FileManager getFileManager()
synchronized static Logger getLogger(String name)
Builder forAllBlobValues(Consumer< byte[]> action)
Builder forAllStringValues(Consumer< String > action)
Consumer< Object > forAllTableValuesConsumer
Consumer< Integer > forAllIntegerValuesConsumer
Consumer< Long > forAllLongValuesConsumer
Consumer< String > forAllColumnNamesConsumer
Builder forAllTableValues(Consumer< Object > action)
Builder forAllLongValues(Consumer< Long > action)
Builder forAllColumnNames(Consumer< String > action)
Builder(AbstractFile file)
Consumer< String > forAllStringValuesConsumer
Builder forAllIntegerValues(Consumer< Integer > action)
Consumer< Double > forAllFloatValuesConsumer
SQLiteTableReader build()
Builder forAllFloatValues(Consumer< Double > action)
Consumer< byte[]> forAllBlobValuesConsumer
String copyFileToTempDirectory(AbstractFile file, long fileId)
static final String SELECT_ALL_QUERY
void read(String tableName, int limit, int offset)
PreparedStatement statement
void readHelper(String query, BooleanSupplier condition)
int getColumnCount(String tableName)
List< String > getTableNames()
int getRowCount(String tableName)
void read(String tableName)
ResultSetMetaData currentMetadata
void openTableResources(String query)
void read(String tableName, BooleanSupplier condition)
SQLiteTableReader(Builder builder)
static final Logger logger
void findAndCopySQLiteMetaFile(AbstractFile sqliteFile, String metaFileName)
void closeTableResources()
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)