From c721a89f5fd928a5da89a4b2dfcc114d628208c0 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 2 Apr 2020 17:40:08 -0400 Subject: [PATCH] 6217 Refactor geo json attr utils --- .../autopsy/geolocation/datamodel/Route.java | 18 +-- .../autopsy/geolocation/datamodel/Track.java | 116 +++++++++--------- .../autopsy/modules/drones/DATExtractor.java | 16 +-- .../GPX_Module/GPX_Parser_Module.py | 18 ++- .../android/googlemaplocation.py | 10 +- InternalPythonModules/android/oruxmaps.py | 7 +- 6 files changed, 93 insertions(+), 92 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Route.java b/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Route.java index 67de1e55ba..cbe54fe9c1 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Route.java +++ b/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Route.java @@ -25,9 +25,9 @@ import java.util.Map; import org.openide.util.NbBundle.Messages; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoWaypointsUtil; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoWaypointsUtil.GeoWaypointList.GeoWaypoint; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoWaypointsUtil.GeoWaypointList; +import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil; +import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil.InvalidJsonException; +import org.sleuthkit.datamodel.blackboardutils.attributes.GeoWaypoints; /** * A Route represents a TSK_GPS_ROUTE artifact which has a start and end point @@ -42,8 +42,6 @@ public class Route extends GeoPath { // This list is not expected to change after construction so the // constructor will take care of creating an unmodifiable List private final List propertiesList; - - private static final TskGeoWaypointsUtil attributeUtil = new TskGeoWaypointsUtil(); /** * Construct a route for the given artifact. @@ -119,9 +117,13 @@ public class Route extends GeoPath { } if (attribute != null) { - GeoWaypointList waypoints = attributeUtil.fromAttribute(attribute); - - for(GeoWaypoint waypoint: waypoints) { + GeoWaypoints waypoints; + try { + waypoints = BlackboardJsonAttrUtil.fromAttribute(attribute, GeoWaypoints.class); + } catch (InvalidJsonException ex) { + throw new GeoLocationDataException(String.format("Unable to parse waypoints in TSK_GEO_WAYPOINTS attribute (artifact object ID =%d)", artifact.getId()), ex); + } + for (GeoWaypoints.Waypoint waypoint : waypoints) { addToPath(new Waypoint(artifact, label, null, waypoint.getLatitude(), waypoint.getLongitude(), waypoint.getAltitude(), null, attributeMap, this)); } } else { diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Track.java b/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Track.java index 213bd6b5f5..68da242b8a 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Track.java +++ b/Core/src/org/sleuthkit/autopsy/geolocation/datamodel/Track.java @@ -1,5 +1,4 @@ /* - * * Autopsy Forensic Browser * * Copyright 2020 Basis Technology Corp. @@ -26,26 +25,24 @@ import java.util.Map; import org.openide.util.NbBundle.Messages; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoTrackpointsUtil; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoTrackpointsUtil.GeoTrackPointList; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoTrackpointsUtil.GeoTrackPointList.GeoTrackPoint; +import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil; +import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil.InvalidJsonException; +import org.sleuthkit.datamodel.blackboardutils.attributes.GeoTrackPoints; /** * A GPS track with which wraps the TSK_GPS_TRACK artifact. */ -public final class Track extends GeoPath{ +public final class Track extends GeoPath { private final Long startTimestamp; private final Long endTimeStamp; - - private static final TskGeoTrackpointsUtil attributeUtil = new TskGeoTrackpointsUtil(); /** * Construct a new Track for the given artifact. - * + * * @param artifact - * - * @throws GeoLocationDataException + * + * @throws GeoLocationDataException */ public Track(BlackboardArtifact artifact) throws GeoLocationDataException { this(artifact, Waypoint.getAttributesFromArtifactAsMap(artifact)); @@ -53,49 +50,49 @@ public final class Track extends GeoPath{ /** * Construct a Track for the given artifact and attributeMap. - * - * @param artifact TSK_GPD_TRACK artifact - * @param attributeMap Map of the artifact attributes - * - * @throws GeoLocationDataException + * + * @param artifact TSK_GPD_TRACK artifact + * @param attributeMap Map of the artifact attributes + * + * @throws GeoLocationDataException */ private Track(BlackboardArtifact artifact, Map attributeMap) throws GeoLocationDataException { super(artifact, getTrackName(attributeMap)); - GeoTrackPointList points = getPointsList(attributeMap); + GeoTrackPoints points = getPointsList(attributeMap); buildPath(points, artifact); startTimestamp = points.getStartTime(); endTimeStamp = points.getEndTime(); } - + /** * Returns the start time of this track. - * - * @return Earliest time, or null if none was available. - * (seconds from java epoch) + * + * @return Earliest time, or null if none was available. (seconds from java + * epoch) */ public Long getStartTime() { return startTimestamp; } - + /** * Returns the end time of this track. - * - * @return Earliest timestamp, or null if none was available. - * (seconds from java epoch) + * + * @return Earliest timestamp, or null if none was available. (seconds from + * java epoch) */ public Long getEndTime() { return endTimeStamp; } /** - * Return the name of the track from the attributeMap. - * Track name is stored in the attribute TSK_NAME - * + * Return the name of the track from the attributeMap. Track name is stored + * in the attribute TSK_NAME + * * @param attributeMap - - * @return Track name or empty string if none was available. + * + * @return Track name or empty string if none was available. */ private static String getTrackName(Map attributeMap) { BlackboardAttribute attribute = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME); @@ -105,38 +102,41 @@ public final class Track extends GeoPath{ /** * Create the list of TrackWaypoints from the GeoTrackPoint list. - * - * @param points List of GeoTrackPoints - * + * + * @param points GeoTrackPoints object. * @param artifact The artifact to which these points belong - * - * @throws GeoLocationDataException + * + * @throws GeoLocationDataException */ @Messages({ "# {0} - track name", "GEOTrack_point_label_header=Trackpoint for track: {0}" }) - private void buildPath(GeoTrackPointList points, BlackboardArtifact artifact) - throws GeoLocationDataException { - for(GeoTrackPoint point: points) { + private void buildPath(GeoTrackPoints points, BlackboardArtifact artifact) throws GeoLocationDataException { + for (GeoTrackPoints.TrackPoint point : points) { addToPath(new TrackWaypoint(artifact, Bundle.GEOTrack_point_label_header(getLabel()), point)); } } /** - * Returns the list of GeoTrackPoints from the attributeMap. Creates the + * Returns the list of GeoTrackPoints from the attributeMap. Creates the * GeoTrackPoint list from the TSK_GEO_TRACKPOINTS attribute. - * + * * @param attributeMap Map of artifact attributes. - * + * * @return GeoTrackPoint list empty list if the attribute was not found. + * + * @throws GeoLocationDataException */ - private GeoTrackPointList getPointsList(Map attributeMap) { + private GeoTrackPoints getPointsList(Map attributeMap) throws GeoLocationDataException { BlackboardAttribute attribute = attributeMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_TRACKPOINTS); if (attribute != null) { - return attributeUtil.fromAttribute(attribute); + try { + return BlackboardJsonAttrUtil.fromAttribute(attribute, GeoTrackPoints.class); + } catch (InvalidJsonException ex) { + throw new GeoLocationDataException("Unable to parse track points in TSK_GEO_TRACKPOINTS attribute", ex); + } } - return null; } @@ -149,16 +149,16 @@ public final class Track extends GeoPath{ /** * Construct a TrackWaypoint. - * - * @param artifact the artifact to which this waypoint belongs - * + * + * @param artifact the artifact to which this waypoint belongs + * * @param pointLabel the label for the waypoint - * - * @param point GeoTrackPoint - * - * @throws GeoLocationDataException + * + * @param point GeoTrackPoint + * + * @throws GeoLocationDataException */ - TrackWaypoint(BlackboardArtifact artifact, String pointLabel, GeoTrackPoint point) throws GeoLocationDataException { + TrackWaypoint(BlackboardArtifact artifact, String pointLabel, GeoTrackPoints.TrackPoint point) throws GeoLocationDataException { super(artifact, pointLabel, point.getTimeStamp(), point.getLatitude(), @@ -172,10 +172,10 @@ public final class Track extends GeoPath{ } /** - * Overloaded to return a property list that is generated from - * the GeoTrackPoint instead of an artifact. - * - * @return unmodifiable list of Waypoint.Property + * Overloaded to return a property list that is generated from the + * GeoTrackPoint instead of an artifact. + * + * @return unmodifiable list of Waypoint.Property */ @Override public List getOtherProperties() { @@ -184,16 +184,16 @@ public final class Track extends GeoPath{ /** * Create a propertyList specific to GeoTrackPoints. - * + * * @param point GeoTrackPoint to get values from. - * + * * @return A list of Waypoint.properies. */ @Messages({ "Track_distanceTraveled_displayName=Distance traveled", "Track_distanceFromHome_displayName=Distance from home point" }) - private List createPropertyList(GeoTrackPoint point) { + private List createPropertyList(GeoTrackPoints.TrackPoint point) { List list = new ArrayList<>(); Long timestamp = point.getTimeStamp(); diff --git a/Core/src/org/sleuthkit/autopsy/modules/drones/DATExtractor.java b/Core/src/org/sleuthkit/autopsy/modules/drones/DATExtractor.java index 97cfbd40be..3966317d15 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/drones/DATExtractor.java +++ b/Core/src/org/sleuthkit/autopsy/modules/drones/DATExtractor.java @@ -41,11 +41,11 @@ import org.sleuthkit.autopsy.ingest.DataSourceIngestModuleProgress; import org.sleuthkit.autopsy.ingest.IngestJobContext; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoTrackpointsUtil.GeoTrackPointList.GeoTrackPoint; import org.sleuthkit.datamodel.blackboardutils.GeoArtifactsHelper; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.Blackboard.BlackboardException; -import org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoTrackpointsUtil.GeoTrackPointList; +import org.sleuthkit.datamodel.blackboardutils.attributes.GeoTrackPoints; +import org.sleuthkit.datamodel.blackboardutils.attributes.GeoTrackPoints.TrackPoint; /** * Extract drone position data from DJI Phantom drones. @@ -111,7 +111,7 @@ final class DATExtractor extends DroneExtractor { } // Process the csv file - GeoTrackPointList trackPoints = processCSVFile(context, DATFile, csvFilePath); + GeoTrackPoints trackPoints = processCSVFile(context, DATFile, csvFilePath); if (trackPoints != null && !trackPoints.isEmpty()) { (new GeoArtifactsHelper(getSleuthkitCase(), getName(), "DatCon", DATFile)).addTrack(DATFile.getName(), trackPoints, null); @@ -188,8 +188,8 @@ final class DATExtractor extends DroneExtractor { * * @throws DroneIngestException */ - private GeoTrackPointList processCSVFile(IngestJobContext context, AbstractFile DATFile, String csvFilePath) throws DroneIngestException { - GeoTrackPointList trackPoints = new GeoTrackPointList(); + private GeoTrackPoints processCSVFile(IngestJobContext context, AbstractFile DATFile, String csvFilePath) throws DroneIngestException { + GeoTrackPoints trackPoints = new GeoTrackPoints(); try (BufferedReader reader = new BufferedReader(new FileReader(new File(csvFilePath)))) { // First read in the header line and process String line = reader.readLine(); @@ -201,7 +201,7 @@ final class DATExtractor extends DroneExtractor { } String[] values = line.split(","); //NON-NLS - GeoTrackPoint point = createTrackPoint(headerMap, values); + TrackPoint point = createTrackPoint(headerMap, values); if (point != null) { trackPoints.addPoint(point); } @@ -246,7 +246,7 @@ final class DATExtractor extends DroneExtractor { * * @throws DroneIngestException */ - private GeoTrackPoint createTrackPoint(Map columnLookup, String[] values) throws DroneIngestException { + private TrackPoint createTrackPoint(Map columnLookup, String[] values) throws DroneIngestException { Double latitude = getDoubleValue(columnLookup.get(HEADER_LAT), values); Double longitude = getDoubleValue(columnLookup.get(HEADER_LONG), values); @@ -256,7 +256,7 @@ final class DATExtractor extends DroneExtractor { return null; } - return new GeoTrackPoint(latitude, + return new TrackPoint(latitude, longitude, getDoubleValue(columnLookup.get(HEADER_ALTITUDE), values), null, diff --git a/InternalPythonModules/GPX_Module/GPX_Parser_Module.py b/InternalPythonModules/GPX_Module/GPX_Parser_Module.py index 6aeb84d5be..1c654503cb 100644 --- a/InternalPythonModules/GPX_Module/GPX_Parser_Module.py +++ b/InternalPythonModules/GPX_Module/GPX_Parser_Module.py @@ -37,12 +37,10 @@ from org.sleuthkit.datamodel import BlackboardArtifact from org.sleuthkit.datamodel import BlackboardAttribute from org.sleuthkit.datamodel import TskCoreException from org.sleuthkit.datamodel.blackboardutils import GeoArtifactsHelper -from org.sleuthkit.datamodel.blackboardutils.attributes import TskGeoWaypointsUtil -from org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoWaypointsUtil import GeoWaypointList -from org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoWaypointsUtil.GeoWaypointList import GeoWaypoint -from org.sleuthkit.datamodel.blackboardutils.attributes import TskGeoTrackpointsUtil -from org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoTrackpointsUtil import GeoTrackPointList -from org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoTrackpointsUtil.GeoTrackPointList import GeoTrackPoint +from org.sleuthkit.datamodel.blackboardutils.attributes import GeoWaypoints +from org.sleuthkit.datamodel.blackboardutils.attributes import GeoWaypoints.Waypoint +from org.sleuthkit.datamodel.blackboardutils.attributes import GeoTrackPoints +from org.sleuthkit.datamodel.blackboardutils.attributes import GeoTrackPoints.TrackPoint from org.sleuthkit.autopsy.datamodel import ContentUtils from org.sleuthkit.autopsy.ingest import IngestModule from org.sleuthkit.autopsy.ingest.IngestModule import IngestModuleException @@ -166,7 +164,7 @@ class GPXParserDataSourceIngestModule(DataSourceIngestModule): if self.writeDebugMsgs: self.log(Level.INFO, "Processing tracks from " + file.getUniquePath() + " (objID = " + str(file.getId()) + ")") for track in gpx.tracks: for segment in track.segments: - geoPointList = TskGeoTrackpointsUtil.GeoTrackPointList() + geoPointList = GeoTrackPoints() for point in segment.points: elevation = 0 @@ -180,7 +178,7 @@ class GPXParserDataSourceIngestModule(DataSourceIngestModule): except Exception as e: self.log(Level.WARNING, "Error getting track timestamp from " + file.getUniquePath() + " (objID = " + str(file.getId()) + "):" + str(e)) - geoPointList.addPoint(GeoTrackPoint(point.latitude, point.longitude, elevation, None, 0, 0, 0, timeStamp)) + geoPointList.addPoint(TrackPoint(point.latitude, point.longitude, elevation, None, 0, 0, 0, timeStamp)) try: geoArtifactHelper.addTrack("Track", geoPointList, None) @@ -213,10 +211,10 @@ class GPXParserDataSourceIngestModule(DataSourceIngestModule): if self.writeDebugMsgs: self.log(Level.INFO, "Processing routes from " + file.getUniquePath() + " (objID = " + str(file.getId()) + ")") for route in gpx.routes: - geoWaypointList = TskGeoWaypointsUtil.GeoWaypointList() + geoWaypoints = GeoWaypoints() for point in route.points: - geoWaypointList.addPoint(GeoWaypoint(point.latitude, point.longitude, point.elevation, point.name)) + geoWaypointList.addPoint(Waypoint(point.latitude, point.longitude, point.elevation, point.name)) try: geoArtifactHelper.addRoute(None, None, geoWaypointList, None) diff --git a/InternalPythonModules/android/googlemaplocation.py b/InternalPythonModules/android/googlemaplocation.py index 8e393dcee2..d2499cbf03 100644 --- a/InternalPythonModules/android/googlemaplocation.py +++ b/InternalPythonModules/android/googlemaplocation.py @@ -43,8 +43,8 @@ from org.sleuthkit.datamodel import Content from org.sleuthkit.datamodel import TskCoreException from org.sleuthkit.datamodel.Blackboard import BlackboardException from org.sleuthkit.datamodel.blackboardutils import GeoArtifactsHelper -from org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoWaypointsUtil import GeoWaypointList -from org.sleuthkit.datamodel.blackboardutils.attributes.TskGeoWaypointsUtil.GeoWaypointList import GeoWaypoint +from org.sleuthkit.datamodel.blackboardutils import GeoWaypoints +from org.sleuthkit.datamodel.blackboardutils.attributes.GeoWaypoints import Waypoint import traceback import general @@ -117,9 +117,9 @@ class GoogleMapLocationAnalyzer(general.AndroidComponentAnalyzer): source_lat = GoogleMapLocationAnalyzer.convertGeo(resultSet.getString("source_lat")) source_lng = GoogleMapLocationAnalyzer.convertGeo(resultSet.getString("source_lng")) - waypointlist = GeoWaypointList() - waypointlist.addPoint(GeoWaypoint(source_lat, source_lng, None, None)) - waypointlist.addPoint(GeoWaypoint(dest_lat, dest_lng, None, dest_address)) + waypointlist = GeoWaypoints() + waypointlist.addPoint(Waypoint(source_lat, source_lng, None, None)) + waypointlist.addPoint(Waypoint(dest_lat, dest_lng, None, dest_address)) artifactHelper.addRoute(dest_title, time, waypointlist, None) diff --git a/InternalPythonModules/android/oruxmaps.py b/InternalPythonModules/android/oruxmaps.py index 7a939e1972..23920af069 100644 --- a/InternalPythonModules/android/oruxmaps.py +++ b/InternalPythonModules/android/oruxmaps.py @@ -45,7 +45,8 @@ from org.sleuthkit.datamodel import Content from org.sleuthkit.datamodel import TskCoreException from org.sleuthkit.datamodel.Blackboard import BlackboardException from org.sleuthkit.datamodel.blackboardutils import GeoArtifactsHelper -from org.sleuthkit.datamodel.blackboardutils.attributes import TskGeoTrackpointsUtil +from org.sleuthkit.datamodel.blackboardutils.attributes import GeoTrackPoints +from org.sleuthkit.datamodel.blackboardutils.attributes import GeoTrackPoints.TrackPoint import traceback import general @@ -139,14 +140,14 @@ class OruxMapsAnalyzer(general.AndroidComponentAnalyzer): trackpointsQueryString = "SELECT trkptlat, trkptlon, trkptalt, trkpttime FROM trackpoints WHERE trkptseg = " + segmentId trackpointsResultSet = oruxMapsTrackpointsDb.runQuery(trackpointsQueryString) if trackpointsResultSet is not None: - geoPointList = TskGeoTrackpointsUtil.GeoTrackPointList() + geoPointList = GeoTrackPoints() while trackpointsResultSet.next(): latitude = trackpointsResultSet.getDouble("trkptlat") longitude = trackpointsResultSet.getDouble("trkptlon") altitude = trackpointsResultSet.getDouble("trkptalt") time = trackpointsResultSet.getLong("trkpttime") / 1000 # milliseconds since unix epoch - geoPointList.addPoint(TskGeoTrackpointsUtil.GeoTrackPointList.GeoTrackPoint(latitude, longitude, altitude, segmentName, 0, 0, 0, time)) + geoPointList.addPoint(TrackPoint(latitude, longitude, altitude, segmentName, 0, 0, 0, time)) try: geoartifact = geoArtifactHelper.addTrack(segmentName, geoPointList, None)