19 package org.sleuthkit.datamodel;
21 import java.io.BufferedReader;
22 import java.io.FileReader;
23 import java.io.IOException;
24 import java.text.DateFormat;
25 import java.text.SimpleDateFormat;
26 import java.util.ArrayList;
27 import java.util.GregorianCalendar;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.TimeZone;
54 private static native
long openCaseDbNat(String path)
throws TskCoreException;
56 private static native
void closeCaseDbNat(
long db)
throws TskCoreException;
58 private static native
int hashDbOpenNat(String hashDbPath)
throws TskCoreException;
60 private static native
int hashDbNewNat(String hashDbPath)
throws TskCoreException;
68 private static native
int hashDbAddEntryNat(String filename, String hashMd5, String hashSha1, String hashSha256, String comment,
int dbHandle)
throws TskCoreException;
80 private static native
void hashDbCloseAll() throws TskCoreException;
82 private static native
void hashDbClose(
int dbHandle) throws TskCoreException;
89 private static native
boolean hashDbIsIdxOnlyNat(
int dbHandle) throws TskCoreException;
91 private static native
boolean hashDbLookup(String hash,
int dbHandle) throws TskCoreException;
96 private static native
long initAddImgNat(
long db, String timezone,
boolean processUnallocSpace,
boolean noFatFsOrphans) throws TskCoreException;
98 private static native
void runAddImgNat(
long process, String[] imgPath,
int splits, String timezone) throws TskCoreException,
TskDataException;
100 private static native
void stopAddImgNat(
long process) throws TskCoreException;
102 private static native
void revertAddImgNat(
long process) throws TskCoreException;
104 private static native
long commitAddImgNat(
long process) throws TskCoreException;
107 private static native
long openImgNat(String[] imgPath,
int splits) throws TskCoreException;
109 private static native
long openVsNat(
long imgHandle,
long vsOffset) throws TskCoreException;
111 private static native
long openVolNat(
long vsHandle,
long volId) throws TskCoreException;
113 private static native
long openFsNat(
long imgHandle,
long fsId) throws TskCoreException;
115 private static native
long openFileNat(
long fsHandle,
long fileId,
int attrType,
int attrId) throws TskCoreException;
118 private static native
int readImgNat(
long imgHandle, byte[] readBuffer,
long offset,
long len) throws TskCoreException;
120 private static native
int readVsNat(
long vsHandle, byte[] readBuffer,
long offset,
long len) throws TskCoreException;
122 private static native
int readVolNat(
long volHandle, byte[] readBuffer,
long offset,
long len) throws TskCoreException;
124 private static native
int readFsNat(
long fsHandle, byte[] readBuffer,
long offset,
long len) throws TskCoreException;
126 private static native
int readFileNat(
long fileHandle, byte[] readBuffer,
long offset,
long len) throws TskCoreException;
131 private static native
void closeImgNat(
long imgHandle);
133 private static native
void closeVsNat(
long vsHandle);
135 private static native
void closeFsNat(
long fsHandle);
137 private static native
void closeFileNat(
long fileHandle);
140 private static native
long findDeviceSizeNat(String devicePath) throws TskCoreException;
142 private static native String
getCurDirNat(
long process);
162 private static final Map<Long, Map<Long, Long>>
fsHandleCache =
new HashMap<Long, Map<Long, Long>>();
165 this.caseDbPointer = pointer;
174 void free() throws TskCoreException {
192 AddImageProcess initAddImageProcess(String timezone,
boolean processUnallocSpace,
boolean noFatFsOrphans) {
193 return new AddImageProcess(timezone, processUnallocSpace, noFatFsOrphans);
208 private AddImageProcess(String timezone,
boolean processUnallocSpace,
boolean noFatFsOrphans) {
225 public void run(String[] imgPath)
throws TskCoreException, TskDataException {
226 if (autoDbPointer != 0) {
227 throw new TskCoreException(
"AddImgProcess:run: AutoDB pointer is already set");
230 synchronized (
this) {
233 if (autoDbPointer == 0) {
235 throw new TskCoreException(
"AddImgProcess::run: AutoDB pointer is NULL after initAddImgNat");
237 runAddImgNat(autoDbPointer, imgPath, imgPath.length, timezone);
248 public void stop() throws TskCoreException {
249 if (autoDbPointer == 0) {
250 throw new TskCoreException(
"AddImgProcess::stop: AutoDB pointer is NULL");
264 public synchronized void revert() throws TskCoreException {
265 if (autoDbPointer == 0) {
266 throw new TskCoreException(
"AddImgProcess::revert: AutoDB pointer is NULL");
285 public synchronized long commit() throws TskCoreException {
286 if (autoDbPointer == 0) {
287 throw new TskCoreException(
"AddImgProcess::commit: AutoDB pointer is NULL");
303 return autoDbPointer == 0 ?
"NO_INFO" :
getCurDirNat(autoDbPointer);
317 static CaseDbHandle newCaseDb(String path)
throws TskCoreException {
330 static CaseDbHandle openCaseDb(String path)
throws TskCoreException {
358 public synchronized static long openImage(String[] imageFiles)
throws TskCoreException {
359 long imageHandle = 0;
361 StringBuilder keyBuilder =
new StringBuilder();
362 for (
int i = 0; i < imageFiles.length; ++i) {
363 keyBuilder.append(imageFiles[i]);
365 final String imageKey = keyBuilder.toString();
372 imageHandle =
openImgNat(imageFiles, imageFiles.length);
390 public static long openVs(
long imgHandle,
long vsOffset)
throws TskCoreException {
404 public static long openVsPart(
long vsHandle,
long volId)
throws TskCoreException {
419 public synchronized static long openFs(
long imgHandle,
long fsOffset)
throws TskCoreException {
422 if (imgOffSetToFsHandle.containsKey(fsOffset)) {
424 fsHandle = imgOffSetToFsHandle.get(fsOffset);
426 fsHandle =
openFsNat(imgHandle, fsOffset);
428 imgOffSetToFsHandle.put(fsOffset, fsHandle);
445 return openFileNat(fsHandle, fileId, attrType.getValue(), attrId);
461 public static int readImg(
long imgHandle, byte[] readBuffer,
long offset,
long len)
throws TskCoreException {
463 return readImgNat(imgHandle, readBuffer, offset, len);
478 public static int readVs(
long vsHandle, byte[] readBuffer,
long offset,
long len)
throws TskCoreException {
479 return readVsNat(vsHandle, readBuffer, offset, len);
494 public static int readVsPart(
long volHandle, byte[] readBuffer,
long offset,
long len)
throws TskCoreException {
496 return readVolNat(volHandle, readBuffer, offset, len);
511 public static int readFs(
long fsHandle, byte[] readBuffer,
long offset,
long len)
throws TskCoreException {
513 return readFsNat(fsHandle, readBuffer, offset, len);
528 public static int readFile(
long fileHandle, byte[] readBuffer,
long offset,
long len)
throws TskCoreException {
529 return readFileNat(fileHandle, readBuffer, offset, len);
542 java.io.File tmp = java.io.File.createTempFile(
"tsk",
".txt");
546 FileReader fr =
new FileReader(tmp.getAbsolutePath());
547 BufferedReader textReader =
new BufferedReader(fr);
549 List<String> lines =
new ArrayList<String>();
551 String line = textReader.readLine();
561 }
catch (IOException ex) {
562 throw new TskCoreException(
"Error reading istat output: " + ex.getLocalizedMessage());
748 public static void addToHashDatabase(String filename, String md5, String sha1, String sha256, String comment,
int dbHandle)
throws TskCoreException {
752 public static void addToHashDatabase(List<HashEntry> hashes,
int dbHandle)
throws TskCoreException {
756 hashDbAddEntryNat(entry.getFileName(), entry.getMd5Hash(), entry.getSha1Hash(), entry.getSha256Hash(), entry.getComment(), dbHandle);
759 }
catch (TskCoreException ex) {
762 }
catch (TskCoreException ex2) {
787 if (timezoneLongForm == null || timezoneLongForm.isEmpty()) {
791 String timezoneShortForm =
"";
792 TimeZone zone = TimeZone.getTimeZone(timezoneLongForm);
793 int offset = zone.getRawOffset() / 1000;
794 int hour = offset / 3600;
795 int min = (offset % 3600) / 60;
796 DateFormat dfm =
new SimpleDateFormat(
"z");
797 dfm.setTimeZone(zone);
798 boolean hasDaylight = zone.useDaylightTime();
799 String first = dfm.format(
new GregorianCalendar(2010, 1, 1).getTime()).substring(0, 3);
800 String second = dfm.format(
new GregorianCalendar(2011, 6, 6).getTime()).substring(0, 3);
802 timezoneShortForm = first + Integer.toString(mid);
804 timezoneShortForm = timezoneShortForm +
":" + (min < 10 ?
"0" :
"") + Integer.toString(min);
807 timezoneShortForm = timezoneShortForm + second;
809 return timezoneShortForm;
static native boolean hashDbIsUpdateableNat(int dbHandle)
static int readImg(long imgHandle, byte[] readBuffer, long offset, long len)
static native long commitAddImgNat(long process)
static native int readFileNat(long fileHandle, byte[] readBuffer, long offset, long len)
static String getHashDatabaseIndexPath(int dbHandle)
static native void closeVsNat(long vsHandle)
static int readVs(long vsHandle, byte[] readBuffer, long offset, long len)
static void createLookupIndexForHashDatabase(int dbHandle)
static native void startVerboseLoggingNat(String logPath)
static native long initAddImgNat(long db, String timezone, boolean processUnallocSpace, boolean noFatFsOrphans)
static void addToHashDatabase(String filename, String md5, String sha1, String sha256, String comment, int dbHandle)
static native int readImgNat(long imgHandle, byte[] readBuffer, long offset, long len)
static int createHashDatabase(String path)
static native String getCurDirNat(long process)
static void closeFs(long fsHandle)
static native int hashDbRollbackTransactionNat(int dbHandle)
static long openFile(long fsHandle, long fileId, TSK_FS_ATTR_TYPE_ENUM attrType, int attrId)
void run(String[] imgPath)
static int readFile(long fileHandle, byte[] readBuffer, long offset, long len)
static native int hashDbAddEntryNat(String filename, String hashMd5, String hashSha1, String hashSha256, String comment, int dbHandle)
static native int readVsNat(long vsHandle, byte[] readBuffer, long offset, long len)
static native void revertAddImgNat(long process)
CaseDbHandle(long pointer)
static native void runAddImgNat(long process, String[] imgPath, int splits, String timezone)
static HashHitInfo lookupInHashDatabaseVerbose(String hash, int dbHandle)
static native String getVersionNat()
static native boolean hashDbIndexExistsNat(int dbHandle)
static native long findDeviceSizeNat(String devicePath)
static long openVs(long imgHandle, long vsOffset)
synchronized long commit()
static native int saveFileMetaDataTextNat(long fileHandle, String fileName)
static native boolean hashDbIsIdxOnlyNat(int dbHandle)
static native long openVolNat(long vsHandle, long volId)
static native void closeFsNat(long fsHandle)
static native void hashDbClose(int dbHandle)
static native int readFsNat(long fsHandle, byte[] readBuffer, long offset, long len)
static boolean hashDatabaseIsIndexOnly(int dbHandle)
synchronized void revert()
static int readVsPart(long volHandle, byte[] readBuffer, long offset, long len)
static boolean loadSleuthkitJNI()
static native HashHitInfo hashDbLookupVerbose(String hash, int dbHandle)
static native int hashDbCommitTransactionNat(int dbHandle)
static final int MAX_DATABASES
static final Map< Long, Map< Long, Long > > fsHandleCache
static synchronized long openFs(long imgHandle, long fsOffset)
static native int hashDbOpenNat(String hashDbPath)
static void closeVs(long vsHandle)
static native long newCaseDbNat(String dbPath)
static native long openImgNat(String[] imgPath, int splits)
static long findDeviceSize(String devPath)
static String getHashDatabaseDisplayName(int dbHandle)
static native long openFileNat(long fsHandle, long fileId, int attrType, int attrId)
static native void closeFileNat(long fileHandle)
static List< String > getFileMetaDataText(long fileHandle)
static void closeImg(long imgHandle)
static native long openVsNat(long imgHandle, long vsOffset)
static native boolean hashDbLookup(String hash, int dbHandle)
static final Map< String, Long > imageHandleCache
static native int readVolNat(long volHandle, byte[] readBuffer, long offset, long len)
static String timezoneLongToShort(String timezoneLongForm)
synchronized String currentDirectory()
static native void hashDbCloseAll()
static int openHashDatabase(String path)
static native int hashDbBeginTransactionNat(int dbHandle)
static void closeFile(long fileHandle)
static boolean lookupInHashDatabase(String hash, int dbHandle)
static boolean hashDatabaseHasLookupIndex(int dbHandle)
AddImageProcess(String timezone, boolean processUnallocSpace, boolean noFatFsOrphans)
static synchronized long openImage(String[] imageFiles)
static native long openFsNat(long imgHandle, long fsId)
static native void closeCaseDbNat(long db)
static long openVsPart(long vsHandle, long volId)
static boolean isUpdateableHashDatabase(int dbHandle)
static native int hashDbNewNat(String hashDbPath)
static void addToHashDatabase(List< HashEntry > hashes, int dbHandle)
static native void stopAddImgNat(long process)
static void closeAllHashDatabases()
static native void closeImgNat(long imgHandle)
boolean processUnallocSpace
static boolean hashDatabaseCanBeReindexed(int dbHandle)
static native String hashDbGetDisplayName(int dbHandle)
static native String hashDbIndexPathNat(int dbHandle)
static String getVersion()
volatile long autoDbPointer
static void startVerboseLogging(String logPath)
static native void hashDbCreateIndexNat(int dbHandle)
static native String hashDbPathNat(int dbHandle)
static int readFs(long fsHandle, byte[] readBuffer, long offset, long len)
static String getHashDatabasePath(int dbHandle)
static void closeHashDatabase(int dbHandle)
static native long openCaseDbNat(String path)
static native boolean hashDbIsReindexableNat(int dbHandle)