-
Notifications
You must be signed in to change notification settings - Fork 92
Add Service.set_launch_protected, get_launch_protected
#138
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
Open
winocreative
wants to merge
2
commits into
mullvad:main
Choose a base branch
from
winocreative:feature/launch_as_protected
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−0
Open
Changes from all commits
Commits
Show all changes
2 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 hidden or 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 |
|---|---|---|
|
|
@@ -359,6 +359,45 @@ impl ServiceFailureActions { | |
| } | ||
| } | ||
|
|
||
| /// Enum describing the service launch protection options. | ||
| /// | ||
| /// See <https://learn.microsoft.com/ko-kr/windows/win32/api/winsvc/ns-winsvc-service_launch_protected_info> | ||
| /// for more information. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| #[repr(u32)] | ||
| pub enum ServiceLaunchProtected { | ||
| /// No launch protection. The service can be modified or replaced without restriction. | ||
| None = Services::SERVICE_LAUNCH_PROTECTED_NONE, | ||
|
|
||
| /// Launch protection for Windows components. | ||
| Windows = Services::SERVICE_LAUNCH_PROTECTED_WINDOWS, | ||
|
|
||
| /// A lighter version of Windows launch protection. | ||
| WindowsLight = Services::SERVICE_LAUNCH_PROTECTED_WINDOWS_LIGHT, | ||
|
|
||
| /// Launch protection used by antimalware (ELAM) services. | ||
| AntimalwareLight = Services::SERVICE_LAUNCH_PROTECTED_ANTIMALWARE_LIGHT, | ||
| } | ||
| impl TryFrom<u32> for ServiceLaunchProtected { | ||
| type Error = Error; | ||
|
|
||
| fn try_from(value: u32) -> Result<Self, Self::Error> { | ||
| match value { | ||
| Services::SERVICE_LAUNCH_PROTECTED_NONE => Ok(ServiceLaunchProtected::None), | ||
| Services::SERVICE_LAUNCH_PROTECTED_WINDOWS => Ok(ServiceLaunchProtected::Windows), | ||
| Services::SERVICE_LAUNCH_PROTECTED_WINDOWS_LIGHT => { | ||
| Ok(ServiceLaunchProtected::WindowsLight) | ||
| } | ||
| Services::SERVICE_LAUNCH_PROTECTED_ANTIMALWARE_LIGHT => { | ||
| Ok(ServiceLaunchProtected::AntimalwareLight) | ||
| } | ||
| _ => Err(Error::ParseValue( | ||
| "Invalid launch protection value", | ||
| ParseRawError::InvalidInteger(value), | ||
| )), | ||
| } | ||
| } | ||
| } | ||
| /// A struct that describes the service. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
| pub struct ServiceInfo { | ||
|
|
@@ -1802,6 +1841,36 @@ impl Service { | |
| } | ||
| } | ||
|
|
||
| /// Set service launch protection. | ||
| /// This is a security feature that allows the service to run in a more secure environment. | ||
| /// there is no example because you need EV Certification and ELAM Driver to test it. | ||
| /// Please refer to the official documentation for more information: | ||
| /// <https://learn.microsoft.com/en-us/windows/win32/services/protecting-anti-malware-services-> | ||
| pub fn set_launch_protected(&self, protection: ServiceLaunchProtected) -> crate::Result<()> { | ||
| let mut launch_protected = | ||
| unsafe { mem::zeroed::<Services::SERVICE_LAUNCH_PROTECTED_INFO>() }; | ||
| launch_protected.dwLaunchProtected = protection as u32; | ||
| unsafe { | ||
| self.change_config2( | ||
| Services::SERVICE_CONFIG_LAUNCH_PROTECTED, | ||
| &mut launch_protected, | ||
| ) | ||
| .map_err(Error::Winapi) | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put an newline between function definitions :) |
||
|
|
||
| /// Get service launch protection. | ||
| /// This is a security feature that allows the service to run in a more secure environment. | ||
| pub fn get_launch_protected(&self) -> crate::Result<ServiceLaunchProtected> { | ||
| let mut data = [0u8; std::mem::size_of::<Services::SERVICE_LAUNCH_PROTECTED_INFO>()]; | ||
| unsafe { | ||
| let raw_data: Services::SERVICE_LAUNCH_PROTECTED_INFO = self | ||
| .query_config2(Services::SERVICE_CONFIG_LAUNCH_PROTECTED, &mut data) | ||
| .map_err(Error::Winapi)?; | ||
| raw_data.dwLaunchProtected.try_into() | ||
| } | ||
| } | ||
|
|
||
| /// Set service description. | ||
| /// | ||
| /// Required permission: [`ServiceAccess::CHANGE_CONFIG`]. | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
It seems like they are inserting newline after each field so it's better to follow in this enum. Also, you could add doc comments for each field.