From 281699c800bacd1bf98660929347131d2db59922 Mon Sep 17 00:00:00 2001 From: Luca Bretting Date: Tue, 10 Dec 2024 23:52:39 +0100 Subject: [PATCH] fix: allow removing configs Signed-off-by: Luca Bretting --- .../bl/configuration/ConfigurationManager.kt | 2 +- .../configuration/ConfigurationViewModel.kt | 33 ++++++++++++++----- .../configuration/data/EBpfProgramOption.kt | 7 ++-- .../ziofa/ui/shared/ConfigurationHelpers.kt | 10 +++--- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/frontend/app/src/main/java/de/amosproj3/ziofa/bl/configuration/ConfigurationManager.kt b/frontend/app/src/main/java/de/amosproj3/ziofa/bl/configuration/ConfigurationManager.kt index e9365628..7960d43e 100644 --- a/frontend/app/src/main/java/de/amosproj3/ziofa/bl/configuration/ConfigurationManager.kt +++ b/frontend/app/src/main/java/de/amosproj3/ziofa/bl/configuration/ConfigurationManager.kt @@ -64,7 +64,7 @@ class ConfigurationManager(val clientFactory: ClientFactory) : ) { _localConfiguration.update { prev -> Timber.e("changeFeatureConfigurationForPIDs.prev $prev") - Timber.e("changeFeatureConfigurationForPIDs() $vfsWriteFeature, $sendMessageFeature") + Timber.e("changeFeatureConfigurationForPIDs() $vfsWriteFeature, $sendMessageFeature, $uprobesFeature, $jniReferencesFeature") // the configuration shall not be changed from the UI if there is none received from // backend if (prev != null && prev is ConfigurationUpdate.Valid) { diff --git a/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/ConfigurationViewModel.kt b/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/ConfigurationViewModel.kt index 0bb23b68..4612efe5 100644 --- a/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/ConfigurationViewModel.kt +++ b/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/ConfigurationViewModel.kt @@ -11,6 +11,7 @@ import de.amosproj3.ziofa.api.configuration.BackendConfigurationAccess import de.amosproj3.ziofa.api.configuration.ConfigurationUpdate import de.amosproj3.ziofa.api.configuration.LocalConfigurationAccess import de.amosproj3.ziofa.client.SysSendmsgConfig +import de.amosproj3.ziofa.client.UprobeConfig import de.amosproj3.ziofa.client.VfsWriteConfig import de.amosproj3.ziofa.ui.configuration.data.BackendFeatureOptions import de.amosproj3.ziofa.ui.configuration.data.ConfigurationScreenState @@ -38,11 +39,11 @@ class ConfigurationViewModel( val changed = combine( - localConfigurationAccess.localConfiguration, - backendConfigurationAccess.backendConfiguration, - ) { local, backend -> - local != backend - } + localConfigurationAccess.localConfiguration, + backendConfigurationAccess.backendConfiguration, + ) { local, backend -> + local != backend + } .stateIn(viewModelScope, SharingStarted.Lazily, false) fun optionChanged(option: BackendFeatureOptions, active: Boolean) { @@ -59,10 +60,24 @@ class ConfigurationViewModel( localConfigurationAccess.changeFeatureConfiguration( enable = active, sendMessageFeature = - SysSendmsgConfig( - pids.associateWith { DURATION_THRESHOLD } - // TODO this is not a duration - ), + SysSendmsgConfig( + pids.associateWith { DURATION_THRESHOLD } + // TODO this is not a duration + ), + ) + } + + is BackendFeatureOptions.UprobeOption -> { + localConfigurationAccess.changeFeatureConfiguration( + enable = active, + uprobesFeature = pids.map { + UprobeConfig( + fnName = option.method, + target = option.odexFilePath, + offset = option.offset, + pid = it.toInt() + ) + } ) } diff --git a/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/data/EBpfProgramOption.kt b/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/data/EBpfProgramOption.kt index 3b21e829..97bae77e 100644 --- a/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/data/EBpfProgramOption.kt +++ b/frontend/app/src/main/java/de/amosproj3/ziofa/ui/configuration/data/EBpfProgramOption.kt @@ -13,9 +13,10 @@ sealed class BackendFeatureOptions(val featureName: String, val active: Boolean) BackendFeatureOptions("Unix Domain Socket Analysis", enabled) data class UprobeOption( - val displayName: String, - val id: String, + val method: String, val enabled: Boolean, val pids: Set, - ) : BackendFeatureOptions(id, enabled) + val offset: ULong, + val odexFilePath: String + ) : BackendFeatureOptions(method, enabled) } diff --git a/frontend/app/src/main/java/de/amosproj3/ziofa/ui/shared/ConfigurationHelpers.kt b/frontend/app/src/main/java/de/amosproj3/ziofa/ui/shared/ConfigurationHelpers.kt index fa1d41b0..a709fd3a 100644 --- a/frontend/app/src/main/java/de/amosproj3/ziofa/ui/shared/ConfigurationHelpers.kt +++ b/frontend/app/src/main/java/de/amosproj3/ziofa/ui/shared/ConfigurationHelpers.kt @@ -83,12 +83,10 @@ fun ConfigurationUpdate.Valid.toUIOptionsForPids( options.add( BackendFeatureOptions.UprobeOption( enabled = true, // uprobe options are either active or not visible - displayName = - "UProbe for Symbol ${uprobeConfig.fnName} in ${uprobeConfig.target}", - id = uprobeConfig.fnName, - pids = - uprobeConfig.pid?.let { setOf(it.toUInt()) } - ?: setOf(), // TODO This should not be null asserted + method = uprobeConfig.fnName, + pids = uprobeConfig.pid?.let { setOf(it.toUInt()) } ?: setOf(), + odexFilePath = uprobeConfig.target, + offset = uprobeConfig.offset ) ) }