Sleuth Kit Java Bindings (JNI)  4.6.0
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-2017 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.logging.Level;
22 import java.util.logging.Logger;
29 
43 public class LayoutFile extends AbstractFile {
44 
45  private long imageHandle = -1;
46 
82  long objId,
83  long dataSourceObjectId,
84  String name,
88  long size,
90  String parentPath, String mimeType) {
91  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, null);
92  }
93 
99  public int getNumParts() {
100  int numParts = 0;
101  try {
102  numParts = getRanges().size();
103  } catch (TskCoreException ex) {
104  Logger.getLogger(LayoutFile.class.getName()).log(Level.SEVERE, String.format("Error getting layout ranges for layout file (objId = %d)", getId()), ex); //NON-NLS
105  }
106  return numParts;
107  }
108 
115  @Override
116  public boolean isRoot() {
117  return false;
118  }
119 
124  @Override
125  public void close() {
126  }
127 
139  @Override
140  protected int readInt(byte[] buf, long offset, long len) throws TskCoreException {
141  long offsetInThisLayoutContent = 0; // current offset in this LayoutContent
142  int bytesRead = 0; // Bytes read so far
143 
144  if (imageHandle == -1) {
145  Content dataSource = getDataSource();
146  if ((dataSource != null) && (dataSource instanceof Image)) {
147  Image image = (Image) dataSource;
148  imageHandle = image.getImageHandle();
149  } else {
150  throw new TskCoreException("Data Source of LayoutFile is not Image");
151  }
152  }
153 
154  for (TskFileRange range : getRanges()) {
155  if (bytesRead < len) { // we haven't read enough yet
156  if (offset < offsetInThisLayoutContent + range.getByteLen()) { // if we are in a range object we want to read from
157  long offsetInRange = 0; // how far into the current range object to start reading
158  if (bytesRead == 0) { // we haven't read anything yet so we want to read from the correct offset in this range object
159  offsetInRange = offset - offsetInThisLayoutContent; // start reading from the correct offset
160  }
161  long offsetInImage = range.getByteStart() + offsetInRange; // how far into the image to start reading
162  long lenToRead = Math.min(range.getByteLen() - offsetInRange, len - bytesRead); // how much we can read this time
163  int lenRead = readImgToOffset(imageHandle, buf, bytesRead, offsetInImage, (int) lenToRead);
164  bytesRead += lenRead;
165  if (lenToRead != lenRead) { // If image read failed or was cut short
166  break;
167  }
168  }
169  offsetInThisLayoutContent += range.getByteLen();
170  } else { // we're done reading
171  break;
172  }
173  }
174  return bytesRead;
175  }
176 
193  private int readImgToOffset(long imgHandle, byte[] buf, int offsetInBuf, long offsetInImage, int lenToRead) throws TskCoreException {
194  byte[] currentBuffer = new byte[lenToRead]; // the buffer for the current range object
195  int lenRead = SleuthkitJNI.readImg(imgHandle, currentBuffer, offsetInImage, lenToRead);
196  System.arraycopy(currentBuffer, 0, buf, offsetInBuf, lenToRead); // copy what we just read into the main buffer
197  return lenRead;
198  }
199 
208  @Override
209  public <T> T accept(ContentVisitor<T> visitor) {
210  return visitor.visit(this);
211  }
212 
221  @Override
222  public <T> T accept(SleuthkitItemVisitor<T> visitor) {
223  return visitor.visit(this);
224  }
225 
232  @Override
233  public String toString(boolean preserveState) {
234  return super.toString(preserveState) + "LayoutFile [\t" + "]\t"; //NON-NLS
235  }
236 
265  @Deprecated
266  @SuppressWarnings("deprecation")
267  protected LayoutFile(SleuthkitCase db, long objId, String name,
268  TSK_DB_FILES_TYPE_ENUM fileType,
270  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags,
271  long size, String md5Hash, FileKnown knownState, String parentPath) {
272  this(db, objId, db.getDataSourceObjectId(objId), name, fileType, dirType, metaType, dirFlag, metaFlags, size, md5Hash, knownState, parentPath, null);
273  }
274 }
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)
final TSK_FS_META_TYPE_ENUM metaType
synchronized long getImageHandle()
Definition: Image.java:115

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