Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilesIdentifierIngestModule.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 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.modules.interestingitems;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26 import java.util.logging.Level;
37 
42 final class FilesIdentifierIngestModule implements FileIngestModule {
43 
44  private static final Object sharedResourcesLock = new Object();
45  private static final Logger logger = Logger.getLogger(FilesIdentifierIngestModule.class.getName());
46  private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
47  private static final Map<Long, List<FilesSet>> interestingFileSetsByJob = new ConcurrentHashMap<>();
48  private final FilesIdentifierIngestJobSettings settings;
49  private IngestJobContext context;
50 
57  FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
58  this.settings = settings;
59  }
60 
64  @Override
65  public void startUp(IngestJobContext context) throws IngestModuleException {
66  this.context = context;
67  synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
68  if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
69  // Starting up the first instance of this module for this ingest
70  // job, so get the interesting file sets definitions snapshot
71  // for the job. Note that getting this snapshot atomically via a
72  // synchronized definitions manager method eliminates the need
73  // to disable the interesting files set definition UI during ingest.
74  List<FilesSet> filesSets = new ArrayList<>();
75  for (FilesSet set : InterestingItemDefsManager.getInstance().getInterestingFilesSets().values()) {
76  if (settings.interestingFilesSetIsEnabled(set.getName())) {
77  filesSets.add(set);
78  }
79  }
80  FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
81  }
82  }
83  }
84 
88  @Override
89  public ProcessResult process(AbstractFile file) {
90  // See if the file belongs to any defined interesting files set.
91  List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
92  for (FilesSet filesSet : filesSets) {
93  String ruleSatisfied = filesSet.fileIsMemberOf(file);
94  if (ruleSatisfied != null) {
95  try {
96  // Post an interesting files set hit artifact to the
97  // blackboard.
98  String moduleName = InterestingItemsIngestModuleFactory.getModuleName();
99  BlackboardArtifact artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
100 
101  // Add a set name attribute to the artifact. This adds a
102  // fair amount of redundant data to the attributes table
103  // (i.e., rows that differ only in artifact id), but doing
104  // otherwise would requires reworking the interesting files
105  // set hit artifact.
106  BlackboardAttribute setNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), moduleName, filesSet.getName());
107  artifact.addAttribute(setNameAttribute);
108 
109  // Add a category attribute to the artifact to record the
110  // interesting files set membership rule that was satisfied.
111  BlackboardAttribute ruleNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY.getTypeID(), moduleName, ruleSatisfied);
112  artifact.addAttribute(ruleNameAttribute);
113 
114  IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent(moduleName, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, Collections.singletonList(artifact)));
115 
116  } catch (TskCoreException ex) {
117  FilesIdentifierIngestModule.logger.log(Level.SEVERE, "Error posting to the blackboard", ex); //NOI18N
118  }
119  }
120  }
121  return ProcessResult.OK;
122  }
123 
127  @Override
128  public void shutDown() {
129  if (refCounter.decrementAndGet(this.context.getJobId()) == 0) {
130  // Shutting down the last instance of this module for this ingest
131  // job, so discard the interesting file sets definitions snapshot
132  // for the job.
133  FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());
134  }
135  }
136 }

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