Sleuth Kit Java Bindings (JNI)  4.12.0
Java bindings for using The Sleuth Kit
FsContent.java
Go to the documentation of this file.
1 /*
2  * SleuthKit Java Bindings
3  *
4  * Copyright 2011-2022 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.datamodel;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
32 
39 public abstract class FsContent extends AbstractFile {
40 
41  private static final Logger logger = Logger.getLogger(FsContent.class.getName());
42  private List<String> metaDataText = null;
43 
48  // TODO: Make private.
49  @Deprecated
50  protected volatile long fileHandle = 0;
51 
108  long objId,
109  long dataSourceObjectId,
110  long fsObjId,
112  String name,
114  long metaAddr, int metaSeq,
117  long size,
118  long ctime, long crtime, long atime, long mtime,
119  short modes, int uid, int gid,
120  String md5Hash, String sha256Hash, String sha1Hash,
122  String parentPath,
123  String mimeType,
124  String extension,
125  String ownerUid,
126  Long osAccountObjId,
127  TskData.CollectedStatus collected,
128  List<Attribute> fileAttributes) {
129  super(db, objId, dataSourceObjectId, Long.valueOf(fsObjId), attrType, attrId, name, fileType, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, sha256Hash, sha1Hash, knownState, parentPath, mimeType, extension, ownerUid, osAccountObjId, collected, fileAttributes);
130  }
131 
137  public long getFileSystemId() {
138  return getFileSystemObjectId().orElse(0L);
139  }
140 
146  @SuppressWarnings("deprecation")
147  void loadFileHandle() throws TskCoreException {
148  if (fileHandle == 0) {
149  synchronized (this) {
150  if (fileHandle == 0) {
151  fileHandle = SleuthkitJNI.openFile(getFileSystem().getFileSystemHandle(), metaAddr, attrType, attrId, getSleuthkitCase());
152  }
153  }
154  }
155  }
156 
163  @SuppressWarnings("deprecation")
164  long getFileHandle() {
165  return fileHandle;
166  }
167 
179  @Override
180  @SuppressWarnings("deprecation")
181  protected synchronized int readInt(byte[] buf, long offset, long len) throws TskCoreException {
182  if (offset == 0 && size == 0) {
183  //special case for 0-size file
184  return 0;
185  }
186  loadFileHandle();
187  return SleuthkitJNI.readFile(fileHandle, buf, offset, len);
188  }
189 
190  @Override
191  public boolean isRoot() {
192  try {
193  FileSystem fs = getFileSystem();
194  return fs.getRoot_inum() == this.getMetaAddr();
195  } catch (TskCoreException ex) {
196  logger.log(Level.SEVERE, "Exception while calling 'getFileSystem' on " + this, ex); //NON-NLS
197  return false;
198  }
199  }
200 
209  public AbstractFile getParentDirectory() throws TskCoreException {
210  return getSleuthkitCase().getParentDirectory(this);
211  }
212 
220  @Override
221  public Content getDataSource() throws TskCoreException {
222  return getFileSystem().getDataSource();
223  }
224 
234  public synchronized List<String> getMetaDataText() throws TskCoreException {
235  if (metaDataText != null) {
236  return metaDataText;
237  }
238 
239  // if there is no metadata for this file, return empty string
240  if (metaAddr == 0) {
241  metaDataText = new ArrayList<String>();
242  metaDataText.add("");
243  return metaDataText;
244  }
245 
246  loadFileHandle();
247  metaDataText = SleuthkitJNI.getFileMetaDataText(fileHandle);
248  return metaDataText;
249  }
250 
254  @Override
255  @SuppressWarnings("deprecation")
256  public synchronized void close() {
257  if (fileHandle != 0) {
258  SleuthkitJNI.closeFile(fileHandle);
259  fileHandle = 0;
260  }
261  }
262 
267  @Override
268  public void finalize() throws Throwable {
269  try {
270  close();
271  } finally {
272  super.finalize();
273  }
274  }
275 
282  @Override
283  public String toString(boolean preserveState) {
284  String path = "";
285  try {
286  path = getUniquePath();
287  } catch (TskCoreException ex) {
288  logger.log(Level.SEVERE, "Error loading unique path for object ID: {0}", this.getId());
289  }
290 
291  return super.toString(preserveState)
292  + "FsContent [\t" //NON-NLS
293  + "fsObjId " + getFileSystemId() //NON-NLS
294  + "\t" + "uniquePath " + path //NON-NLS
295  + "\t" + "fileHandle " + getFileHandle() //NON-NLS
296  + "]\t";
297  }
298 
338  @Deprecated
339  @SuppressWarnings("deprecation")
340  FsContent(SleuthkitCase db, long objId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
342  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
343  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath) {
344  this(db, objId, db.getDataSourceObjectId(objId), fsObjId, attrType, (int) attrId, name, TSK_DB_FILES_TYPE_ENUM.FS, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, null, null, knownState, parentPath, null, null, OsAccount.NO_OWNER_ID, OsAccount.NO_ACCOUNT, Collections.emptyList());
345  }
346 
397  @Deprecated
398  @SuppressWarnings("deprecation")
399  FsContent(SleuthkitCase db, long objId, long dataSourceObjectId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
400  String name, long metaAddr, int metaSeq, TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
401  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
402  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath, String mimeType) {
403  this(db, objId, dataSourceObjectId, fsObjId, attrType, (int) attrId, name, TSK_DB_FILES_TYPE_ENUM.FS, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, null, null, knownState, parentPath, mimeType, null, OsAccount.NO_OWNER_ID, OsAccount.NO_ACCOUNT, Collections.emptyList());
404  }
405 
462  @Deprecated
463  @SuppressWarnings("deprecation")
464  FsContent(SleuthkitCase db,
465  long objId,
466  long dataSourceObjectId,
467  long fsObjId,
468  TSK_FS_ATTR_TYPE_ENUM attrType, int attrId,
469  String name,
470  TSK_DB_FILES_TYPE_ENUM fileType,
471  long metaAddr, int metaSeq,
472  TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
473  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags,
474  long size,
475  long ctime, long crtime, long atime, long mtime,
476  short modes, int uid, int gid,
477  String md5Hash, String sha256Hash, String sha1Hash,
478  FileKnown knownState,
479  String parentPath,
480  String mimeType,
481  String extension,
482  String ownerUid,
483  Long osAccountObjId,
484  List<Attribute> fileAttributes) {
485  this(db, objId, dataSourceObjectId, fsObjId, attrType, attrId, name, TSK_DB_FILES_TYPE_ENUM.FS, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, null, null, knownState, parentPath, mimeType, null, OsAccount.NO_OWNER_ID, OsAccount.NO_ACCOUNT, TskData.CollectedStatus.UNKNOWN, Collections.emptyList());
486  }
487 }
FS
File that can be found in file system tree.
Definition: TskData.java:694
final TSK_FS_NAME_TYPE_ENUM dirType
synchronized int readInt(byte[] buf, long offset, long len)
Definition: FsContent.java:181
static long openFile(long fsHandle, long fileId, TSK_FS_ATTR_TYPE_ENUM attrType, int attrId, SleuthkitCase skCase)
static int readFile(long fileHandle, byte[] readBuffer, long offset, long len)
final TskData.TSK_DB_FILES_TYPE_ENUM fileType
synchronized List< String > getMetaDataText()
Definition: FsContent.java:234
final TskData.TSK_FS_ATTR_TYPE_ENUM attrType
Set< TSK_FS_META_FLAG_ENUM > metaFlags
final Set< TskData.TSK_FS_META_MODE_ENUM > modes
static List< String > getFileMetaDataText(long fileHandle)
String toString(boolean preserveState)
Definition: FsContent.java:283
static void closeFile(long fileHandle)
final TSK_FS_META_TYPE_ENUM metaType

Copyright © 2011-2021 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.