Skip to content
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

Fix small bugs in Android OS Plugin #415

Merged
merged 5 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions dissect/target/plugins/os/unix/linux/android/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AndroidPlugin(OSPlugin):
def __init__(self, target: Target):
super().__init__(target)
self.target = target
self.props = BuildProp(self.target.path("/build.prop").open("rt"))
self.props = BuildProp(self.target.fs.path("/build.prop").open("rt"))

@classmethod
def detect(cls, target: Target) -> Optional[Filesystem]:
Expand All @@ -50,9 +50,17 @@ def ips(self) -> list[str]:

@export(property=True)
def version(self) -> str:
release_version = self.props.props["ro.build.version.release"]
security_patch_version = self.props.props["ro.build.version.security_patch"]
return f"Android {release_version} ({security_patch_version})"
full_version = "Android"

release_version = self.props.props.get("ro.build.version.release")
if release_version:
full_version += f" {release_version}"

security_patch_version = self.props.props.get("ro.build.version.security_patch")
if security_patch_version:
full_version += f" ({security_patch_version})"

return full_version

@export(property=True)
def os(self) -> str:
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ def target_citrix(fs_bsd):
yield mock_target


@pytest.fixture
def target_android() -> Target:
mock_target = next(make_mock_target())

mock_filesystem = VirtualFilesystem()
mock_filesystem.map_file("/build.prop", absolute_path("data/plugins/os/unix/linux/android/build.prop"))

mock_target.filesystems.add(mock_filesystem)

mock_target.apply()
yield mock_target


@pytest.fixture
def target_win_users(hive_hklm, hive_hku, target_win):
profile_list_key_name = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList"
Expand Down
5 changes: 5 additions & 0 deletions tests/data/plugins/os/unix/linux/android/build.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# begin build properties
# autogenerated by buildinfo.sh
ro.build.host=TMG28071935
ro.build.version.release=4.4.2
ro.build.version.security_patch=2013-10-31
9 changes: 9 additions & 0 deletions tests/test_plugins_os_unix_linux_android.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dissect.target.plugins.os.unix.linux.android._os import AndroidPlugin


def test_unix_linux_android_os(target_android):
target_android.add_plugin(AndroidPlugin)

assert target_android.os == "android"
assert target_android.version == "Android 4.4.2 (2013-10-31)"
assert target_android.hostname == "TMG28071935"