@@ -116,38 +116,54 @@ def check_indicators(self) -> None:
116
116
)
117
117
118
118
def _extract_browsing_stats (self , log_path ):
119
- items = []
120
-
121
- with open (log_path , "rb" ) as handle :
122
- file_plist = plistlib .load (handle )
119
+ items = []
120
+
121
+ with open (log_path , "rb" ) as handle :
122
+ file_plist = plistlib .load (handle )
123
+
124
+ if "browsingStatistics" not in file_plist :
125
+ return items
126
+
127
+ browsing_stats = file_plist ["browsingStatistics" ]
128
+
129
+ for item in browsing_stats :
130
+ most_recent_interaction , last_seen = None , None
131
+ if "mostRecentUserInteraction" in item :
132
+ try :
133
+ most_recent_interaction = convert_datetime_to_iso (
134
+ item ["mostRecentUserInteraction" ]
135
+ )
136
+ except Exception :
137
+ self .log .error (
138
+ f'Error converting date of Safari resource"most recent interaction": { item ["mostRecentUserInteraction" ]} '
139
+ )
140
+ if "lastSeen" in item :
141
+ try :
142
+ last_seen = convert_datetime_to_iso (item ["lastSeen" ])
143
+ except Exception :
144
+ self .log .error (
145
+ f'Error converting date of Safari resource"last seen": { item ["lastSeen" ]} '
146
+ )
147
+
148
+ items .append (
149
+ {
150
+ "origin" : item .get ("PrevalentResourceOrigin" , "" ),
151
+ "redirect_source" : item .get ("topFrameUniqueRedirectsFrom" , "" ),
152
+ "redirect_destination" : item .get ("topFrameUniqueRedirectsTo" , "" ),
153
+ "subframe_under_origin" : item .get (
154
+ "subframeUnderTopFrameOrigins" , ""
155
+ ),
156
+ "subresource_under_origin" : item .get (
157
+ "subresourceUnderTopFrameOrigins" , ""
158
+ ),
159
+ "user_interaction" : item .get ("hadUserInteraction" ),
160
+ "most_recent_interaction" : most_recent_interaction ,
161
+ "last_seen" : last_seen ,
162
+ }
163
+ )
123
164
124
- if "browsingStatistics" not in file_plist :
125
165
return items
126
166
127
- browsing_stats = file_plist ["browsingStatistics" ]
128
-
129
- for item in browsing_stats :
130
- items .append (
131
- {
132
- "origin" : item .get ("PrevalentResourceOrigin" , "" ),
133
- "redirect_source" : item .get ("topFrameUniqueRedirectsFrom" , "" ),
134
- "redirect_destination" : item .get ("topFrameUniqueRedirectsTo" , "" ),
135
- "subframe_under_origin" : item .get (
136
- "subframeUnderTopFrameOrigins" , ""
137
- ),
138
- "subresource_under_origin" : item .get (
139
- "subresourceUnderTopFrameOrigins" , ""
140
- ),
141
- "user_interaction" : item .get ("hadUserInteraction" ),
142
- "most_recent_interaction" : convert_datetime_to_iso (
143
- item ["mostRecentUserInteraction" ]
144
- ),
145
- "last_seen" : convert_datetime_to_iso (item ["lastSeen" ]),
146
- }
147
- )
148
-
149
- return items
150
-
151
167
def run (self ) -> None :
152
168
if self .is_backup :
153
169
for log_file in self ._get_backup_files_from_manifest (
0 commit comments