-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented SQLite parser plugin for android's turbo.db database #4880
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that both battery_saver and charge_type are enumerations, let's add their values here