-
Notifications
You must be signed in to change notification settings - Fork 91
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
base: main
Are you sure you want to change the base?
Add Service.set_launch_protected, get_launch_protected
#138
Conversation
kkent030315
left a comment
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.
Thank you for this great patch. I am also waiting this PR to be merged!
| /// for more information. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| #[repr(u32)] | ||
| pub enum ServiceLaunchProtected { |
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.
| pub enum ServiceLaunchProtected { | |
| 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, | |
| } |
src/service.rs
Outdated
| *self as u32 | ||
| } | ||
|
|
||
| pub fn from_raw(raw: u32) -> crate::Result<ServiceLaunchProtected> { |
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.
I think you can turn this whole function into TryFrom trait impl.
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),
)),
}
}
}
src/service.rs
Outdated
| /// 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 = vec![0u8; std::mem::size_of::<Services::SERVICE_LAUNCH_PROTECTED_INFO>()]; |
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.
No allocation is actually required here since the size is known at compile-time. You can remove vec! so that it forces data to be on a stack.
| let mut data = vec![0u8; std::mem::size_of::<Services::SERVICE_LAUNCH_PROTECTED_INFO>()]; | |
| let mut data = [0u8; std::mem::size_of::<Services::SERVICE_LAUNCH_PROTECTED_INFO>()]; |
| ) | ||
| .map_err(Error::Winapi) | ||
| } | ||
| } |
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.
Put an newline between function definitions :)
Adds launch-protection support to the crate.
A new ServiceLaunchProtected enum (wrapping the four SERVICE_LAUNCH_PROTECTED_* constants) is introduced together with the public helpers Service::set_launch_protected and Service::get_launch_protected, which use SERVICE_CONFIG_LAUNCH_PROTECTED internally. The change is purely additive and does not modify existing APIs.
This change is