Sleuth Kit Java Bindings (JNI)  4.12.1
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;
26 import org.apache.commons.lang3.ArrayUtils;
33 
40 public abstract class FsContent extends AbstractFile {
41 
42  private static final Logger logger = Logger.getLogger(FsContent.class.getName());
43  private List<String> metaDataText = null;
44 
49  // TODO: Make private.
50  @Deprecated
51  protected volatile long fileHandle = 0;
52 
109  long objId,
110  long dataSourceObjectId,
111  long fsObjId,
113  String name,
115  long metaAddr, int metaSeq,
118  long size,
119  long ctime, long crtime, long atime, long mtime,
120  short modes, int uid, int gid,
121  String md5Hash, String sha256Hash, String sha1Hash,
123  String parentPath,
124  String mimeType,
125  String extension,
126  String ownerUid,
127  Long osAccountObjId,
128  TskData.CollectedStatus collected,
129  List<Attribute> fileAttributes) {
130  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);
131  }
132 
138  public long getFileSystemId() {
139  return getFileSystemObjectId().orElse(0L);
140  }
141 
147  @SuppressWarnings("deprecation")
148  void loadFileHandle() throws TskCoreException {
149  if (fileHandle == 0) {
150  synchronized (this) {
151  if (fileHandle == 0) {
152  fileHandle = SleuthkitJNI.openFile(getFileSystem().getFileSystemHandle(), metaAddr, attrType, attrId, getSleuthkitCase());
153  }
154  }
155  }
156  }
157 
164  @SuppressWarnings("deprecation")
165  long getFileHandle() {
166  return fileHandle;
167  }
168 
180  @Override
181  @SuppressWarnings("deprecation")
182  protected synchronized int readInt(byte[] buf, long offset, long len) throws TskCoreException {
183  if (offset == 0 && size == 0) {
184  //special case for 0-size file
185  return 0;
186  }
187 
188  Content dataSource = getDataSource();
189  if (dataSource instanceof Image && ArrayUtils.isEmpty(((Image) dataSource).getPaths())) {
190  return 0;
191  }
192 
193  loadFileHandle();
194  return SleuthkitJNI.readFile(fileHandle, buf, offset, len);
195  }
196 
197  @Override
198  public boolean isRoot() {
199  try {
200  FileSystem fs = getFileSystem();
201  return fs.getRoot_inum() == this.getMetaAddr();
202  } catch (TskCoreException ex) {
203  logger.log(Level.SEVERE, "Exception while calling 'getFileSystem' on " + this, ex); //NON-NLS
204  return false;
205  }
206  }
207 
216  public AbstractFile getParentDirectory() throws TskCoreException {
217  return getSleuthkitCase().getParentDirectory(this);
218  }
219 
227  @Override
228  public Content getDataSource() throws TskCoreException {
229  return getFileSystem().getDataSource();
230  }
231 
241  public synchronized List<String> getMetaDataText() throws TskCoreException {
242  if (metaDataText != null) {
243  return metaDataText;
244  }
245 
246  // if there is no metadata for this file, return empty string
247  if (metaAddr == 0) {
248  metaDataText = new ArrayList<String>();
249  metaDataText.add("");
250  return metaDataText;
251  }
252 
253  loadFileHandle();
254  metaDataText = SleuthkitJNI.getFileMetaDataText(fileHandle);
255  return metaDataText;
256  }
257 
261  @Override
262  @SuppressWarnings("deprecation")
263  public synchronized void close() {
264  if (fileHandle != 0) {
265  SleuthkitJNI.closeFile(fileHandle);
266  fileHandle = 0;
267  }
268  }
269 
274  @Override
275  public void finalize() throws Throwable {
276  try {
277  close();
278  } finally {
279  super.finalize();
280  }
281  }
282 
289  @Override
290  public String toString(boolean preserveState) {
291  String path = "";
292  try {
293  path = getUniquePath();
294  } catch (TskCoreException ex) {
295  logger.log(Level.SEVERE, "Error loading unique path for object ID: {0}", this.getId());
296  }
297 
298  return super.toString(preserveState)
299  + "FsContent [\t" //NON-NLS
300  + "fsObjId " + getFileSystemId() //NON-NLS
301  + "\t" + "uniquePath " + path //NON-NLS
302  + "\t" + "fileHandle " + getFileHandle() //NON-NLS
303  + "]\t";
304  }
305 
345  @Deprecated
346  @SuppressWarnings("deprecation")
347  FsContent(SleuthkitCase db, long objId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
349  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
350  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath) {
351  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());
352  }
353 
404  @Deprecated
405  @SuppressWarnings("deprecation")
406  FsContent(SleuthkitCase db, long objId, long dataSourceObjectId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
407  String name, long metaAddr, int metaSeq, TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
408  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
409  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath, String mimeType) {
410  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());
411  }
412 
469  @Deprecated
470  @SuppressWarnings("deprecation")
471  FsContent(SleuthkitCase db,
472  long objId,
473  long dataSourceObjectId,
474  long fsObjId,
475  TSK_FS_ATTR_TYPE_ENUM attrType, int attrId,
476  String name,
477  TSK_DB_FILES_TYPE_ENUM fileType,
478  long metaAddr, int metaSeq,
479  TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
480  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags,
481  long size,
482  long ctime, long crtime, long atime, long mtime,
483  short modes, int uid, int gid,
484  String md5Hash, String sha256Hash, String sha1Hash,
485  FileKnown knownState,
486  String parentPath,
487  String mimeType,
488  String extension,
489  String ownerUid,
490  Long osAccountObjId,
491  List<Attribute> fileAttributes) {
492  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());
493  }
494 }
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:182
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:241
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:290
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.