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

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