19 package org.sleuthkit.datamodel;
21 import com.google.common.base.Strings;
22 import java.sql.PreparedStatement;
23 import java.sql.SQLException;
24 import java.sql.Statement;
25 import org.apache.commons.lang3.StringUtils;
26 import java.util.List;
27 import java.util.Arrays;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.Iterator;
31 import java.util.LinkedList;
33 import java.util.Objects;
34 import java.util.Optional;
35 import java.util.Queue;
36 import java.util.logging.Level;
37 import java.util.logging.Logger;
50 class TskCaseDbBridge {
52 private static final Logger logger = Logger.getLogger(TskCaseDbBridge.class.getName());
54 private final SleuthkitCase caseDb;
55 private CaseDbTransaction trans = null;
56 private final AddDataSourceCallbacks addDataSourceCallbacks;
57 private final Host imageHost;
59 private final Map<Long, Long> fsIdToRootDir =
new HashMap<>();
60 private final Map<Long, TskData.TSK_FS_TYPE_ENUM> fsIdToFsType =
new HashMap<>();
61 private final Map<ParentCacheKey, Long> parentDirCache =
new HashMap<>();
63 private final Map<String, OsAccount> ownerIdToAccountMap =
new HashMap<>();
65 private static final long BATCH_FILE_THRESHOLD = 500;
66 private final Queue<FileInfo> batchedFiles =
new LinkedList<>();
67 private final Queue<LayoutRangeInfo> batchedLayoutRanges =
new LinkedList<>();
68 private final List<Long> layoutFileIds =
new ArrayList<>();
69 private final Map<Long, VirtualDirectory> unallocFileDirs =
new HashMap<>();
71 TskCaseDbBridge(SleuthkitCase caseDb, AddDataSourceCallbacks addDataSourceCallbacks, Host host) {
73 this.addDataSourceCallbacks = addDataSourceCallbacks;
83 private void beginTransaction() throws TskCoreException {
84 trans = caseDb.beginTransaction();
92 private void commitTransaction() throws TskCoreException {
100 private void revertTransaction() {
106 }
catch (TskCoreException ex) {
107 logger.log(Level.SEVERE,
"Error rolling back transaction", ex);
115 addBatchedFilesToDb();
116 addBatchedLayoutRangesToDb();
117 processLayoutFiles();
139 long addImageInfo(
int type,
long ssize, String timezone,
140 long size, String md5, String sha1, String sha256, String deviceId,
141 String collectionDetails, String[] paths) {
144 long objId = addImageToDb(TskData.TSK_IMG_TYPE_ENUM.valueOf(type), ssize, size,
145 timezone, md5, sha1, sha256, deviceId, collectionDetails, trans);
146 for (
int i = 0;i < paths.length;i++) {
147 addImageNameToDb(objId, paths[i], i, trans);
151 }
catch (TskCoreException ex) {
152 logger.log(Level.SEVERE,
"Error adding image to the database", ex);
164 void addAcquisitionDetails(
long imgId, String details) {
167 caseDb.setAcquisitionDetails(imgId, details, trans);
169 }
catch (TskCoreException ex) {
170 logger.log(Level.SEVERE,
"Error adding image details \"" + details +
"\" to image with ID " + imgId, ex);
186 long addVsInfo(
long parentObjId,
int vsType,
long imgOffset,
long blockSize) {
189 VolumeSystem vs = caseDb.addVolumeSystem(parentObjId, TskData.TSK_VS_TYPE_ENUM.valueOf(vsType), imgOffset, blockSize, trans);
192 }
catch (TskCoreException ex) {
193 logger.log(Level.SEVERE,
"Error adding volume system to the database - parent obj ID: " + parentObjId
194 +
", image offset: " + imgOffset, ex);
213 long addVolume(
long parentObjId,
long addr,
long start,
long length, String desc,
217 Volume vol = caseDb.addVolume(parentObjId, addr, start, length, desc, flags, trans);
220 }
catch (TskCoreException ex) {
221 logger.log(Level.SEVERE,
"Error adding volume to the database - parent object ID: " + parentObjId
222 +
", addr: " + addr, ex);
237 long addPool(
long parentObjId,
int poolType) {
240 Pool pool = caseDb.addPool(parentObjId, TskData.TSK_POOL_TYPE_ENUM.valueOf(poolType), trans);
243 }
catch (TskCoreException ex) {
244 logger.log(Level.SEVERE,
"Error adding pool to the database - parent object ID: " + parentObjId, ex);
265 long addFileSystem(
long parentObjId,
long imgOffset,
int fsType,
long blockSize,
long blockCount,
266 long rootInum,
long firstInum,
long lastInum) {
269 FileSystem fs = caseDb.addFileSystem(parentObjId, imgOffset, TskData.TSK_FS_TYPE_ENUM.valueOf(fsType), blockSize, blockCount,
270 rootInum, firstInum, lastInum, null, trans);
272 fsIdToFsType.put(fs.getId(), TskData.TSK_FS_TYPE_ENUM.valueOf(fsType));
274 }
catch (TskCoreException ex) {
275 logger.log(Level.SEVERE,
"Error adding file system to the database - parent object ID: " + parentObjId
276 +
", offset: " + imgOffset, ex);
323 long addFile(
long parentObjId,
324 long fsObjId,
long dataSourceObjId,
326 int attrType,
int attrId, String name,
327 long metaAddr,
long metaSeq,
328 int dirType,
int metaType,
int dirFlags,
int metaFlags,
330 long crtime,
long ctime,
long atime,
long mtime,
331 int meta_mode,
int gid,
int uid,
332 String escaped_path, String extension,
333 long seq,
long parMetaAddr,
long parSeq, String ownerUid) {
336 batchedFiles.add(
new FileInfo(parentObjId,
337 fsObjId, dataSourceObjId,
339 attrType, attrId, name,
341 dirType, metaType, dirFlags, metaFlags,
343 crtime, ctime, atime, mtime,
345 escaped_path, extension,
346 seq, parMetaAddr, parSeq, ownerUid));
350 if ((fsObjId == parentObjId)
351 || (batchedFiles.size() > BATCH_FILE_THRESHOLD)) {
352 return addBatchedFilesToDb();
362 private long addBatchedFilesToDb() {
363 List<Long> newObjIds =
new ArrayList<>();
368 Iterator<FileInfo> it = batchedFiles.iterator();
370 while (it.hasNext()) {
371 FileInfo fileInfo = it.next();
372 String ownerUid = fileInfo.ownerUid;
373 if (Strings.isNullOrEmpty(fileInfo.ownerUid) ==
false) {
375 if (this.ownerIdToAccountMap.containsKey(ownerUid)) {
381 Optional<OsAccount> ownerAccount = caseDb.getOsAccountManager().getWindowsOsAccount(ownerUid, null, null, imageHost);
382 if (ownerAccount.isPresent()) {
384 ownerIdToAccountMap.put(ownerUid, ownerAccount.get());
388 OsAccountManager accountMgr = caseDb.getOsAccountManager();
389 OsAccount newAccount = accountMgr.newWindowsOsAccount(ownerUid, null, null, imageHost, OsAccountRealm.RealmScope.UNKNOWN);
390 Content ds = caseDb.getContentById(fileInfo.dataSourceObjId);
391 if (ds instanceof DataSource) {
392 accountMgr.newOsAccountInstance(newAccount, (DataSource)ds, OsAccountInstance.OsAccountInstanceType.ACCESSED);
394 ownerIdToAccountMap.put(ownerUid, newAccount);
396 }
catch (NotUserSIDException ex) {
398 ownerIdToAccountMap.put(ownerUid, null);
407 while ((fileInfo = batchedFiles.poll()) != null) {
408 long computedParentObjId = fileInfo.parentObjId;
411 if (fileInfo.parentObjId == 0) {
412 computedParentObjId = getParentObjId(fileInfo);
415 Long ownerAccountObjId = OsAccount.NO_ACCOUNT;
416 if (Strings.isNullOrEmpty(fileInfo.ownerUid) ==
false) {
417 if (ownerIdToAccountMap.containsKey(fileInfo.ownerUid)) {
419 if (Objects.nonNull(ownerIdToAccountMap.get(fileInfo.ownerUid))) {
420 ownerAccountObjId = ownerIdToAccountMap.get(fileInfo.ownerUid).getId();
424 throw new TskCoreException(String.format(
"Failed to add file. Owner account not found for file with parent object ID: %d, name: %s, owner id: %s", fileInfo.parentObjId, fileInfo.name, fileInfo.ownerUid));
432 if ((fileInfo.parentObjId == fileInfo.fsObjId)
433 && (fileInfo.metaType != TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue())) {
434 fileInfo.metaType = TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue();
437 long objId = addFileToDb(computedParentObjId,
438 fileInfo.fsObjId, fileInfo.dataSourceObjId,
440 fileInfo.attrType, fileInfo.attrId, fileInfo.name,
441 fileInfo.metaAddr, fileInfo.metaSeq,
442 fileInfo.dirType, fileInfo.metaType, fileInfo.dirFlags, fileInfo.metaFlags,
444 fileInfo.crtime, fileInfo.ctime, fileInfo.atime, fileInfo.mtime,
445 fileInfo.meta_mode, fileInfo.gid, fileInfo.uid,
446 null, TskData.FileKnown.UNKNOWN,
447 fileInfo.escaped_path, fileInfo.extension, fileInfo.ownerUid, ownerAccountObjId,
449 if (fileInfo.fsObjId != fileInfo.parentObjId) {
451 newObjIds.add(objId);
455 if (fileInfo.parentObjId == fileInfo.fsObjId) {
456 fsIdToRootDir.put(fileInfo.fsObjId, objId);
460 if ((fileInfo.metaType == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue()
461 || (fileInfo.metaType == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR.getValue()))
462 && (fileInfo.name != null)
463 && ! fileInfo.name.equals(
".")
464 && ! fileInfo.name.equals(
"..")) {
465 String dirName = fileInfo.escaped_path + fileInfo.name;
466 ParentCacheKey key =
new ParentCacheKey(fileInfo.fsObjId, fileInfo.metaAddr, fileInfo.seq, dirName);
467 parentDirCache.put(key, objId);
469 }
catch (TskCoreException ex) {
470 if (computedParentObjId > 0) {
472 logger.log(Level.SEVERE,
"Error adding file to the database - parent object ID: " + computedParentObjId
473 +
", file system object ID: " + fileInfo.fsObjId +
", name: " + fileInfo.name, ex);
476 logger.log(Level.SEVERE,
"Error adding file to the database", ex);
482 addDataSourceCallbacks.onFilesAdded(newObjIds);
483 }
catch (Exception ex) {
485 logger.log(Level.SEVERE,
"Unexpected error from files added callback", ex);
487 }
catch (TskCoreException ex) {
488 logger.log(Level.SEVERE,
"Error adding batched files to database", ex);
504 private long getParentObjId(FileInfo fileInfo)
throws TskCoreException {
506 String parentPath = fileInfo.escaped_path;
507 if(parentPath.endsWith(
"/") && ! parentPath.equals(
"/")) {
508 parentPath = parentPath.substring(0, parentPath.lastIndexOf(
'/'));
512 ParentCacheKey key =
new ParentCacheKey(fileInfo.fsObjId, fileInfo.parMetaAddr, fileInfo.parSeq, parentPath);
513 if (parentDirCache.containsKey(key)) {
514 return parentDirCache.get(key);
518 throw new TskCoreException(
"Could not find parent (fsObjId: " +fileInfo.fsObjId +
", parMetaAddr: " + fileInfo.parMetaAddr
519 +
", parSeq: " + fileInfo.parSeq +
", parentPath: " + parentPath +
")");
536 long addLayoutFile(
long parentObjId,
537 long fsObjId,
long dataSourceObjId,
539 String name,
long size) {
543 Long fsObjIdForDb = fsObjId;
549 String parentPath =
"/";
550 if (unallocFileDirs.containsKey(parentObjId)) {
551 parentPath =
"/" + unallocFileDirs.get(parentObjId).getName() +
"/";
555 long objId = addFileToDb(parentObjId,
556 fsObjIdForDb, dataSourceObjId,
560 TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue(),
561 TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getValue(),
562 TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue(),
563 TskData.TSK_FS_META_FLAG_ENUM.UNALLOC.getValue(),
565 null, null, null, null,
567 null, TskData.FileKnown.UNKNOWN,
568 parentPath, null, null, OsAccount.NO_ACCOUNT,
573 layoutFileIds.add(objId);
576 }
catch (TskCoreException ex) {
577 logger.log(Level.SEVERE,
"Error adding layout file to the database - parent object ID: " + parentObjId
578 +
", file system object ID: " + fsObjId +
", name: " + name, ex);
595 long addLayoutFileRange(
long objId,
long byteStart,
long byteLen,
long seq) {
596 batchedLayoutRanges.add(
new LayoutRangeInfo(objId, byteStart, byteLen, seq));
598 if (batchedLayoutRanges.size() > BATCH_FILE_THRESHOLD) {
599 return addBatchedLayoutRangesToDb();
609 private long addBatchedLayoutRangesToDb() {
612 LayoutRangeInfo range;
613 while ((range = batchedLayoutRanges.poll()) != null) {
615 addLayoutFileRangeToDb(range.objId, range.byteStart, range.byteLen, range.seq, trans);
616 }
catch (TskCoreException ex) {
617 logger.log(Level.SEVERE,
"Error adding layout file range to the database - layout file ID: " + range.objId
618 +
", byte start: " + range.byteStart +
", length: " + range.byteLen +
", seq: " + range.seq, ex);
623 }
catch (TskCoreException ex) {
624 logger.log(Level.SEVERE,
"Error adding batched files to database", ex);
635 void processLayoutFiles() {
636 addDataSourceCallbacks.onFilesAdded(layoutFileIds);
637 layoutFileIds.clear();
649 long addUnallocFsBlockFilesParent(
long fsObjId, String name) {
651 if (! fsIdToRootDir.containsKey(fsObjId)) {
652 logger.log(Level.SEVERE,
"Error - root directory for file system ID {0} not found", fsObjId);
656 VirtualDirectory dir = caseDb.addVirtualDirectory(fsIdToRootDir.get(fsObjId), name, trans);
658 unallocFileDirs.put(dir.getId(), dir);
659 addDataSourceCallbacks.onFilesAdded(Arrays.asList(dir.getId()));
661 }
catch (TskCoreException ex) {
662 logger.log(Level.SEVERE,
"Error creating virtual directory " + name +
" under file system ID " + fsObjId, ex);
671 private class ParentCacheKey {
686 ParentCacheKey(
long fsObjId,
long metaAddr,
long seqNum, String path) {
687 this.fsObjId = fsObjId;
688 this.metaAddr = metaAddr;
689 if (ownerIdToAccountMap.containsKey(fsObjId)
690 && (ownerIdToAccountMap.get(fsObjId).equals(TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_NTFS)
691 || ownerIdToAccountMap.get(fsObjId).equals(TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_NTFS_DETECT))) {
692 this.seqNum = seqNum;
700 public boolean equals(Object obj) {
701 if (! (obj instanceof ParentCacheKey)) {
705 ParentCacheKey otherKey = (ParentCacheKey) obj;
706 if (this.fsObjId != otherKey.fsObjId
707 ||
this.metaAddr != otherKey.metaAddr
708 ||
this.seqNum != otherKey.seqNum) {
712 return StringUtils.equals(this.path, otherKey.path);
716 public int hashCode() {
718 hash = 31 * hash + (int) (this.fsObjId ^ (this.fsObjId >>> 32));
719 hash = 31 * hash + (int) (this.metaAddr ^ (this.metaAddr >>> 32));
720 hash = 31 * hash + (int) (this.seqNum ^ (this.seqNum >>> 32));
721 hash = 31 * hash + Objects.hashCode(this.path);
730 private class LayoutRangeInfo {
736 LayoutRangeInfo(
long objId,
long byteStart,
long byteLen,
long seq) {
738 this.byteStart = byteStart;
739 this.byteLen = byteLen;
748 private class FileInfo {
751 long dataSourceObjId;
777 FileInfo(
long parentObjId,
778 long fsObjId,
long dataSourceObjId,
780 int attrType,
int attrId, String name,
781 long metaAddr,
long metaSeq,
782 int dirType,
int metaType,
int dirFlags,
int metaFlags,
784 long crtime,
long ctime,
long atime,
long mtime,
785 int meta_mode,
int gid,
int uid,
786 String escaped_path, String extension,
787 long seq,
long parMetaAddr,
long parSeq, String ownerUid) {
789 this.parentObjId = parentObjId;
790 this.fsObjId = fsObjId;
791 this.dataSourceObjId = dataSourceObjId;
792 this.fsType = fsType;
793 this.attrType = attrType;
794 this.attrId = attrId;
796 this.metaAddr = metaAddr;
797 this.metaSeq = metaSeq;
798 this.dirType = dirType;
799 this.metaType = metaType;
800 this.dirFlags = dirFlags;
801 this.metaFlags = metaFlags;
803 this.crtime = crtime;
807 this.meta_mode = meta_mode;
810 this.escaped_path = escaped_path;
811 this.extension = extension;
813 this.parMetaAddr = parMetaAddr;
814 this.parSeq = parSeq;
815 this.ownerUid = ownerUid;
862 private long addFileToDb(
long parentObjId,
863 Long fsObjId,
long dataSourceObjId,
865 Integer attrType, Integer attrId, String name,
866 Long metaAddr, Long metaSeq,
867 int dirType,
int metaType,
int dirFlags,
int metaFlags,
869 Long crtime, Long ctime, Long atime, Long mtime,
870 Integer meta_mode, Integer gid, Integer uid,
871 String md5, TskData.FileKnown known,
872 String escaped_path, String extension, String ownerUid, Long ownerAcctObjId,
873 boolean hasLayout, CaseDbTransaction transaction)
throws TskCoreException {
876 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
880 long objectId = caseDb.addObject(parentObjId, TskData.ObjectType.ABSTRACTFILE.getObjectType(), connection);
882 String fileInsert =
"INSERT INTO tsk_files (fs_obj_id, obj_id, data_source_obj_id, type, attr_type, attr_id, name, meta_addr, meta_seq, dir_type, meta_type, dir_flags, meta_flags, size, crtime, ctime, atime, mtime, mode, gid, uid, md5, known, parent_path, extension, has_layout, owner_uid, os_account_obj_id)"
883 +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
884 PreparedStatement preparedStatement = connection.getPreparedStatement(fileInsert, Statement.NO_GENERATED_KEYS);
885 preparedStatement.clearParameters();
887 if (fsObjId != null) {
888 preparedStatement.setLong(1, fsObjId);
890 preparedStatement.setNull(1, java.sql.Types.BIGINT);
892 preparedStatement.setLong(2, objectId);
893 preparedStatement.setLong(3, dataSourceObjId);
894 preparedStatement.setShort(4, (
short) fsType);
895 if (attrType != null) {
896 preparedStatement.setShort(5, attrType.shortValue());
898 preparedStatement.setNull(5, java.sql.Types.SMALLINT);
900 if (attrId != null) {
901 preparedStatement.setInt(6, attrId);
903 preparedStatement.setNull(6, java.sql.Types.INTEGER);
905 preparedStatement.setString(7, name);
906 if (metaAddr != null) {
907 preparedStatement.setLong(8, metaAddr);
909 preparedStatement.setNull(8, java.sql.Types.BIGINT);
911 if (metaSeq != null) {
912 preparedStatement.setInt(9, metaSeq.intValue());
914 preparedStatement.setNull(9, java.sql.Types.INTEGER);
916 preparedStatement.setShort(10, (
short) dirType);
917 preparedStatement.setShort(11, (
short) metaType);
918 preparedStatement.setShort(12, (
short) dirFlags);
919 preparedStatement.setShort(13, (
short) metaFlags);
920 preparedStatement.setLong(14, size < 0 ? 0 : size);
921 if (crtime != null) {
922 preparedStatement.setLong(15, crtime);
924 preparedStatement.setNull(15, java.sql.Types.BIGINT);
927 preparedStatement.setLong(16, ctime);
929 preparedStatement.setNull(16, java.sql.Types.BIGINT);
932 preparedStatement.setLong(17, atime);
934 preparedStatement.setNull(17, java.sql.Types.BIGINT);
937 preparedStatement.setLong(18, mtime);
939 preparedStatement.setNull(18, java.sql.Types.BIGINT);
941 if (meta_mode != null) {
942 preparedStatement.setLong(19, meta_mode);
944 preparedStatement.setNull(19, java.sql.Types.BIGINT);
947 preparedStatement.setLong(20, gid);
949 preparedStatement.setNull(20, java.sql.Types.BIGINT);
952 preparedStatement.setLong(21, uid);
954 preparedStatement.setNull(21, java.sql.Types.BIGINT);
956 preparedStatement.setString(22, md5);
957 preparedStatement.setInt(23, known.getFileKnownValue());
958 preparedStatement.setString(24, escaped_path);
959 preparedStatement.setString(25, extension);
961 preparedStatement.setInt(26, 1);
963 preparedStatement.setNull(26, java.sql.Types.INTEGER);
966 preparedStatement.setString(27, ownerUid);
968 if (ownerAcctObjId != OsAccount.NO_ACCOUNT) {
969 preparedStatement.setLong(28, ownerAcctObjId);
971 preparedStatement.setNull(28, java.sql.Types.BIGINT);
974 connection.executeUpdate(preparedStatement);
978 && TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.getFileType() != fsType
979 && (!name.equals(
".")) && (!name.equals(
".."))) {
980 TimelineManager timelineManager = caseDb.getTimelineManager();
981 DerivedFile derivedFile =
new DerivedFile(caseDb, objectId, dataSourceObjId, fsObjId, name,
982 TskData.TSK_FS_NAME_TYPE_ENUM.valueOf((
short) dirType),
983 TskData.TSK_FS_META_TYPE_ENUM.valueOf((
short) metaType),
984 TskData.TSK_FS_NAME_FLAG_ENUM.valueOf(dirFlags),
986 size, ctime, crtime, atime, mtime, null, null, null, null, escaped_path, null, parentObjId, null, null, extension, ownerUid, ownerAcctObjId);
988 timelineManager.addEventsForNewFileQuiet(derivedFile, connection);
992 }
catch (SQLException ex) {
993 throw new TskCoreException(
"Failed to add file system file", ex);
1016 private long addImageToDb(TskData.TSK_IMG_TYPE_ENUM type,
long sectorSize,
long size,
1017 String timezone, String md5, String sha1, String sha256,
1018 String deviceId, String collectionDetails,
1019 CaseDbTransaction transaction)
throws TskCoreException {
1022 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1023 long newObjId = caseDb.addObject(0, TskData.ObjectType.IMG.getObjectType(), connection);
1027 String imageInfoSql =
"INSERT INTO tsk_image_info (obj_id, type, ssize, tzone, size, md5, sha1, sha256, display_name)"
1028 +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
1029 PreparedStatement preparedStatement = connection.getPreparedStatement(imageInfoSql, Statement.NO_GENERATED_KEYS);
1030 preparedStatement.clearParameters();
1031 preparedStatement.setLong(1, newObjId);
1032 preparedStatement.setShort(2, (
short) type.getValue());
1033 preparedStatement.setLong(3, sectorSize);
1034 preparedStatement.setString(4, timezone);
1036 long savedSize = size < 0 ? 0 : size;
1037 preparedStatement.setLong(5, savedSize);
1038 preparedStatement.setString(6, md5);
1039 preparedStatement.setString(7, sha1);
1040 preparedStatement.setString(8, sha256);
1041 preparedStatement.setString(9, null);
1042 connection.executeUpdate(preparedStatement);
1045 String dataSourceInfoSql =
"INSERT INTO data_source_info (obj_id, device_id, time_zone, acquisition_details, host_id) VALUES (?, ?, ?, ?, ?)";
1046 preparedStatement = connection.getPreparedStatement(dataSourceInfoSql, Statement.NO_GENERATED_KEYS);
1047 preparedStatement.clearParameters();
1048 preparedStatement.setLong(1, newObjId);
1049 preparedStatement.setString(2, deviceId);
1050 preparedStatement.setString(3, timezone);
1051 preparedStatement.setString(4, collectionDetails);
1052 preparedStatement.setLong(5, imageHost.getHostId());
1053 connection.executeUpdate(preparedStatement);
1056 }
catch (SQLException ex) {
1057 throw new TskCoreException(String.format(
"Error adding image to database"), ex);
1071 private void addImageNameToDb(
long objId, String name,
long sequence,
1072 CaseDbTransaction transaction)
throws TskCoreException {
1074 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1076 String imageNameSql =
"INSERT INTO tsk_image_names (obj_id, name, sequence) VALUES (?, ?, ?)";
1077 PreparedStatement preparedStatement = connection.getPreparedStatement(imageNameSql, Statement.NO_GENERATED_KEYS);
1078 preparedStatement.clearParameters();
1079 preparedStatement.setLong(1, objId);
1080 preparedStatement.setString(2, name);
1081 preparedStatement.setLong(3, sequence);
1082 connection.executeUpdate(preparedStatement);
1083 }
catch (SQLException ex) {
1084 throw new TskCoreException(String.format(
"Error adding image name %s to image with object ID %d", name, objId), ex);
1099 void addLayoutFileRangeToDb(
long objId,
long byteStart,
long byteLen,
1100 long seq, CaseDbTransaction transaction)
throws TskCoreException {
1102 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1104 String insertRangeSql =
"INSERT INTO tsk_file_layout (obj_id, byte_start, byte_len, sequence) "
1105 +
"VALUES (?, ?, ?, ?)";
1106 PreparedStatement preparedStatement = connection.getPreparedStatement(insertRangeSql, Statement.NO_GENERATED_KEYS);
1107 preparedStatement.clearParameters();
1108 preparedStatement.setLong(1, objId);
1109 preparedStatement.setLong(2, byteStart);
1110 preparedStatement.setLong(3, byteLen);
1111 preparedStatement.setLong(4, seq);
1112 connection.executeUpdate(preparedStatement);
1113 }
catch (SQLException ex) {
1114 throw new TskCoreException(
"Error adding layout range to file with obj ID " + objId, ex);