Sleuth Kit Java Bindings (JNI)  4.11.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.Collections;
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 
90  long objId,
91  long dataSourceObjectId,
92  String name,
96  long size,
97  long ctime, long crtime, long atime, long mtime,
98  String md5Hash, String sha256Hash, FileKnown knownState,
99  String parentPath, String mimeType,
100  String ownerUid,
101  Long osAccountObjId) {
102 
103  super(db, objId, dataSourceObjectId, TSK_FS_ATTR_TYPE_ENUM.TSK_FS_ATTR_TYPE_DEFAULT, 0, name, fileType, 0L, 0, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, (short) 0, 0, 0, md5Hash, sha256Hash, knownState, parentPath, mimeType, SleuthkitCase.extractExtension(name), ownerUid, osAccountObjId, Collections.emptyList());
104  }
105 
111  public int getNumParts() {
112  int numParts = 0;
113  try {
114  numParts = getRanges().size();
115  } catch (TskCoreException ex) {
116  Logger.getLogger(LayoutFile.class.getName()).log(Level.SEVERE, String.format("Error getting layout ranges for layout file (objId = %d)", getId()), ex); //NON-NLS
117  }
118  return numParts;
119  }
120 
127  @Override
128  public boolean isRoot() {
129  return false;
130  }
131 
136  @Override
137  public void close() {
138  }
139 
151  @Override
152  protected int readInt(byte[] buf, long offset, long len) throws TskCoreException {
153  long offsetInThisLayoutContent = 0; // current offset in this LayoutContent
154  int bytesRead = 0; // Bytes read so far
155 
156  // if the caller has requested more data than we have in the file
157  // then make sure we don't go beyond the end of the file
158  long readLen = len;
159  if (offset + readLen > size)
160  readLen = size - offset;
161 
162  if (imageHandle == -1) {
163  Content dataSource = getDataSource();
164  if ((dataSource != null) && (dataSource instanceof Image)) {
165  Image image = (Image) dataSource;
166  imageHandle = image.getImageHandle();
167  } else {
168  throw new TskCoreException("Data Source of LayoutFile is not Image");
169  }
170  }
171 
172  for (TskFileRange range : getRanges()) {
173  if (bytesRead < readLen) { // we haven't read enough yet
174  if (offset < offsetInThisLayoutContent + range.getByteLen()) { // if we are in a range object we want to read from
175  long offsetInRange = 0; // how far into the current range object to start reading
176  if (bytesRead == 0) { // we haven't read anything yet so we want to read from the correct offset in this range object
177  offsetInRange = offset - offsetInThisLayoutContent; // start reading from the correct offset
178  }
179  long offsetInImage = range.getByteStart() + offsetInRange; // how far into the image to start reading
180  long lenToReadInRange = Math.min(range.getByteLen() - offsetInRange, readLen - bytesRead); // how much we can read this time
181  int lenRead = readImgToOffset(imageHandle, buf, bytesRead, offsetInImage, (int) lenToReadInRange);
182  bytesRead += lenRead;
183  if (lenToReadInRange != lenRead) { // If image read failed or was cut short
184  break;
185  }
186  }
187  offsetInThisLayoutContent += range.getByteLen();
188  } else { // we're done reading
189  break;
190  }
191  }
192  return bytesRead;
193  }
194 
211  private int readImgToOffset(long imgHandle, byte[] buf, int offsetInBuf, long offsetInImage, int lenToRead) throws TskCoreException {
212  byte[] currentBuffer = new byte[lenToRead]; // the buffer for the current range object
213  int lenRead = SleuthkitJNI.readImg(imgHandle, currentBuffer, offsetInImage, lenToRead);
214  System.arraycopy(currentBuffer, 0, buf, offsetInBuf, lenToRead); // copy what we just read into the main buffer
215  return lenRead;
216  }
217 
226  @Override
227  public <T> T accept(ContentVisitor<T> visitor) {
228  return visitor.visit(this);
229  }
230 
239  @Override
240  public <T> T accept(SleuthkitItemVisitor<T> visitor) {
241  return visitor.visit(this);
242  }
243 
250  @Override
251  public String toString(boolean preserveState) {
252  return super.toString(preserveState) + "LayoutFile [\t" + "]\t"; //NON-NLS
253  }
254 
283  @Deprecated
284  @SuppressWarnings("deprecation")
285  protected LayoutFile(SleuthkitCase db, long objId, String name,
286  TSK_DB_FILES_TYPE_ENUM fileType,
288  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags,
289  long size, String md5Hash, FileKnown knownState, String parentPath) {
290  this(db, objId, db.getDataSourceObjectId(objId), name, fileType, dirType, metaType, dirFlag, metaFlags, size, 0L, 0L, 0L, 0L, md5Hash, null, knownState, parentPath, null, OsAccount.NO_OWNER_ID, OsAccount.NO_ACCOUNT);
291  }
292 }
final TSK_FS_NAME_TYPE_ENUM dirType
static int readImg(long imgHandle, byte[] readBuffer, long offset, long len)
final TskData.TSK_DB_FILES_TYPE_ENUM fileType
String toString(boolean preserveState)
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:122

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.