-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Android turbo.db SQLite parser plugin (#4880)
- Loading branch information
Showing
7 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
"""SQLite parser plugin for Android turbo database files.""" | ||
|
||
from dfdatetime import posix_time as dfdatetime_posix_time | ||
|
||
from plaso.containers import events | ||
from plaso.parsers import sqlite | ||
from plaso.parsers.sqlite_plugins import interface | ||
|
||
|
||
class AndroidTurboBatteryEvent(events.EventData): | ||
"""Android turbo battery event data. | ||
Attributes: | ||
battery_level (int): Remaining battery level, expressed as a percentage. | ||
battery_saver (int): Indicates if battery saver is turn on. | ||
charge_type (int): Indicates that the device is charging. | ||
recorded_time (dfdatetime.DateTimeValues): date and time the battery event | ||
was recorded. | ||
""" | ||
|
||
DATA_TYPE = 'android:event:battery' | ||
|
||
def __init__(self): | ||
"""Initializes event data.""" | ||
super(AndroidTurboBatteryEvent, self).__init__(data_type=self.DATA_TYPE) | ||
self.battery_level = None | ||
self.battery_saver = None | ||
self.charge_type = None | ||
self.recorded_time = None | ||
|
||
|
||
class AndroidTurboPlugin(interface.SQLitePlugin): | ||
"""SQLite parser plugin for Android's turbo.db database files.""" | ||
|
||
NAME = 'android_turbo' | ||
DATA_FORMAT = 'Android turbo SQLite database (turbo.db) file' | ||
|
||
REQUIRED_STRUCTURE = { | ||
'battery_event': frozenset([ | ||
'timestamp_millis', 'battery_level', 'charge_type', 'battery_saver'])} | ||
|
||
QUERIES = [ | ||
('SELECT timestamp_millis, battery_level, charge_type, battery_saver ' | ||
'FROM battery_event', | ||
'ParseBatteryEventRow')] | ||
|
||
SCHEMAS = [{ | ||
'android_metadata': 'CREATE TABLE android_metadata (locale TEXT)', | ||
'battery_event': ( | ||
'CREATE TABLE battery_event(timestamp_millis INTEGER PRIMARY KEY ' | ||
'DESC, battery_level INTEGER, charge_type INTEGER, battery_saver ' | ||
'INTEGER, timezone TEXT, place_key INTEGER, FOREIGN KEY(place_key) ' | ||
'REFERENCES charging_places(_id))'), | ||
'charging_places': ( | ||
'CREATE TABLE charging_places(_id INTEGER PRIMARY KEY, place_name ' | ||
'TEXT, place_api_id TEXT, UNIQUE(place_api_id) ON CONFLICT IGNORE)')}] | ||
|
||
def ParseBatteryEventRow(self, parser_mediator, query, row, **unused_kwargs): | ||
"""Parses a row from the battery_event table. | ||
Args: | ||
parser_mediator (ParserMediator): mediates interactions between parsers | ||
and other components, such as storage and dfVFS. | ||
query (str): query that created the row. | ||
row (sqlite3.Row): row. | ||
""" | ||
query_hash = hash(query) | ||
|
||
event_data = AndroidTurboBatteryEvent() | ||
event_data.battery_level = self._GetRowValue( | ||
query_hash, row, 'battery_level') | ||
event_data.battery_saver = self._GetRowValue( | ||
query_hash, row, 'battery_saver') | ||
event_data.charge_type = self._GetRowValue(query_hash, row, 'charge_type') | ||
|
||
timestamp = self._GetRowValue(query_hash, row, 'timestamp_millis') | ||
|
||
event_data.recorded_time = dfdatetime_posix_time.PosixTimeInMilliseconds( | ||
timestamp=timestamp) | ||
|
||
parser_mediator.ProduceEventData(event_data) | ||
|
||
|
||
sqlite.SQLiteParser.RegisterPlugin(AndroidTurboPlugin) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
"""Tests for the Android turbo plugin.""" | ||
|
||
import unittest | ||
|
||
from plaso.parsers.sqlite_plugins import android_turbo | ||
|
||
from tests.parsers.sqlite_plugins import test_lib | ||
|
||
|
||
class AndroidTurboSQLitePluginTest(test_lib.SQLitePluginTestCase): | ||
"""Tests for the Android turbo database plugin.""" | ||
|
||
def testProcess(self): | ||
"""Tests the Process function on an Android turbo.db file.""" | ||
plugin = android_turbo.AndroidTurboPlugin() | ||
storage_writer = self._ParseDatabaseFileWithPlugin( | ||
['android_turbo.db'], plugin) | ||
|
||
number_of_event_data = storage_writer.GetNumberOfAttributeContainers( | ||
'event_data') | ||
self.assertEqual(number_of_event_data, 2717) | ||
|
||
number_of_warnings = storage_writer.GetNumberOfAttributeContainers( | ||
'extraction_warning') | ||
self.assertEqual(number_of_warnings, 0) | ||
|
||
number_of_warnings = storage_writer.GetNumberOfAttributeContainers( | ||
'recovery_warning') | ||
self.assertEqual(number_of_warnings, 0) | ||
|
||
expected_event_values = { | ||
'battery_level': 99, | ||
'battery_saver': 2, | ||
'charge_type': 0, | ||
'recorded_time': '2023-05-27T13:06:46.000+00:00'} | ||
|
||
event_data = storage_writer.GetAttributeContainerByIndex('event_data', 0) | ||
self.CheckEventData(event_data, expected_event_values) | ||
|
||
expected_event_values = { | ||
'battery_level': 54, | ||
'battery_saver': 2, | ||
'charge_type': 1, | ||
'recorded_time': '2023-06-22T11:26:27.000+00:00'} | ||
|
||
event_data = storage_writer.GetAttributeContainerByIndex('event_data', 2138) | ||
self.CheckEventData(event_data, expected_event_values) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |