Sleuth Kit Java Bindings (JNI)  4.2
Java bindings for using The Sleuth Kit
DerivedFile.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2013 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.text.MessageFormat;
22 import java.util.ResourceBundle;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 
32 
42 public class DerivedFile extends AbstractFile {
43 
44  private volatile DerivedMethod derivedMethod;
45  private static final Logger logger = Logger.getLogger(DerivedFile.class.getName());
46  private static ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
47  private boolean hasDerivedMethod = true;
48 
72  long ctime, long crtime, long atime, long mtime,
73  String md5Hash, FileKnown knownState, String parentPath, String localPath, long parentId) {
74 
75  super(db, objId, TskData.TSK_FS_ATTR_TYPE_ENUM.TSK_FS_ATTR_TYPE_DEFAULT, (short) 0,
76  name, TSK_DB_FILES_TYPE_ENUM.LOCAL, 0L, 0, dirType, metaType, dirFlag,
77  metaFlags, size, ctime, crtime, atime, mtime, (short) 0, 0, 0, md5Hash, knownState, parentPath);
78 
79  //use the local path read infrastructure
80  setLocalPath(localPath, false); //local paths for derived files are relative to case db
81  }
82 
83  @Override
84  public boolean isRoot() {
85  //not a root of a fs, since it always has a parent
86  return false;
87  }
88 
89  @Override
91  //TODO need schema support to implement this more efficiently
93  Content dataSource = parent.getDataSource();
94  while (dataSource == null) {
95  parent = parent.getParent();
96  if (parent == null) {
97  //should never happen
98  break;
99  }
100  dataSource = parent.getDataSource();
101  }
102  return dataSource;
103  }
104 
105  @Override
106  public List<Content> getChildren() throws TskCoreException {
107  //derived file/dir children, can only be other derived files
108  return getSleuthkitCase().getAbstractFileChildren(this, TSK_DB_FILES_TYPE_ENUM.DERIVED);
109 
110  }
111 
112  @Override
113  public List<Long> getChildrenIds() throws TskCoreException {
114  //derived file/dir children, can only be other derived files
115  return getSleuthkitCase().getAbstractFileChildrenIds(this, TSK_DB_FILES_TYPE_ENUM.DERIVED);
116  }
117 
118  @Override
119  public <T> T accept(SleuthkitItemVisitor<T> v) {
120  return v.visit(this);
121  }
122 
123  @Override
124  public <T> T accept(ContentVisitor<T> v) {
125  return v.visit(this);
126  }
127 
135  public synchronized DerivedMethod getDerivedMethod() throws TskCoreException {
136  if (derivedMethod == null && hasDerivedMethod == true) {
137  try {
138  derivedMethod = getSleuthkitCase().getDerivedMethod(getId());
139  if (derivedMethod == null) {
140  hasDerivedMethod = false; //do not attempt to lazy load
141  }
142  } catch (TskCoreException e) {
143  String msg = MessageFormat.format(bundle.getString("DerviedFile.derivedMethod.exception.msg1.text"), getId());
144  logger.log(Level.WARNING, msg, e);
145  throw new TskCoreException(msg, e);
146  }
147  }
148 
149  return derivedMethod;
150  }
151 
152  @Override
153  protected void finalize() throws Throwable {
154  try {
155  close();
156  } finally {
157  super.finalize(); //To change body of generated methods, choose Tools | Templates.
158  }
159  }
160 
161  @Override
162  public String toString(boolean preserveState) {
163  return super.toString(preserveState) + "DerivedFile{" //NON-NLS
164  + "derivedMethod=" + derivedMethod //NON-NLS
165  + ", hasDerivedMethod=" + hasDerivedMethod //NON-NLS
166  + '}';
167  }
168 
173  public static class DerivedMethod {
174 
175  private int derivedId;
176  private String toolName;
177  private String toolVersion;
178  private String other;
179  private String rederiveDetails;
180 
181  public DerivedMethod(int derivedId, String rederiveDetails) {
182  this.derivedId = derivedId;
183  this.rederiveDetails = rederiveDetails;
184  if (this.rederiveDetails == null) {
185  this.rederiveDetails = "";
186  }
187  this.toolName = "";
188  this.toolVersion = "";
189  this.other = "";
190  }
191 
192  void setToolName(String toolName) {
193  this.toolName = toolName;
194  }
195 
196  void setToolVersion(String toolVersion) {
197  this.toolVersion = toolVersion;
198  }
199 
200  void setOther(String other) {
201  this.other = other;
202  }
203 
204  public int getDerivedId() {
205  return derivedId;
206  }
207 
208  public String getToolName() {
209  return toolName;
210  }
211 
212  public String getToolVersion() {
213  return toolVersion;
214  }
215 
216  public String getOther() {
217  return other;
218  }
219 
220  public String getRederiveDetails() {
221  return rederiveDetails;
222  }
223 
224  @Override
225  public String toString() {
226  return "DerivedMethod{" + "derived_id=" + derivedId + ", toolName=" + toolName + ", toolVersion=" + toolVersion + ", other=" + other + ", rederiveDetails=" + rederiveDetails + '}'; //NON-NLS
227  }
228  }
229 }
final TSK_FS_NAME_TYPE_ENUM dirType
DerivedMethod(int derivedId, String rederiveDetails)
final TSK_FS_NAME_FLAG_ENUM dirFlag
String rederiveDetails
details to rederive specific to this method
DerivedFile(SleuthkitCase db, long objId, String name, TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType, TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime, String md5Hash, FileKnown knownState, String parentPath, String localPath, long parentId)
LOCAL
Local file that was added (not from a disk image)
Definition: TskData.java:647
String toString(boolean preserveState)
boolean hasDerivedMethod
whether it has the derived method to lazy load or not
final Set< TSK_FS_META_FLAG_ENUM > metaFlags
String localPath
local path as stored in db tsk_files_path, is relative to the db,
DERIVED
File derived from a parent file (i.e. from ZIP)
Definition: TskData.java:646
String toolName
Name of derivation method/tool.
int derivedId
Unique id for this derivation method.
volatile DerivedMethod derivedMethod
synchronized DerivedMethod getDerivedMethod()
void setLocalPath(String localPath, boolean isAbsolute)
final TSK_FS_META_TYPE_ENUM metaType
String toolVersion
Version of tool used in derivation method.

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