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<>();
70 TskCaseDbBridge(SleuthkitCase caseDb, AddDataSourceCallbacks addDataSourceCallbacks, Host host) {
72 this.addDataSourceCallbacks = addDataSourceCallbacks;
82 private void beginTransaction() throws TskCoreException {
83 trans = caseDb.beginTransaction();
91 private void commitTransaction() throws TskCoreException {
99 private void revertTransaction() {
105 }
catch (TskCoreException ex) {
106 logger.log(Level.SEVERE,
"Error rolling back transaction", ex);
114 addBatchedFilesToDb();
115 addBatchedLayoutRangesToDb();
116 processLayoutFiles();
138 long addImageInfo(
int type,
long ssize, String timezone,
139 long size, String md5, String sha1, String sha256, String deviceId,
140 String collectionDetails, String[] paths) {
143 long objId = addImageToDb(TskData.TSK_IMG_TYPE_ENUM.valueOf(type), ssize, size,
144 timezone, md5, sha1, sha256, deviceId, collectionDetails, trans);
145 for (
int i = 0;i < paths.length;i++) {
146 addImageNameToDb(objId, paths[i], i, trans);
150 }
catch (TskCoreException ex) {
151 logger.log(Level.SEVERE,
"Error adding image to the database", ex);
163 void addAcquisitionDetails(
long imgId, String details) {
166 caseDb.setAcquisitionDetails(imgId, details, trans);
168 }
catch (TskCoreException ex) {
169 logger.log(Level.SEVERE,
"Error adding image details \"" + details +
"\" to image with ID " + imgId, ex);
185 long addVsInfo(
long parentObjId,
int vsType,
long imgOffset,
long blockSize) {
188 VolumeSystem vs = caseDb.addVolumeSystem(parentObjId, TskData.TSK_VS_TYPE_ENUM.valueOf(vsType), imgOffset, blockSize, trans);
191 }
catch (TskCoreException ex) {
192 logger.log(Level.SEVERE,
"Error adding volume system to the database - parent obj ID: " + parentObjId
193 +
", image offset: " + imgOffset, ex);
212 long addVolume(
long parentObjId,
long addr,
long start,
long length, String desc,
216 Volume vol = caseDb.addVolume(parentObjId, addr, start, length, desc, flags, trans);
219 }
catch (TskCoreException ex) {
220 logger.log(Level.SEVERE,
"Error adding volume to the database - parent object ID: " + parentObjId
221 +
", addr: " + addr, ex);
236 long addPool(
long parentObjId,
int poolType) {
239 Pool pool = caseDb.addPool(parentObjId, TskData.TSK_POOL_TYPE_ENUM.valueOf(poolType), trans);
242 }
catch (TskCoreException ex) {
243 logger.log(Level.SEVERE,
"Error adding pool to the database - parent object ID: " + parentObjId, ex);
264 long addFileSystem(
long parentObjId,
long imgOffset,
int fsType,
long blockSize,
long blockCount,
265 long rootInum,
long firstInum,
long lastInum) {
268 FileSystem fs = caseDb.addFileSystem(parentObjId, imgOffset, TskData.TSK_FS_TYPE_ENUM.valueOf(fsType), blockSize, blockCount,
269 rootInum, firstInum, lastInum, null, trans);
271 fsIdToFsType.put(fs.getId(), TskData.TSK_FS_TYPE_ENUM.valueOf(fsType));
273 }
catch (TskCoreException ex) {
274 logger.log(Level.SEVERE,
"Error adding file system to the database - parent object ID: " + parentObjId
275 +
", offset: " + imgOffset, ex);
322 long addFile(
long parentObjId,
323 long fsObjId,
long dataSourceObjId,
325 int attrType,
int attrId, String name,
326 long metaAddr,
long metaSeq,
327 int dirType,
int metaType,
int dirFlags,
int metaFlags,
329 long crtime,
long ctime,
long atime,
long mtime,
330 int meta_mode,
int gid,
int uid,
331 String escaped_path, String extension,
332 long seq,
long parMetaAddr,
long parSeq, String ownerUid) {
335 batchedFiles.add(
new FileInfo(parentObjId,
336 fsObjId, dataSourceObjId,
338 attrType, attrId, name,
340 dirType, metaType, dirFlags, metaFlags,
342 crtime, ctime, atime, mtime,
344 escaped_path, extension,
345 seq, parMetaAddr, parSeq, ownerUid));
349 if ((fsObjId == parentObjId)
350 || (batchedFiles.size() > BATCH_FILE_THRESHOLD)) {
351 return addBatchedFilesToDb();
361 private long addBatchedFilesToDb() {
362 List<Long> newObjIds =
new ArrayList<>();
367 Iterator<FileInfo> it = batchedFiles.iterator();
369 while (it.hasNext()) {
370 FileInfo fileInfo = it.next();
371 String ownerUid = fileInfo.ownerUid;
372 if (Strings.isNullOrEmpty(fileInfo.ownerUid) ==
false) {
374 if (this.ownerIdToAccountMap.containsKey(ownerUid)) {
380 Optional<OsAccount> ownerAccount = caseDb.getOsAccountManager().getWindowsOsAccount(ownerUid, null, null, imageHost);
381 if (ownerAccount.isPresent()) {
383 ownerIdToAccountMap.put(ownerUid, ownerAccount.get());
387 OsAccount newAccount = caseDb.getOsAccountManager().newWindowsOsAccount(ownerUid, null, null, imageHost, OsAccountRealm.RealmScope.UNKNOWN);
388 ownerIdToAccountMap.put(ownerUid, newAccount);
390 }
catch (NotUserSIDException ex) {
392 ownerIdToAccountMap.put(ownerUid, null);
401 while ((fileInfo = batchedFiles.poll()) != null) {
402 long computedParentObjId = fileInfo.parentObjId;
405 if (fileInfo.parentObjId == 0) {
406 computedParentObjId = getParentObjId(fileInfo);
409 Long ownerAccountObjId = OsAccount.NO_ACCOUNT;
410 if (Strings.isNullOrEmpty(fileInfo.ownerUid) ==
false) {
411 if (ownerIdToAccountMap.containsKey(fileInfo.ownerUid)) {
413 if (Objects.nonNull(ownerIdToAccountMap.get(fileInfo.ownerUid))) {
414 ownerAccountObjId = ownerIdToAccountMap.get(fileInfo.ownerUid).getId();
418 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));
425 if ((fileInfo.parentObjId == fileInfo.fsObjId)
426 && (fileInfo.metaType == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_UNDEF.getValue())) {
427 fileInfo.metaType = TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue();
430 long objId = addFileToDb(computedParentObjId,
431 fileInfo.fsObjId, fileInfo.dataSourceObjId,
433 fileInfo.attrType, fileInfo.attrId, fileInfo.name,
434 fileInfo.metaAddr, fileInfo.metaSeq,
435 fileInfo.dirType, fileInfo.metaType, fileInfo.dirFlags, fileInfo.metaFlags,
437 fileInfo.crtime, fileInfo.ctime, fileInfo.atime, fileInfo.mtime,
438 fileInfo.meta_mode, fileInfo.gid, fileInfo.uid,
439 null, TskData.FileKnown.UNKNOWN,
440 fileInfo.escaped_path, fileInfo.extension, fileInfo.ownerUid, ownerAccountObjId,
442 if (fileInfo.fsObjId != fileInfo.parentObjId) {
444 newObjIds.add(objId);
448 if (fileInfo.parentObjId == fileInfo.fsObjId) {
449 fsIdToRootDir.put(fileInfo.fsObjId, objId);
453 if ((fileInfo.metaType == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue()
454 || (fileInfo.metaType == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR.getValue()))
455 && (fileInfo.name != null)
456 && ! fileInfo.name.equals(
".")
457 && ! fileInfo.name.equals(
"..")) {
458 String dirName = fileInfo.escaped_path + fileInfo.name;
459 ParentCacheKey key =
new ParentCacheKey(fileInfo.fsObjId, fileInfo.metaAddr, fileInfo.seq, dirName);
460 parentDirCache.put(key, objId);
462 }
catch (TskCoreException ex) {
463 if (computedParentObjId > 0) {
465 logger.log(Level.SEVERE,
"Error adding file to the database - parent object ID: " + computedParentObjId
466 +
", file system object ID: " + fileInfo.fsObjId +
", name: " + fileInfo.name, ex);
469 logger.log(Level.SEVERE,
"Error adding file to the database", ex);
475 addDataSourceCallbacks.onFilesAdded(newObjIds);
476 }
catch (Exception ex) {
478 logger.log(Level.SEVERE,
"Unexpected error from files added callback", ex);
480 }
catch (TskCoreException ex) {
481 logger.log(Level.SEVERE,
"Error adding batched files to database", ex);
497 private long getParentObjId(FileInfo fileInfo)
throws TskCoreException {
499 String parentPath = fileInfo.escaped_path;
500 if(parentPath.endsWith(
"/") && ! parentPath.equals(
"/")) {
501 parentPath = parentPath.substring(0, parentPath.lastIndexOf(
'/'));
505 ParentCacheKey key =
new ParentCacheKey(fileInfo.fsObjId, fileInfo.parMetaAddr, fileInfo.parSeq, parentPath);
506 if (parentDirCache.containsKey(key)) {
507 return parentDirCache.get(key);
511 throw new TskCoreException(
"Could not find parent (fsObjId: " +fileInfo.fsObjId +
", parMetaAddr: " + fileInfo.parMetaAddr
512 +
", parSeq: " + fileInfo.parSeq +
", parentPath: " + parentPath +
")");
529 long addLayoutFile(
long parentObjId,
530 long fsObjId,
long dataSourceObjId,
532 String name,
long size) {
536 Long fsObjIdForDb = fsObjId;
542 long objId = addFileToDb(parentObjId,
543 fsObjIdForDb, dataSourceObjId,
547 TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue(),
548 TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getValue(),
549 TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue(),
550 TskData.TSK_FS_META_FLAG_ENUM.UNALLOC.getValue(),
552 null, null, null, null,
554 null, TskData.FileKnown.UNKNOWN,
555 null, null, null, OsAccount.NO_ACCOUNT,
560 layoutFileIds.add(objId);
563 }
catch (TskCoreException ex) {
564 logger.log(Level.SEVERE,
"Error adding layout file to the database - parent object ID: " + parentObjId
565 +
", file system object ID: " + fsObjId +
", name: " + name, ex);
582 long addLayoutFileRange(
long objId,
long byteStart,
long byteLen,
long seq) {
583 batchedLayoutRanges.add(
new LayoutRangeInfo(objId, byteStart, byteLen, seq));
585 if (batchedLayoutRanges.size() > BATCH_FILE_THRESHOLD) {
586 return addBatchedLayoutRangesToDb();
596 private long addBatchedLayoutRangesToDb() {
599 LayoutRangeInfo range;
600 while ((range = batchedLayoutRanges.poll()) != null) {
602 addLayoutFileRangeToDb(range.objId, range.byteStart, range.byteLen, range.seq, trans);
603 }
catch (TskCoreException ex) {
604 logger.log(Level.SEVERE,
"Error adding layout file range to the database - layout file ID: " + range.objId
605 +
", byte start: " + range.byteStart +
", length: " + range.byteLen +
", seq: " + range.seq, ex);
610 }
catch (TskCoreException ex) {
611 logger.log(Level.SEVERE,
"Error adding batched files to database", ex);
622 void processLayoutFiles() {
623 addDataSourceCallbacks.onFilesAdded(layoutFileIds);
624 layoutFileIds.clear();
636 long addUnallocFsBlockFilesParent(
long fsObjId, String name) {
638 if (! fsIdToRootDir.containsKey(fsObjId)) {
639 logger.log(Level.SEVERE,
"Error - root directory for file system ID {0} not found", fsObjId);
643 VirtualDirectory dir = caseDb.addVirtualDirectory(fsIdToRootDir.get(fsObjId), name, trans);
645 addDataSourceCallbacks.onFilesAdded(Arrays.asList(dir.getId()));
647 }
catch (TskCoreException ex) {
648 logger.log(Level.SEVERE,
"Error creating virtual directory " + name +
" under file system ID " + fsObjId, ex);
657 private class ParentCacheKey {
672 ParentCacheKey(
long fsObjId,
long metaAddr,
long seqNum, String path) {
673 this.fsObjId = fsObjId;
674 this.metaAddr = metaAddr;
675 if (ownerIdToAccountMap.containsKey(fsObjId)
676 && (ownerIdToAccountMap.get(fsObjId).equals(TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_NTFS)
677 || ownerIdToAccountMap.get(fsObjId).equals(TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_NTFS_DETECT))) {
678 this.seqNum = seqNum;
686 public boolean equals(Object obj) {
687 if (! (obj instanceof ParentCacheKey)) {
691 ParentCacheKey otherKey = (ParentCacheKey) obj;
692 if (this.fsObjId != otherKey.fsObjId
693 ||
this.metaAddr != otherKey.metaAddr
694 ||
this.seqNum != otherKey.seqNum) {
698 return StringUtils.equals(this.path, otherKey.path);
702 public int hashCode() {
704 hash = 31 * hash + (int) (this.fsObjId ^ (this.fsObjId >>> 32));
705 hash = 31 * hash + (int) (this.metaAddr ^ (this.metaAddr >>> 32));
706 hash = 31 * hash + (int) (this.seqNum ^ (this.seqNum >>> 32));
707 hash = 31 * hash + Objects.hashCode(this.path);
716 private class LayoutRangeInfo {
722 LayoutRangeInfo(
long objId,
long byteStart,
long byteLen,
long seq) {
724 this.byteStart = byteStart;
725 this.byteLen = byteLen;
734 private class FileInfo {
737 long dataSourceObjId;
763 FileInfo(
long parentObjId,
764 long fsObjId,
long dataSourceObjId,
766 int attrType,
int attrId, String name,
767 long metaAddr,
long metaSeq,
768 int dirType,
int metaType,
int dirFlags,
int metaFlags,
770 long crtime,
long ctime,
long atime,
long mtime,
771 int meta_mode,
int gid,
int uid,
772 String escaped_path, String extension,
773 long seq,
long parMetaAddr,
long parSeq, String ownerUid) {
775 this.parentObjId = parentObjId;
776 this.fsObjId = fsObjId;
777 this.dataSourceObjId = dataSourceObjId;
778 this.fsType = fsType;
779 this.attrType = attrType;
780 this.attrId = attrId;
782 this.metaAddr = metaAddr;
783 this.metaSeq = metaSeq;
784 this.dirType = dirType;
785 this.metaType = metaType;
786 this.dirFlags = dirFlags;
787 this.metaFlags = metaFlags;
789 this.crtime = crtime;
793 this.meta_mode = meta_mode;
796 this.escaped_path = escaped_path;
797 this.extension = extension;
799 this.parMetaAddr = parMetaAddr;
800 this.parSeq = parSeq;
801 this.ownerUid = ownerUid;
848 private long addFileToDb(
long parentObjId,
849 Long fsObjId,
long dataSourceObjId,
851 Integer attrType, Integer attrId, String name,
852 Long metaAddr, Long metaSeq,
853 int dirType,
int metaType,
int dirFlags,
int metaFlags,
855 Long crtime, Long ctime, Long atime, Long mtime,
856 Integer meta_mode, Integer gid, Integer uid,
857 String md5, TskData.FileKnown known,
858 String escaped_path, String extension, String ownerUid, Long ownerAcctObjId,
859 boolean hasLayout, CaseDbTransaction transaction)
throws TskCoreException {
862 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
866 long objectId = caseDb.addObject(parentObjId, TskData.ObjectType.ABSTRACTFILE.getObjectType(), connection);
868 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)"
869 +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
870 PreparedStatement preparedStatement = connection.getPreparedStatement(fileInsert, Statement.NO_GENERATED_KEYS);
871 preparedStatement.clearParameters();
873 if (fsObjId != null) {
874 preparedStatement.setLong(1, fsObjId);
876 preparedStatement.setNull(1, java.sql.Types.BIGINT);
878 preparedStatement.setLong(2, objectId);
879 preparedStatement.setLong(3, dataSourceObjId);
880 preparedStatement.setShort(4, (
short) fsType);
881 if (attrType != null) {
882 preparedStatement.setShort(5, attrType.shortValue());
884 preparedStatement.setNull(5, java.sql.Types.SMALLINT);
886 if (attrId != null) {
887 preparedStatement.setInt(6, attrId);
889 preparedStatement.setNull(6, java.sql.Types.INTEGER);
891 preparedStatement.setString(7, name);
892 if (metaAddr != null) {
893 preparedStatement.setLong(8, metaAddr);
895 preparedStatement.setNull(8, java.sql.Types.BIGINT);
897 if (metaSeq != null) {
898 preparedStatement.setInt(9, metaSeq.intValue());
900 preparedStatement.setNull(9, java.sql.Types.INTEGER);
902 preparedStatement.setShort(10, (
short) dirType);
903 preparedStatement.setShort(11, (
short) metaType);
904 preparedStatement.setShort(12, (
short) dirFlags);
905 preparedStatement.setShort(13, (
short) metaFlags);
906 preparedStatement.setLong(14, size < 0 ? 0 : size);
907 if (crtime != null) {
908 preparedStatement.setLong(15, crtime);
910 preparedStatement.setNull(15, java.sql.Types.BIGINT);
913 preparedStatement.setLong(16, ctime);
915 preparedStatement.setNull(16, java.sql.Types.BIGINT);
918 preparedStatement.setLong(17, atime);
920 preparedStatement.setNull(17, java.sql.Types.BIGINT);
923 preparedStatement.setLong(18, mtime);
925 preparedStatement.setNull(18, java.sql.Types.BIGINT);
927 if (meta_mode != null) {
928 preparedStatement.setLong(19, meta_mode);
930 preparedStatement.setNull(19, java.sql.Types.BIGINT);
933 preparedStatement.setLong(20, gid);
935 preparedStatement.setNull(20, java.sql.Types.BIGINT);
938 preparedStatement.setLong(21, uid);
940 preparedStatement.setNull(21, java.sql.Types.BIGINT);
942 preparedStatement.setString(22, md5);
943 preparedStatement.setInt(23, known.getFileKnownValue());
944 preparedStatement.setString(24, escaped_path);
945 preparedStatement.setString(25, extension);
947 preparedStatement.setInt(26, 1);
949 preparedStatement.setNull(26, java.sql.Types.INTEGER);
952 preparedStatement.setString(27, ownerUid);
954 if (ownerAcctObjId != OsAccount.NO_ACCOUNT) {
955 preparedStatement.setLong(28, ownerAcctObjId);
957 preparedStatement.setNull(28, java.sql.Types.BIGINT);
960 connection.executeUpdate(preparedStatement);
964 && TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.getFileType() != fsType
965 && (!name.equals(
".")) && (!name.equals(
".."))) {
966 TimelineManager timelineManager = caseDb.getTimelineManager();
967 DerivedFile derivedFile =
new DerivedFile(caseDb, objectId, dataSourceObjId, name,
968 TskData.TSK_FS_NAME_TYPE_ENUM.valueOf((
short) dirType),
969 TskData.TSK_FS_META_TYPE_ENUM.valueOf((
short) metaType),
970 TskData.TSK_FS_NAME_FLAG_ENUM.valueOf(dirFlags),
972 size, ctime, crtime, atime, mtime, null, null, null, escaped_path, null, parentObjId, null, null, extension, ownerUid, ownerAcctObjId);
974 timelineManager.addEventsForNewFileQuiet(derivedFile, connection);
978 }
catch (SQLException ex) {
979 throw new TskCoreException(
"Failed to add file system file", ex);
1002 private long addImageToDb(TskData.TSK_IMG_TYPE_ENUM type,
long sectorSize,
long size,
1003 String timezone, String md5, String sha1, String sha256,
1004 String deviceId, String collectionDetails,
1005 CaseDbTransaction transaction)
throws TskCoreException {
1008 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1009 long newObjId = caseDb.addObject(0, TskData.ObjectType.IMG.getObjectType(), connection);
1013 String imageInfoSql =
"INSERT INTO tsk_image_info (obj_id, type, ssize, tzone, size, md5, sha1, sha256, display_name)"
1014 +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
1015 PreparedStatement preparedStatement = connection.getPreparedStatement(imageInfoSql, Statement.NO_GENERATED_KEYS);
1016 preparedStatement.clearParameters();
1017 preparedStatement.setLong(1, newObjId);
1018 preparedStatement.setShort(2, (
short) type.getValue());
1019 preparedStatement.setLong(3, sectorSize);
1020 preparedStatement.setString(4, timezone);
1022 long savedSize = size < 0 ? 0 : size;
1023 preparedStatement.setLong(5, savedSize);
1024 preparedStatement.setString(6, md5);
1025 preparedStatement.setString(7, sha1);
1026 preparedStatement.setString(8, sha256);
1027 preparedStatement.setString(9, null);
1028 connection.executeUpdate(preparedStatement);
1031 String dataSourceInfoSql =
"INSERT INTO data_source_info (obj_id, device_id, time_zone, acquisition_details, host_id) VALUES (?, ?, ?, ?, ?)";
1032 preparedStatement = connection.getPreparedStatement(dataSourceInfoSql, Statement.NO_GENERATED_KEYS);
1033 preparedStatement.clearParameters();
1034 preparedStatement.setLong(1, newObjId);
1035 preparedStatement.setString(2, deviceId);
1036 preparedStatement.setString(3, timezone);
1037 preparedStatement.setString(4, collectionDetails);
1038 preparedStatement.setLong(5, imageHost.getHostId());
1039 connection.executeUpdate(preparedStatement);
1042 }
catch (SQLException ex) {
1043 throw new TskCoreException(String.format(
"Error adding image to database"), ex);
1057 private void addImageNameToDb(
long objId, String name,
long sequence,
1058 CaseDbTransaction transaction)
throws TskCoreException {
1060 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1062 String imageNameSql =
"INSERT INTO tsk_image_names (obj_id, name, sequence) VALUES (?, ?, ?)";
1063 PreparedStatement preparedStatement = connection.getPreparedStatement(imageNameSql, Statement.NO_GENERATED_KEYS);
1064 preparedStatement.clearParameters();
1065 preparedStatement.setLong(1, objId);
1066 preparedStatement.setString(2, name);
1067 preparedStatement.setLong(3, sequence);
1068 connection.executeUpdate(preparedStatement);
1069 }
catch (SQLException ex) {
1070 throw new TskCoreException(String.format(
"Error adding image name %s to image with object ID %d", name, objId), ex);
1085 void addLayoutFileRangeToDb(
long objId,
long byteStart,
long byteLen,
1086 long seq, CaseDbTransaction transaction)
throws TskCoreException {
1088 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1090 String insertRangeSql =
"INSERT INTO tsk_file_layout (obj_id, byte_start, byte_len, sequence) "
1091 +
"VALUES (?, ?, ?, ?)";
1092 PreparedStatement preparedStatement = connection.getPreparedStatement(insertRangeSql, Statement.NO_GENERATED_KEYS);
1093 preparedStatement.clearParameters();
1094 preparedStatement.setLong(1, objId);
1095 preparedStatement.setLong(2, byteStart);
1096 preparedStatement.setLong(3, byteLen);
1097 preparedStatement.setLong(4, seq);
1098 connection.executeUpdate(preparedStatement);
1099 }
catch (SQLException ex) {
1100 throw new TskCoreException(
"Error adding layout range to file with obj ID " + objId, ex);