Sleuth Kit Java Bindings (JNI) 4.14.0
Java bindings for using The Sleuth Kit
Loading...
Searching...
No Matches
Sample.java
Go to the documentation of this file.
1/*
2 * Sleuth Kit Data Model
3 *
4 * Copyright 2012-2018 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 */
19package org.sleuthkit.datamodel.Examples;
20
21import java.util.ArrayList;
22import java.util.List;
23import java.util.UUID;
24import java.util.logging.Level;
25import java.util.logging.Logger;
26import org.sleuthkit.datamodel.AbstractFile;
27import org.sleuthkit.datamodel.Content;
28import org.sleuthkit.datamodel.Image;
29import org.sleuthkit.datamodel.SleuthkitCase;
30import org.sleuthkit.datamodel.SleuthkitJNI.CaseDbHandle.AddImageProcess;
31import org.sleuthkit.datamodel.TskCoreException;
32import org.sleuthkit.datamodel.TskDataException;
33
37public class Sample {
38
39 public static void run(String imagePath) {
40 try {
41 SleuthkitCase sk = SleuthkitCase.newCase(imagePath + ".db");
42
43 // initialize the case with an image
44 String timezone = "";
45 AddImageProcess process = sk.makeAddImageProcess(timezone, true, false, "");
46 ArrayList<String> paths = new ArrayList<String>();
47 paths.add(imagePath);
48 try {
49 process.run(UUID.randomUUID().toString(), paths.toArray(new String[paths.size()]), 0);
50 } catch (TskDataException ex) {
51 Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex);
52 }
53
54 // print out all the images found, and their children
55 List<Image> images = sk.getImages();
56 for (Image image : images) {
57 System.out.println("Found image: " + image.getName());
58 System.out.println("There are " + image.getChildren().size() + " children.");
59 for (Content content : image.getChildren()) {
60 System.out.println('"' + content.getName() + '"' + " is a child of " + image.getName());
61 }
62 }
63
64 // print out all .txt files found
65 List<AbstractFile> files = sk.findAllFilesWhere("LOWER(name) LIKE LOWER('%.txt')");
66 for (AbstractFile file : files) {
67 System.out.println("Found text file: " + file.getName());
68 }
69
70 } catch (TskCoreException e) {
71 System.out.println("Exception caught: " + e.getMessage());
72 Sample.usage(e.getMessage());
73
74 }
75 }
76
77 public static void usage(String error) {
78 System.out.println("Usage: ant -Dimage:{image string} run-sample");
79 if (error.contains("deleted first")) {
80 System.out.println("A database for the image already exists. Delete it to run this sample again.");
81 } else if (error.contains("unable to open database")) {
82 System.out.println("Image must be encapsulated by double quotes. Ex: ant -Dimage=\"C:\\Users\\You\\image.E01\" run-sample");
83 }
84 }
85
86 public static void main(String[] args) {
87 Sample.run(args[0]);
88 }
89}
static void usage(String error)
Definition Sample.java:77
static void run(String imagePath)
Definition Sample.java:39
static void main(String[] args)
Definition Sample.java:86
static SleuthkitCase newCase(String dbPath)
List< AbstractFile > findAllFilesWhere(String sqlWhereClause)
AddImageProcess makeAddImageProcess(String timeZone, boolean addUnallocSpace, boolean noFatFsOrphans, String imageCopyPath)
void run(String deviceId, String[] imageFilePaths, int sectorSize)
List< Content > getChildren()

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