Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DATDumper.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.drones;
20 
21 import java.io.File;
22 import java.io.FileNotFoundException;
23 import java.io.IOException;
24 import src.Files.ConvertDat;
25 import src.Files.CsvWriter;
26 import src.Files.DatFile;
27 import src.Files.DJIAssistantFile;
28 import src.Files.Exception.FileEnd;
29 import src.Files.Exception.NotDatFile;
30 
35 final class DATDumper {
36 
40  DATDumper() {
41  // This constructor is intentionally empty. Nothing special is needed here.
42  }
43 
54  void dumpDATFile(String datFilePath, String outputFilePath, boolean overWriteExisting) throws DroneIngestException {
55  // Validate the input and output file paths.
56  validateOutputFile(outputFilePath, overWriteExisting);
57  if (!isDATFile(datFilePath)) {
58  throw new DroneIngestException(String.format("Not a DAT file! DAT = %s", datFilePath)); //NON-NLS
59  }
60 
61  DatFile datFile = null;
62  try (CsvWriter writer = new CsvWriter(outputFilePath)) {
63  // Creates a version specific DatFile object
64  datFile = DatFile.createDatFile(datFilePath);
65  datFile.reset();
66  // preAnalyze does an inital pass of the DAT file to gather some
67  // information about the file.
68  datFile.preAnalyze();
69 
70  // Creates a version specific ConvertDat object
71  ConvertDat convertDat = datFile.createConVertDat();
72 
73  // The lower the sample rate the smaller the output csv file will be
74  // however the date will be less precise. For our purposes we are going
75  // a sample rate of 1.
76  convertDat.sampleRate = 1;
77 
78  // Setting the tickRangeLower and upper values reduces some of the
79  // noise invalid data in the output file.
80  if (datFile.gpsLockTick != -1) {
81  convertDat.tickRangeLower = datFile.gpsLockTick;
82  }
83 
84  if (datFile.lastMotorStopTick != -1) {
85  convertDat.tickRangeUpper = datFile.lastMotorStopTick;
86  }
87 
88  convertDat.setCsvWriter(writer);
89  convertDat.createRecordParsers();
90  datFile.reset();
91 
92  // Analyze does the work of parsing the data, everything prior was
93  // setup
94  convertDat.analyze(true);
95 
96  } catch (IOException | NotDatFile | FileEnd ex) {
97  throw new DroneIngestException(String.format("Failed to dump DAT file to csv. DAT = %s, CSV = %s", datFilePath, outputFilePath), ex); //NON-NLS
98  } finally {
99  if (datFile != null) {
100  datFile.close();
101  }
102  }
103  }
104 
116  private void validateOutputFile(String outputFileName, boolean overWriteExisting) throws DroneIngestException {
117  File csvFile = new File(outputFileName);
118 
119  if (csvFile.exists()) {
120  if (overWriteExisting) {
121  csvFile.delete();
122  } else {
123  throw new DroneIngestException(String.format("Unable to dump DAT file. overWriteExsiting is false and DAT output csv file exists: %s", outputFileName)); //NON-NLS
124  }
125  }
126  }
127 
136  public boolean isDATFile(String datFilePath) throws DroneIngestException {
137  File datFile = new File(datFilePath);
138 
139  if (!datFile.exists()) {
140  throw new DroneIngestException(String.format("Unable to dump DAT file DAT file does not exist: %s", datFilePath)); //NON-NLS
141  }
142 
143  try {
144  return DatFile.isDatFile(datFilePath) || DJIAssistantFile.isDJIDat(datFile);
145  } catch (FileNotFoundException ex) {
146  throw new DroneIngestException(String.format("Unable to dump DAT file. File not found %s", datFilePath), ex); //NON-NLS
147  }
148  }
149 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.