Sleuth Kit Java Bindings (JNI)  4.11.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;
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 
107  long objId,
108  long dataSourceObjectId,
109  long fsObjId,
111  String name,
113  long metaAddr, int metaSeq,
116  long size,
117  long ctime, long crtime, long atime, long mtime,
118  short modes, int uid, int gid,
119  String md5Hash, String sha256Hash, String sha1Hash,
121  String parentPath,
122  String mimeType,
123  String extension,
124  String ownerUid,
125  Long osAccountObjId,
126  List<Attribute> fileAttributes) {
127  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, fileAttributes);
128  }
129 
135  public long getFileSystemId() {
136  return getFileSystemObjectId().orElse(0L);
137  }
138 
144  @SuppressWarnings("deprecation")
145  void loadFileHandle() throws TskCoreException {
146  if (fileHandle == 0) {
147  synchronized (this) {
148  if (fileHandle == 0) {
149  fileHandle = SleuthkitJNI.openFile(getFileSystem().getFileSystemHandle(), metaAddr, attrType, attrId, getSleuthkitCase());
150  }
151  }
152  }
153  }
154 
161  @SuppressWarnings("deprecation")
162  long getFileHandle() {
163  return fileHandle;
164  }
165 
177  @Override
178  @SuppressWarnings("deprecation")
179  protected synchronized int readInt(byte[] buf, long offset, long len) throws TskCoreException {
180  if (offset == 0 && size == 0) {
181  //special case for 0-size file
182  return 0;
183  }
184  loadFileHandle();
185  return SleuthkitJNI.readFile(fileHandle, buf, offset, len);
186  }
187 
188  @Override
189  public boolean isRoot() {
190  try {
191  FileSystem fs = getFileSystem();
192  return fs.getRoot_inum() == this.getMetaAddr();
193  } catch (TskCoreException ex) {
194  logger.log(Level.SEVERE, "Exception while calling 'getFileSystem' on " + this, ex); //NON-NLS
195  return false;
196  }
197  }
198 
207  public AbstractFile getParentDirectory() throws TskCoreException {
208  return getSleuthkitCase().getParentDirectory(this);
209  }
210 
218  @Override
219  public Content getDataSource() throws TskCoreException {
220  return getFileSystem().getDataSource();
221  }
222 
232  public synchronized List<String> getMetaDataText() throws TskCoreException {
233  if (metaDataText != null) {
234  return metaDataText;
235  }
236 
237  // if there is no metadata for this file, return empty string
238  if (metaAddr == 0) {
239  metaDataText = new ArrayList<String>();
240  metaDataText.add("");
241  return metaDataText;
242  }
243 
244  loadFileHandle();
245  metaDataText = SleuthkitJNI.getFileMetaDataText(fileHandle);
246  return metaDataText;
247  }
248 
252  @Override
253  @SuppressWarnings("deprecation")
254  public synchronized void close() {
255  if (fileHandle != 0) {
256  SleuthkitJNI.closeFile(fileHandle);
257  fileHandle = 0;
258  }
259  }
260 
265  @Override
266  public void finalize() throws Throwable {
267  try {
268  close();
269  } finally {
270  super.finalize();
271  }
272  }
273 
280  @Override
281  public String toString(boolean preserveState) {
282  String path = "";
283  try {
284  path = getUniquePath();
285  } catch (TskCoreException ex) {
286  logger.log(Level.SEVERE, "Error loading unique path for object ID: {0}", this.getId());
287  }
288 
289  return super.toString(preserveState)
290  + "FsContent [\t" //NON-NLS
291  + "fsObjId " + getFileSystemId() //NON-NLS
292  + "\t" + "uniquePath " + path //NON-NLS
293  + "\t" + "fileHandle " + getFileHandle() //NON-NLS
294  + "]\t";
295  }
296 
336  @Deprecated
337  @SuppressWarnings("deprecation")
338  FsContent(SleuthkitCase db, long objId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
340  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
341  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath) {
342  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());
343  }
344 
395  @Deprecated
396  @SuppressWarnings("deprecation")
397  FsContent(SleuthkitCase db, long objId, long dataSourceObjectId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
398  String name, long metaAddr, int metaSeq, TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
399  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
400  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath, String mimeType) {
401  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());
402  }
403 }
FS
File that can be found in file system tree.
Definition: TskData.java:687
final TSK_FS_NAME_TYPE_ENUM dirType
synchronized int readInt(byte[] buf, long offset, long len)
Definition: FsContent.java:179
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:232
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:281
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.