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);
399 }
catch (Exception ex) {
401 logger.log(Level.WARNING,
"Error mapping ownerId " + ownerUid +
" to account", ex);
402 ownerIdToAccountMap.put(ownerUid, null);
411 while ((fileInfo = batchedFiles.poll()) != null) {
412 long computedParentObjId = fileInfo.parentObjId;
415 if (fileInfo.parentObjId == 0) {
416 computedParentObjId = getParentObjId(fileInfo);
419 Long ownerAccountObjId = OsAccount.NO_ACCOUNT;
420 if (Strings.isNullOrEmpty(fileInfo.ownerUid) ==
false) {
421 if (ownerIdToAccountMap.containsKey(fileInfo.ownerUid)) {
423 if (Objects.nonNull(ownerIdToAccountMap.get(fileInfo.ownerUid))) {
424 ownerAccountObjId = ownerIdToAccountMap.get(fileInfo.ownerUid).getId();
428 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));
436 if ((fileInfo.parentObjId == fileInfo.fsObjId)
437 && (fileInfo.metaType != TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue())) {
438 fileInfo.metaType = TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue();
441 long objId = addFileToDb(computedParentObjId,
442 fileInfo.fsObjId, fileInfo.dataSourceObjId,
444 fileInfo.attrType, fileInfo.attrId, fileInfo.name,
445 fileInfo.metaAddr, fileInfo.metaSeq,
446 fileInfo.dirType, fileInfo.metaType, fileInfo.dirFlags, fileInfo.metaFlags,
448 fileInfo.crtime, fileInfo.ctime, fileInfo.atime, fileInfo.mtime,
449 fileInfo.meta_mode, fileInfo.gid, fileInfo.uid,
450 null, TskData.FileKnown.UNKNOWN,
451 fileInfo.escaped_path, fileInfo.extension, fileInfo.ownerUid, ownerAccountObjId,
453 if (fileInfo.fsObjId != fileInfo.parentObjId) {
455 newObjIds.add(objId);
459 if (fileInfo.parentObjId == fileInfo.fsObjId) {
460 fsIdToRootDir.put(fileInfo.fsObjId, objId);
464 if ((fileInfo.metaType == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue()
465 || (fileInfo.metaType == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR.getValue()))
466 && (fileInfo.name != null)
467 && ! fileInfo.name.equals(
".")
468 && ! fileInfo.name.equals(
"..")) {
469 String dirName = fileInfo.escaped_path + fileInfo.name;
470 ParentCacheKey key =
new ParentCacheKey(fileInfo.fsObjId, fileInfo.metaAddr, fileInfo.seq, dirName);
471 parentDirCache.put(key, objId);
473 }
catch (TskCoreException ex) {
474 if (computedParentObjId > 0) {
476 logger.log(Level.SEVERE,
"Error adding file to the database - parent object ID: " + computedParentObjId
477 +
", file system object ID: " + fileInfo.fsObjId +
", name: " + fileInfo.name, ex);
480 logger.log(Level.SEVERE,
"Error adding file to the database", ex);
486 addDataSourceCallbacks.onFilesAdded(newObjIds);
487 }
catch (Exception ex) {
489 logger.log(Level.SEVERE,
"Unexpected error from files added callback", ex);
491 }
catch (Throwable ex) {
492 logger.log(Level.SEVERE,
"Error adding batched files to database", ex);
508 private long getParentObjId(FileInfo fileInfo)
throws TskCoreException {
510 String parentPath = fileInfo.escaped_path;
511 if(parentPath.endsWith(
"/") && ! parentPath.equals(
"/")) {
512 parentPath = parentPath.substring(0, parentPath.lastIndexOf(
'/'));
516 ParentCacheKey key =
new ParentCacheKey(fileInfo.fsObjId, fileInfo.parMetaAddr, fileInfo.parSeq, parentPath);
517 if (parentDirCache.containsKey(key)) {
518 return parentDirCache.get(key);
522 throw new TskCoreException(
"Could not find parent (fsObjId: " +fileInfo.fsObjId +
", parMetaAddr: " + fileInfo.parMetaAddr
523 +
", parSeq: " + fileInfo.parSeq +
", parentPath: " + parentPath +
")");
540 long addLayoutFile(
long parentObjId,
541 long fsObjId,
long dataSourceObjId,
543 String name,
long size) {
547 Long fsObjIdForDb = fsObjId;
553 String parentPath =
"/";
554 if (unallocFileDirs.containsKey(parentObjId)) {
555 parentPath =
"/" + unallocFileDirs.get(parentObjId).getName() +
"/";
559 long objId = addFileToDb(parentObjId,
560 fsObjIdForDb, dataSourceObjId,
564 TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue(),
565 TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getValue(),
566 TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue(),
567 TskData.TSK_FS_META_FLAG_ENUM.UNALLOC.getValue(),
569 null, null, null, null,
571 null, TskData.FileKnown.UNKNOWN,
572 parentPath, null, null, OsAccount.NO_ACCOUNT,
577 layoutFileIds.add(objId);
580 }
catch (TskCoreException ex) {
581 logger.log(Level.SEVERE,
"Error adding layout file to the database - parent object ID: " + parentObjId
582 +
", file system object ID: " + fsObjId +
", name: " + name, ex);
599 long addLayoutFileRange(
long objId,
long byteStart,
long byteLen,
long seq) {
600 batchedLayoutRanges.add(
new LayoutRangeInfo(objId, byteStart, byteLen, seq));
602 if (batchedLayoutRanges.size() > BATCH_FILE_THRESHOLD) {
603 return addBatchedLayoutRangesToDb();
613 private long addBatchedLayoutRangesToDb() {
616 LayoutRangeInfo range;
617 while ((range = batchedLayoutRanges.poll()) != null) {
619 addLayoutFileRangeToDb(range.objId, range.byteStart, range.byteLen, range.seq, trans);
620 }
catch (TskCoreException ex) {
621 logger.log(Level.SEVERE,
"Error adding layout file range to the database - layout file ID: " + range.objId
622 +
", byte start: " + range.byteStart +
", length: " + range.byteLen +
", seq: " + range.seq, ex);
627 }
catch (TskCoreException ex) {
628 logger.log(Level.SEVERE,
"Error adding batched files to database", ex);
639 void processLayoutFiles() {
640 addDataSourceCallbacks.onFilesAdded(layoutFileIds);
641 layoutFileIds.clear();
653 long addUnallocFsBlockFilesParent(
long fsObjId, String name) {
655 if (! fsIdToRootDir.containsKey(fsObjId)) {
656 logger.log(Level.SEVERE,
"Error - root directory for file system ID {0} not found", fsObjId);
660 VirtualDirectory dir = caseDb.addVirtualDirectory(fsIdToRootDir.get(fsObjId), name, trans);
662 unallocFileDirs.put(dir.getId(), dir);
663 addDataSourceCallbacks.onFilesAdded(Arrays.asList(dir.getId()));
665 }
catch (TskCoreException ex) {
666 logger.log(Level.SEVERE,
"Error creating virtual directory " + name +
" under file system ID " + fsObjId, ex);
675 private class ParentCacheKey {
690 ParentCacheKey(
long fsObjId,
long metaAddr,
long seqNum, String path) {
691 this.fsObjId = fsObjId;
692 this.metaAddr = metaAddr;
693 if (ownerIdToAccountMap.containsKey(fsObjId)
694 && (ownerIdToAccountMap.get(fsObjId).equals(TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_NTFS)
695 || ownerIdToAccountMap.get(fsObjId).equals(TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_NTFS_DETECT))) {
696 this.seqNum = seqNum;
704 public boolean equals(Object obj) {
705 if (! (obj instanceof ParentCacheKey)) {
709 ParentCacheKey otherKey = (ParentCacheKey) obj;
710 if (this.fsObjId != otherKey.fsObjId
711 ||
this.metaAddr != otherKey.metaAddr
712 ||
this.seqNum != otherKey.seqNum) {
716 return StringUtils.equals(this.path, otherKey.path);
720 public int hashCode() {
722 hash = 31 * hash + (int) (this.fsObjId ^ (this.fsObjId >>> 32));
723 hash = 31 * hash + (int) (this.metaAddr ^ (this.metaAddr >>> 32));
724 hash = 31 * hash + (int) (this.seqNum ^ (this.seqNum >>> 32));
725 hash = 31 * hash + Objects.hashCode(this.path);
734 private class LayoutRangeInfo {
740 LayoutRangeInfo(
long objId,
long byteStart,
long byteLen,
long seq) {
742 this.byteStart = byteStart;
743 this.byteLen = byteLen;
752 private class FileInfo {
755 long dataSourceObjId;
781 FileInfo(
long parentObjId,
782 long fsObjId,
long dataSourceObjId,
784 int attrType,
int attrId, String name,
785 long metaAddr,
long metaSeq,
786 int dirType,
int metaType,
int dirFlags,
int metaFlags,
788 long crtime,
long ctime,
long atime,
long mtime,
789 int meta_mode,
int gid,
int uid,
790 String escaped_path, String extension,
791 long seq,
long parMetaAddr,
long parSeq, String ownerUid) {
793 this.parentObjId = parentObjId;
794 this.fsObjId = fsObjId;
795 this.dataSourceObjId = dataSourceObjId;
796 this.fsType = fsType;
797 this.attrType = attrType;
798 this.attrId = attrId;
800 this.metaAddr = metaAddr;
801 this.metaSeq = metaSeq;
802 this.dirType = dirType;
803 this.metaType = metaType;
804 this.dirFlags = dirFlags;
805 this.metaFlags = metaFlags;
807 this.crtime = crtime;
811 this.meta_mode = meta_mode;
814 this.escaped_path = escaped_path;
815 this.extension = extension;
817 this.parMetaAddr = parMetaAddr;
818 this.parSeq = parSeq;
819 this.ownerUid = ownerUid;
866 private long addFileToDb(
long parentObjId,
867 Long fsObjId,
long dataSourceObjId,
869 Integer attrType, Integer attrId, String name,
870 Long metaAddr, Long metaSeq,
871 int dirType,
int metaType,
int dirFlags,
int metaFlags,
873 Long crtime, Long ctime, Long atime, Long mtime,
874 Integer meta_mode, Integer gid, Integer uid,
875 String md5, TskData.FileKnown known,
876 String escaped_path, String extension, String ownerUid, Long ownerAcctObjId,
877 boolean hasLayout, CaseDbTransaction transaction)
throws TskCoreException {
880 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
884 long objectId = caseDb.addObject(parentObjId, TskData.ObjectType.ABSTRACTFILE.getObjectType(), connection);
886 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, collected)"
887 +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
888 PreparedStatement preparedStatement = connection.getPreparedStatement(fileInsert, Statement.NO_GENERATED_KEYS);
889 preparedStatement.clearParameters();
891 if (fsObjId != null) {
892 preparedStatement.setLong(1, fsObjId);
894 preparedStatement.setNull(1, java.sql.Types.BIGINT);
896 preparedStatement.setLong(2, objectId);
897 preparedStatement.setLong(3, dataSourceObjId);
898 preparedStatement.setShort(4, (
short) fsType);
899 if (attrType != null) {
900 preparedStatement.setShort(5, attrType.shortValue());
902 preparedStatement.setNull(5, java.sql.Types.SMALLINT);
904 if (attrId != null) {
905 preparedStatement.setInt(6, attrId);
907 preparedStatement.setNull(6, java.sql.Types.INTEGER);
909 preparedStatement.setString(7, name);
910 if (metaAddr != null) {
911 preparedStatement.setLong(8, metaAddr);
913 preparedStatement.setNull(8, java.sql.Types.BIGINT);
915 if (metaSeq != null) {
916 preparedStatement.setInt(9, metaSeq.intValue());
918 preparedStatement.setNull(9, java.sql.Types.INTEGER);
920 preparedStatement.setShort(10, (
short) dirType);
921 preparedStatement.setShort(11, (
short) metaType);
922 preparedStatement.setShort(12, (
short) dirFlags);
923 preparedStatement.setShort(13, (
short) metaFlags);
924 preparedStatement.setLong(14, size < 0 ? 0 : size);
925 if (crtime != null) {
926 preparedStatement.setLong(15, crtime);
928 preparedStatement.setNull(15, java.sql.Types.BIGINT);
931 preparedStatement.setLong(16, ctime);
933 preparedStatement.setNull(16, java.sql.Types.BIGINT);
936 preparedStatement.setLong(17, atime);
938 preparedStatement.setNull(17, java.sql.Types.BIGINT);
941 preparedStatement.setLong(18, mtime);
943 preparedStatement.setNull(18, java.sql.Types.BIGINT);
945 if (meta_mode != null) {
946 preparedStatement.setLong(19, meta_mode);
948 preparedStatement.setNull(19, java.sql.Types.BIGINT);
951 preparedStatement.setLong(20, gid);
953 preparedStatement.setNull(20, java.sql.Types.BIGINT);
956 preparedStatement.setLong(21, uid);
958 preparedStatement.setNull(21, java.sql.Types.BIGINT);
960 preparedStatement.setString(22, md5);
961 preparedStatement.setInt(23, known.getFileKnownValue());
962 preparedStatement.setString(24, escaped_path);
963 preparedStatement.setString(25, extension);
965 preparedStatement.setInt(26, 1);
967 preparedStatement.setNull(26, java.sql.Types.INTEGER);
970 preparedStatement.setString(27, ownerUid);
972 if (ownerAcctObjId != OsAccount.NO_ACCOUNT) {
973 preparedStatement.setLong(28, ownerAcctObjId);
975 preparedStatement.setNull(28, java.sql.Types.BIGINT);
978 preparedStatement.setLong(29, TskData.CollectedStatus.UNKNOWN.getType());
980 connection.executeUpdate(preparedStatement);
984 && TskData.TSK_DB_FILES_TYPE_ENUM.SLACK.getFileType() != fsType
985 && (!name.equals(
".")) && (!name.equals(
".."))) {
986 TimelineManager timelineManager = caseDb.getTimelineManager();
987 DerivedFile derivedFile =
new DerivedFile(caseDb, objectId, dataSourceObjId, fsObjId, name,
988 TskData.TSK_FS_NAME_TYPE_ENUM.valueOf((
short) dirType),
989 TskData.TSK_FS_META_TYPE_ENUM.valueOf((
short) metaType),
990 TskData.TSK_FS_NAME_FLAG_ENUM.valueOf(dirFlags),
992 size, ctime, crtime, atime, mtime, null, null, null, null, escaped_path, null, parentObjId, null, null, extension, ownerUid, ownerAcctObjId);
994 timelineManager.addEventsForNewFileQuiet(derivedFile, connection);
998 }
catch (SQLException ex) {
999 throw new TskCoreException(
"Failed to add file system file", ex);
1022 private long addImageToDb(TskData.TSK_IMG_TYPE_ENUM type,
long sectorSize,
long size,
1023 String timezone, String md5, String sha1, String sha256,
1024 String deviceId, String collectionDetails,
1025 CaseDbTransaction transaction)
throws TskCoreException {
1028 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1029 long newObjId = caseDb.addObject(0, TskData.ObjectType.IMG.getObjectType(), connection);
1033 String imageInfoSql =
"INSERT INTO tsk_image_info (obj_id, type, ssize, tzone, size, md5, sha1, sha256, display_name)"
1034 +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
1035 PreparedStatement preparedStatement = connection.getPreparedStatement(imageInfoSql, Statement.NO_GENERATED_KEYS);
1036 preparedStatement.clearParameters();
1037 preparedStatement.setLong(1, newObjId);
1038 preparedStatement.setShort(2, (
short) type.getValue());
1039 preparedStatement.setLong(3, sectorSize);
1040 preparedStatement.setString(4, timezone);
1042 long savedSize = size < 0 ? 0 : size;
1043 preparedStatement.setLong(5, savedSize);
1044 preparedStatement.setString(6, md5);
1045 preparedStatement.setString(7, sha1);
1046 preparedStatement.setString(8, sha256);
1047 preparedStatement.setString(9, null);
1048 connection.executeUpdate(preparedStatement);
1051 String dataSourceInfoSql =
"INSERT INTO data_source_info (obj_id, device_id, time_zone, acquisition_details, host_id) VALUES (?, ?, ?, ?, ?)";
1052 preparedStatement = connection.getPreparedStatement(dataSourceInfoSql, Statement.NO_GENERATED_KEYS);
1053 preparedStatement.clearParameters();
1054 preparedStatement.setLong(1, newObjId);
1055 preparedStatement.setString(2, deviceId);
1056 preparedStatement.setString(3, timezone);
1057 preparedStatement.setString(4, collectionDetails);
1058 preparedStatement.setLong(5, imageHost.getHostId());
1059 connection.executeUpdate(preparedStatement);
1062 }
catch (SQLException ex) {
1063 throw new TskCoreException(String.format(
"Error adding image to database"), ex);
1077 private void addImageNameToDb(
long objId, String name,
long sequence,
1078 CaseDbTransaction transaction)
throws TskCoreException {
1080 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1082 String imageNameSql =
"INSERT INTO tsk_image_names (obj_id, name, sequence) VALUES (?, ?, ?)";
1083 PreparedStatement preparedStatement = connection.getPreparedStatement(imageNameSql, Statement.NO_GENERATED_KEYS);
1084 preparedStatement.clearParameters();
1085 preparedStatement.setLong(1, objId);
1086 preparedStatement.setString(2, name);
1087 preparedStatement.setLong(3, sequence);
1088 connection.executeUpdate(preparedStatement);
1089 }
catch (SQLException ex) {
1090 throw new TskCoreException(String.format(
"Error adding image name %s to image with object ID %d", name, objId), ex);
1105 void addLayoutFileRangeToDb(
long objId,
long byteStart,
long byteLen,
1106 long seq, CaseDbTransaction transaction)
throws TskCoreException {
1108 SleuthkitCase.CaseDbConnection connection = transaction.getConnection();
1110 String insertRangeSql =
"INSERT INTO tsk_file_layout (obj_id, byte_start, byte_len, sequence) "
1111 +
"VALUES (?, ?, ?, ?)";
1112 PreparedStatement preparedStatement = connection.getPreparedStatement(insertRangeSql, Statement.NO_GENERATED_KEYS);
1113 preparedStatement.clearParameters();
1114 preparedStatement.setLong(1, objId);
1115 preparedStatement.setLong(2, byteStart);
1116 preparedStatement.setLong(3, byteLen);
1117 preparedStatement.setLong(4, seq);
1118 connection.executeUpdate(preparedStatement);
1119 }
catch (SQLException ex) {
1120 throw new TskCoreException(
"Error adding layout range to file with obj ID " + objId, ex);