19 package org.sleuthkit.datamodel;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.ArrayList;
24 import java.util.List;
35 class ResultSetHelper {
39 ResultSetHelper(SleuthkitCase db) {
54 Image image(ResultSet rs, String[] imagePaths)
throws TskCoreException, SQLException {
56 long obj_id, type, ssize;
59 obj_id = rs.getLong(
"obj_id");
60 type = rs.getLong(
"type");
61 ssize = rs.getLong(
"ssize");
62 tzone = rs.getString(
"tzone");
64 if (db.getSchemaVersion() > 2) {
65 md5 = rs.getString(
"md5");
68 String name = rs.getString(
"display_name");
70 if (imagePaths.length > 0) {
71 String path1 = imagePaths[0];
72 name = (
new java.io.File(path1)).getName();
78 Image img =
new Image(db, obj_id, type, ssize, name, imagePaths, tzone, md5);
89 String imagePath(ResultSet rs)
throws SQLException {
90 return rs.getString(
"name");
102 VolumeSystem volumeSystem(ResultSet rs, Image parent)
throws SQLException {
104 long id = rs.getLong(
"obj_id");
105 long type = rs.getLong(
"vs_type");
106 long imgOffset = rs.getLong(
"img_offset");
107 long blockSize = rs.getLong(
"block_size");
109 VolumeSystem vs =
new VolumeSystem(db,
id,
"", type, imgOffset, blockSize);
111 vs.setParent(parent);
124 Volume volume(ResultSet rs, VolumeSystem parent)
throws SQLException {
125 Volume vol =
new Volume(db, rs.getLong(
"obj_id"), rs.getLong(
"addr"),
126 rs.getLong(
"start"), rs.getLong(
"length"), rs.getLong(
"flags"),
127 rs.getString(
"desc"));
128 vol.setParent(parent);
141 FileSystem fileSystem(ResultSet rs, Content parent)
throws SQLException {
143 TskData.TSK_FS_TYPE_ENUM fsType = TskData.TSK_FS_TYPE_ENUM.valueOf(rs.getInt(
"fs_type"));
144 FileSystem fs =
new FileSystem(db, rs.getLong(
"obj_id"),
"", rs.getLong(
"img_offset"),
145 fsType, rs.getLong(
"block_size"), rs.getLong(
"block_count"),
146 rs.getLong(
"root_inum"), rs.getLong(
"first_inum"), rs.getLong(
"last_inum"));
147 fs.setParent(parent);
160 File file(ResultSet rs, FileSystem fs)
throws SQLException {
161 File f =
new File(db, rs.getLong(
"obj_id"), rs.getLong(
"fs_obj_id"),
162 TSK_FS_ATTR_TYPE_ENUM.valueOf(rs.getShort(
"attr_type")),
163 rs.getShort(
"attr_id"), rs.getString(
"name"), rs.getLong(
"meta_addr"), rs.getInt(
"meta_seq"),
164 TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort(
"dir_type")),
165 TSK_FS_META_TYPE_ENUM.valueOf(rs.getShort(
"meta_type")),
166 TSK_FS_NAME_FLAG_ENUM.valueOf(rs.getShort(
"dir_flags")),
167 rs.getShort(
"meta_flags"), rs.getLong(
"size"),
168 rs.getLong(
"ctime"), rs.getLong(
"crtime"), rs.getLong(
"atime"), rs.getLong(
"mtime"),
169 rs.getShort(
"mode"), rs.getInt(
"uid"), rs.getInt(
"gid"),
171 FileKnown.valueOf(rs.getByte(
"known")), rs.getString(
"parent_path"));
186 Directory directory(ResultSet rs, FileSystem fs, String name)
throws SQLException {
187 Directory dir =
new Directory(db, rs.getLong(
"obj_id"), rs.getLong(
"fs_obj_id"),
188 TSK_FS_ATTR_TYPE_ENUM.valueOf(rs.getShort(
"attr_type")),
189 rs.getShort(
"attr_id"), name, rs.getLong(
"meta_addr"), rs.getInt(
"meta_seq"),
190 TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort(
"dir_type")),
191 TSK_FS_META_TYPE_ENUM.valueOf(rs.getShort(
"meta_type")),
192 TSK_FS_NAME_FLAG_ENUM.valueOf(rs.getShort(
"dir_flags")),
193 rs.getShort(
"meta_flags"), rs.getLong(
"size"),
194 rs.getLong(
"ctime"), rs.getLong(
"crtime"), rs.getLong(
"atime"), rs.getLong(
"mtime"),
195 rs.getShort(
"mode"), rs.getInt(
"uid"), rs.getInt(
"gid"),
197 FileKnown.valueOf(rs.getByte(
"known")), rs.getString(
"parent_path"));
198 dir.setFileSystem(fs);
209 VirtualDirectory virtualDirectory(ResultSet rs)
throws SQLException {
210 String parentPath = rs.getString(
"parent_path");
211 if (parentPath == null) {
215 final VirtualDirectory vd =
new VirtualDirectory(db, rs.getLong(
"obj_id"),
216 rs.getString(
"name"),
217 TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort(
"dir_type")),
218 TSK_FS_META_TYPE_ENUM.valueOf(rs.getShort(
"meta_type")),
219 TSK_FS_NAME_FLAG_ENUM.valueOf(rs.getShort(
"dir_flags")), rs.getShort(
"meta_flags"),
220 rs.getLong(
"size"), rs.getString(
"md5"),
221 FileKnown.valueOf(rs.getByte(
"known")), parentPath);
234 Directory directory(ResultSet rs, FileSystem fs)
throws SQLException {
235 return directory(rs, fs, rs.getString(
"name"));
246 TskFileRange tskFileRange(ResultSet rs)
throws SQLException {
247 return new TskFileRange(rs.getLong(
"byte_start"),
248 rs.getLong(
"byte_len"), rs.getLong(
"sequence"));
259 DerivedFile derivedFile(ResultSet rs,
long parentId)
throws SQLException {
260 boolean hasLocalPath = rs.getBoolean(
"has_path");
261 long objId = rs.getLong(
"obj_id");
262 String localPath = null;
264 localPath = db.getFilePath(objId);
267 String parentPath = rs.getString(
"parent_path");
268 if (parentPath == null) {
273 =
new DerivedFile(db, objId, rs.getString(
"name"),
274 TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort(
"dir_type")),
275 TSK_FS_META_TYPE_ENUM.valueOf(rs.getShort(
"meta_type")),
276 TSK_FS_NAME_FLAG_ENUM.valueOf(rs.getShort(
"dir_flags")), rs.getShort(
"meta_flags"),
278 rs.getLong(
"ctime"), rs.getLong(
"crtime"), rs.getLong(
"atime"), rs.getLong(
"mtime"),
279 rs.getString(
"md5"), FileKnown.valueOf(rs.getByte(
"known")),
280 parentPath, localPath,
294 LocalFile localFile(ResultSet rs,
long parentId)
throws SQLException {
295 boolean hasLocalPath = rs.getBoolean(
"has_path");
296 long objId = rs.getLong(
"obj_id");
297 String localPath = null;
299 localPath = db.getFilePath(objId);
302 String parentPath = rs.getString(
"parent_path");
303 if (parentPath == null) {
308 =
new LocalFile(db, objId, rs.getString(
"name"),
309 TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort(
"dir_type")),
310 TSK_FS_META_TYPE_ENUM.valueOf(rs.getShort(
"meta_type")),
311 TSK_FS_NAME_FLAG_ENUM.valueOf(rs.getShort(
"dir_flags")), rs.getShort(
"meta_flags"),
313 rs.getLong(
"ctime"), rs.getLong(
"crtime"), rs.getLong(
"atime"), rs.getLong(
"mtime"),
314 rs.getString(
"md5"), FileKnown.valueOf(rs.getByte(
"known")),
315 parentPath, localPath,
330 List<Content> fileChildren(ResultSet rs,
long parentId)
throws SQLException {
331 List<Content> children =
new ArrayList<Content>();
334 TskData.TSK_DB_FILES_TYPE_ENUM type = TskData.TSK_DB_FILES_TYPE_ENUM.valueOf(rs.getShort(
"type"));
336 if (type == TskData.TSK_DB_FILES_TYPE_ENUM.FS) {
338 if (rs.getShort(
"meta_type") == TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue()) {
339 result = directory(rs, null);
341 result = file(rs, null);
343 children.add(result);
344 }
else if (type == TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR) {
345 VirtualDirectory virtDir = virtualDirectory(rs);
346 children.add(virtDir);
347 }
else if (type == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
348 || type == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS
349 || type == TskData.TSK_DB_FILES_TYPE_ENUM.CARVED) {
350 String parentPath = rs.getString(
"parent_path");
351 if (parentPath == null) {
355 =
new LayoutFile(db, rs.getLong(
"obj_id"), rs.getString(
"name"),
357 TSK_FS_NAME_TYPE_ENUM.valueOf(rs.getShort(
"dir_type")),
358 TSK_FS_META_TYPE_ENUM.valueOf(rs.getShort(
"meta_type")),
359 TSK_FS_NAME_FLAG_ENUM.valueOf(rs.getShort(
"dir_flags")),
360 rs.getShort(
"meta_flags"),
362 rs.getString(
"md5"), FileKnown.valueOf(rs.getByte(
"known")), parentPath);
364 }
else if (type == TskData.TSK_DB_FILES_TYPE_ENUM.DERIVED) {
365 final DerivedFile df = derivedFile(rs, parentId);
367 }
else if (type == TskData.TSK_DB_FILES_TYPE_ENUM.LOCAL) {
368 final LocalFile lf = localFile(rs, parentId);