Skip to content

Commit 141db62

Browse files
author
casework
committed
Add timestamp conversion.
1 parent 72a09b8 commit 141db62

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

case.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""An API to the CASE ontology."""
22

33
import rdflib
4-
from rdflib import RDF
4+
from rdflib import RDF, XSD
5+
import rdflib.term
56

67
CASE = rdflib.Namespace('http://case.example.org/core#')
78

case_plaso/event_exporters/android_calls.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from case_plaso import event_exporter
2+
from case_plaso import event_exporter, lib
33

44

55
@event_exporter.register
@@ -15,7 +15,6 @@ class AndroidCallExporter(event_exporter.EventExporter):
1515
def __init__(self, document):
1616
super(AndroidCallExporter, self).__init__(document)
1717
self._contacts = {}
18-
self._phone_calls = {}
1918

2019
def export_event_data(self, event):
2120
phone_call_pb = self.document.create_trace().create_property_bundle(
@@ -43,6 +42,6 @@ def export_event_data(self, event):
4342

4443
def export_timestamp(self, event, pb):
4544
try:
46-
pb.add(self.TIMESTAMP_MAP[event.timestamp_desc], event.timestamp)
45+
pb.add(self.TIMESTAMP_MAP[event.timestamp_desc], lib.convert_timestamp(event.timestamp))
4746
except KeyError:
4847
pass

case_plaso/event_exporters/ntfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
from plaso.lib.eventdata import EventTimestamp
33

4-
from case_plaso import event_exporter
4+
from case_plaso import event_exporter, lib
55

66

77
@event_exporter.register
@@ -28,7 +28,7 @@ def export_event_data(self, event):
2828

2929
def export_timestamp(self, event, pb):
3030
try:
31-
pb.add(self.TIMESTAMP_MAP[event.timestamp_desc], event.timestamp)
31+
pb.add(self.TIMESTAMP_MAP[event.timestamp_desc], lib.convert_timestamp(event.timestamp))
3232
except KeyError:
3333
# TODO: Log this or something.
3434
pass

case_plaso/lib.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11

2+
import rdflib
3+
from plaso.lib import timelib
4+
import pytz
5+
6+
7+
def convert_timestamp(timestamp):
8+
"""Converts a plaso timestamp into a valid rdflib Literal."""
9+
# TODO: Extract timezone from knowledge base in plaso storage file. Assuming UTC for now.
10+
# TODO: Create binding for XSD.dateTimeStamp. It's unavailable in rdflib.
11+
# - Binding should allow direct conversion from Iso format.
12+
timestamp = timelib.Timestamp.CopyToDatetime(timestamp, timezone=pytz.UTC)
13+
return rdflib.Literal(timestamp, datatype=rdflib.XSD.dateTime)
14+
215

316
def hash_dict(dictionary):
417
# NOTE: If we have a recursive dictionary, we have bigger problems.

plaso_case_output.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
document = case.Document()
2828
exporter = plaso_exporter.PlasoExporter(document)
29+
print 'Exporting storage file...'
2930
exporter.export_storage_file(options.storage_file)
30-
31+
print 'Serializing graph...'
3132
document.serialize(format='json-ld', destination='test.json')

0 commit comments

Comments
 (0)