Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
RecentFilesChildren.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011 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.autopsy.datamodel;
20 
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.Arrays;
25 import java.util.Calendar;
26 import java.util.List;
27 import java.util.logging.Level;
29 import org.openide.nodes.ChildFactory;
30 import org.openide.nodes.Node;
31 import org.sleuthkit.datamodel.SleuthkitCase;
32 import org.sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
33 import org.sleuthkit.datamodel.TskCoreException;
34 
39 class RecentFilesChildren extends ChildFactory<RecentFiles.RecentFilesFilter> {
40 
41  private SleuthkitCase skCase;
42  private Calendar lastDay;
43  private final static Logger logger = Logger.getLogger(RecentFilesChildren.class.getName());
44 
45  public RecentFilesChildren(SleuthkitCase skCase) {
46  this.skCase = skCase;
47  }
48 
49  @Override
50  protected boolean createKeys(List<RecentFiles.RecentFilesFilter> list) {
51  list.addAll(Arrays.asList(RecentFiles.RecentFilesFilter.values()));
52  lastDay = Calendar.getInstance();
53  lastDay.setTimeInMillis(getLastTime() * 1000);
54  lastDay.set(Calendar.HOUR_OF_DAY, 0);
55  lastDay.set(Calendar.MINUTE, 0);
56  lastDay.set(Calendar.SECOND, 0);
57  lastDay.set(Calendar.MILLISECOND, 0);
58  return true;
59  }
60 
61  @Override
62  protected Node createNodeForKey(RecentFiles.RecentFilesFilter key) {
63  return new RecentFilesFilterNode(skCase, key, lastDay);
64  }
65 
66  private long getLastTime() {
67  String query = createMaxQuery("crtime"); //NON-NLS
68  long maxcr = runTimeQuery(query);
69  query = createMaxQuery("ctime"); //NON-NLS
70  long maxc = runTimeQuery(query);
71  query = createMaxQuery("mtime"); //NON-NLS
72  long maxm = runTimeQuery(query);
73  //query = createMaxQuery("atime");
74  //long maxa = runTimeQuery(query);
75  //return Math.max(maxcr, Math.max(maxc, Math.max(maxm, maxa)));
76  return Math.max(maxcr, Math.max(maxc, maxm));
77  }
78 
79  //TODO add a generic query to SleuthkitCase
80  private String createMaxQuery(String attr) {
81  return "SELECT MAX(" + attr + ") FROM tsk_files WHERE " + attr + " < " + System.currentTimeMillis() / 1000; //NON-NLS
82  }
83 
84  @SuppressWarnings("deprecation")
85  private long runTimeQuery(String query) {
86  long result = 0;
87 
88  try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
89  ResultSet resultSet = dbQuery.getResultSet();
90  resultSet.next();
91  result = resultSet.getLong(1);
92  } catch (TskCoreException | SQLException ex) {
93  logger.log(Level.WARNING, "Couldn't get recent files results: ", ex); //NON-NLS
94  }
95 
96  return result;
97  }
98 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.