19package org.sleuthkit.datamodel;
21import java.io.IOException;
22import java.nio.ByteBuffer;
23import java.nio.channels.FileChannel;
24import java.nio.file.Files;
25import java.nio.file.Path;
26import java.nio.file.Paths;
27import static java.nio.file.StandardOpenOption.READ;
28import java.util.ArrayList;
29import java.util.Collection;
30import java.util.Collections;
33import java.util.logging.Level;
34import java.util.logging.Logger;
35import org.sleuthkit.datamodel.Blackboard.BlackboardException;
36import org.sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction;
44 static long ID_NOT_SET = -1;
45 private long objectId = ID_NOT_SET;
46 private final String pathAsString;
47 private final Path pathAsPath;
48 private final long createdTime;
49 private final String sourceModuleName;
50 private final String reportName;
55 private FileChannel fileChannel =
null;
57 private static final Logger LOGGER = Logger.getLogger(Report.class.getName());
68 Report(
SleuthkitCase db,
long id, String path,
long createdTime, String sourceModuleName, String reportName,
Content parent) {
71 this.pathAsString = path;
72 if (path.startsWith(
"http")) {
73 this.pathAsPath =
null;
75 this.pathAsPath = Paths.get(path);
78 this.createdTime = createdTime;
79 this.sourceModuleName = sourceModuleName;
80 this.reportName = reportName;
95 return (pathAsPath !=
null ? pathAsPath.toString() : pathAsString);
114 return this.sourceModuleName;
128 if (pathAsPath ==
null || Files.isDirectory(pathAsPath)) {
132 int totalBytesRead = 0;
133 ByteBuffer data = ByteBuffer.wrap(buf);
135 if (fileChannel ==
null) {
136 fileChannel = FileChannel.open(pathAsPath, READ);
138 fileChannel.position(offset);
141 bytesRead = fileChannel.read(data);
142 if (bytesRead != -1) {
143 totalBytesRead += bytesRead;
145 }
while (bytesRead != -1 && data.hasRemaining());
146 }
catch (IOException ex) {
147 LOGGER.log(Level.SEVERE,
"Failed to read report file.", ex);
150 return totalBytesRead;
156 if (fileChannel !=
null) {
159 }
catch (IOException ex) {
160 LOGGER.log(Level.WARNING,
"Failed to close report file.", ex);
167 return (pathAsPath !=
null ? Files.size(pathAsPath) : 0);
168 }
catch (IOException ex) {
169 LOGGER.log(Level.SEVERE,
"Failed to get size of report.", ex);
178 return v.
visit(
this);
194 if (
null == parent) {
197 return parent.getDataSource();
203 return Collections.<
Content>emptyList();
218 if (parent ==
null) {
219 SleuthkitCase.ObjectInfo parentInfo;
220 parentInfo = db.getParentInfo(
this);
221 if (parentInfo ==
null) {
224 parent = db.getContentById(parentInfo.getId());
232 return Collections.<Long>emptyList();
242 long fileObjId =
getId();
246 return db.getBlackboard().newAnalysisResult(
248 null,
null,
null, Collections.emptyList())
249 .getAnalysisResult();
251 throw new TskCoreException(
"Unable to get analysis result for keword hit.", ex);
262 AnalysisResultAdded resultAdded = db.getBlackboard().newAnalysisResult(artifactType, objectId, dataSourceObjId, score, conclusion, configuration, justification, attributesList, trans);
276 AnalysisResultAdded resultAdded = db.getBlackboard().newAnalysisResult(artifactType, objectId, dataSourceId, score, conclusion, configuration, justification, attributesList, trans);
294 return db.getBlackboard().newDataArtifact(artifactType, objectId, this.
getDataSource().
getId(), attributesList, osAccountId);
304 return db.getBlackboard().newDataArtifact(artifactType, objectId, dataSourceId, attributesList, osAccountId);
313 @SuppressWarnings(
"deprecation")
321 return getArtifacts(db.getBlackboard().getArtifactType(artifactTypeName).getTypeID());
347 return db.getBlackboardArtifacts(artifactTypeID, objectId);
357 return db.getMatchingArtifacts(
"WHERE obj_id = " + objectId);
362 return db.getBlackboard().getAnalysisResults(objectId);
367 return db.getBlackboard().getDataArtifactsBySource(objectId);
372 return db.getBlackboard().getAnalysisResults(objectId, artifactType.getTypeID());
377 return db.getScoringManager().getAggregateScore(objectId);
382 return Collections.<String>emptySet();
387 return getArtifactsCount(db.getBlackboard().getArtifactType(artifactTypeName).getTypeID());
395 return db.getBlackboardArtifactsCount(artifactTypeID, objectId);
405 return db.getBlackboardArtifactsCount(objectId);
410 return v.
visit(
this);
ArrayList< BlackboardArtifact > getArtifacts(String artifactTypeName)
BlackboardArtifact getGenInfoArtifact(boolean create)
List< Long > getChildrenIds()
List< AnalysisResult > getAnalysisResults(BlackboardArtifact.Type artifactType)
BlackboardArtifact getGenInfoArtifact()
AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactType, Score score, String conclusion, String configuration, String justification, Collection< BlackboardAttribute > attributesList, long dataSourceId)
long getArtifactsCount(int artifactTypeID)
long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type)
String getSourceModuleName()
ArrayList< BlackboardAttribute > getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type)
long getArtifactsCount(String artifactTypeName)
DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection< BlackboardAttribute > attributesList, Long osAccountId)
AnalysisResultAdded newAnalysisResult(BlackboardArtifact.Type artifactType, Score score, String conclusion, String configuration, String justification, Collection< BlackboardAttribute > attributesList)
List< Content > getChildren()
ArrayList< BlackboardArtifact > getArtifacts(int artifactTypeID)
DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection< BlackboardAttribute > attributesList, Long osAccountId, long dataSourceId)
int read(byte[] buf, long offset, long len)
List< AnalysisResult > getAllAnalysisResults()
Set< String > getHashSetNames()
BlackboardArtifact newArtifact(int artifactTypeID)
BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type)
ArrayList< BlackboardArtifact > getAllArtifacts()
List< DataArtifact > getAllDataArtifacts()
ArrayList< BlackboardArtifact > getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type)
long getAllArtifactsCount()
Score getAggregateScore()
DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection< BlackboardAttribute > attributesList)
static final Score SCORE_UNKNOWN