Sleuth Kit Java Bindings (JNI)  4.3
Java bindings for using The Sleuth Kit
LayoutFile.java
Go to the documentation of this file.
1 /*
2  * SleuthKit Java Bindings
3  *
4  * Copyright 2011-2016 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.List;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
30 
44 public class LayoutFile extends AbstractFile {
45 
46  private long imageHandle = -1;
47 
83  long objId,
84  long dataSourceObjectId,
85  String name,
89  long size,
91  String parentPath, String mimeType) {
92  super(db, objId, dataSourceObjectId, TSK_FS_ATTR_TYPE_ENUM.TSK_FS_ATTR_TYPE_DEFAULT, 0, name, fileType, 0L, 0, dirType, metaType, dirFlag, metaFlags, size, 0L, 0L, 0L, 0L, (short) 0, 0, 0, md5Hash, knownState, parentPath, mimeType);
93  }
94 
100  public int getNumParts() {
101  int numParts = 0;
102  try {
103  numParts = getRanges().size();
104  } catch (TskCoreException ex) {
105  Logger.getLogger(LayoutFile.class.getName()).log(Level.SEVERE, String.format("Error getting layout ranges for layout file (objId = %d)", getId()), ex); //NON-NLS
106  }
107  return numParts;
108  }
109 
116  @Override
117  public boolean isRoot() {
118  return false;
119  }
120 
129  @Override
130  public List<Content> getChildren() throws TskCoreException {
131  return getSleuthkitCase().getAbstractFileChildren(this, TskData.TSK_DB_FILES_TYPE_ENUM.DERIVED);
132  }
133 
143  @Override
144  public List<Long> getChildrenIds() throws TskCoreException {
145  return getSleuthkitCase().getAbstractFileChildrenIds(this, TskData.TSK_DB_FILES_TYPE_ENUM.DERIVED);
146  }
147 
152  @Override
153  public void close() {
154  }
155 
167  @Override
168  protected int readInt(byte[] buf, long offset, long len) throws TskCoreException {
169  long offsetInThisLayoutContent = 0; // current offset in this LayoutContent
170  int bytesRead = 0; // Bytes read so far
171 
172  if (imageHandle == -1) {
173  Content dataSource = getDataSource();
174  if ((dataSource != null) && (dataSource instanceof Image)) {
175  Image image = (Image) dataSource;
176  imageHandle = image.getImageHandle();
177  } else {
178  throw new TskCoreException("Data Source of LayoutFile is not Image");
179  }
180  }
181 
182  for (TskFileRange range : getRanges()) {
183  if (bytesRead < len) { // we haven't read enough yet
184  if (offset < offsetInThisLayoutContent + range.getByteLen()) { // if we are in a range object we want to read from
185  long offsetInRange = 0; // how far into the current range object to start reading
186  if (bytesRead == 0) { // we haven't read anything yet so we want to read from the correct offset in this range object
187  offsetInRange = offset - offsetInThisLayoutContent; // start reading from the correct offset
188  }
189  long offsetInImage = range.getByteStart() + offsetInRange; // how far into the image to start reading
190  long lenToRead = Math.min(range.getByteLen() - offsetInRange, len - bytesRead); // how much we can read this time
191  int lenRead = readImgToOffset(imageHandle, buf, bytesRead, offsetInImage, (int) lenToRead);
192  bytesRead += lenRead;
193  if (lenToRead != lenRead) { // If image read failed or was cut short
194  break;
195  }
196  }
197  offsetInThisLayoutContent += range.getByteLen();
198  } else { // we're done reading
199  break;
200  }
201  }
202  return bytesRead;
203  }
204 
215  private int readImgToOffset(long imgHandle, byte[] buf, int offsetInBuf, long offsetInImage, int lenToRead) throws TskCoreException {
216  byte[] currentBuffer = new byte[lenToRead]; // the buffer for the current range object
217  int lenRead = SleuthkitJNI.readImg(imgHandle, currentBuffer, offsetInImage, lenToRead);
218  System.arraycopy(currentBuffer, 0, buf, offsetInBuf, lenToRead); // copy what we just read into the main buffer
219  return lenRead;
220  }
221 
230  @Override
231  public <T> T accept(ContentVisitor<T> v) {
232  return v.visit(this);
233  }
234 
243  @Override
244  public <T> T accept(SleuthkitItemVisitor<T> v) {
245  return v.visit(this);
246  }
247 
257  @Override
258  public String toString(boolean preserveState) {
259  return super.toString(preserveState) + "LayoutFile [\t" + "]\t"; //NON-NLS
260  }
261 
290  @Deprecated
291  @SuppressWarnings("deprecation")
292  protected LayoutFile(SleuthkitCase db, long objId, String name,
296  long size, String md5Hash, FileKnown knownState, String parentPath) {
297  this(db, objId, db.getDataSourceObjectId(objId), name, fileType, dirType, metaType, dirFlag, metaFlags, size, md5Hash, knownState, parentPath, null);
298  }
299 
300 }
final TSK_FS_NAME_TYPE_ENUM dirType
static int readImg(long imgHandle, byte[] readBuffer, long offset, long len)
final TSK_FS_NAME_FLAG_ENUM dirFlag
final TskData.TSK_DB_FILES_TYPE_ENUM fileType
String toString(boolean preserveState)
final Set< TSK_FS_META_FLAG_ENUM > metaFlags
int readInt(byte[] buf, long offset, long len)
DERIVED
File derived from a parent file (i.e. from ZIP)
Definition: TskData.java:658
int readImgToOffset(long imgHandle, byte[] buf, int offsetInBuf, long offsetInImage, int lenToRead)
final TSK_FS_META_TYPE_ENUM metaType
synchronized long getImageHandle()
Definition: Image.java:72

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.