Skip to content

Commit 3a2c2c0

Browse files
CopilotCBenoit
andcommitted
Make ai_enable_desktop_rpc_interface and ai_disable_desktop_rpc_interface non-unsafe
These functions don't impose safety requirements on callers - all unsafe operations are properly contained in inner unsafe blocks with clear safety comments. Updated safety comments to be more descriptive about operations. Co-authored-by: CBenoit <3809077+CBenoit@users.noreply.github.com>
1 parent 73a69fe commit 3a2c2c0

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

crates/devolutions-agent-shared/src/windows/reversed_hex_uuid.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ mod tests {
7777
#[test]
7878
fn convert_reversed_hex_to_uuid() {
7979
assert_eq!(
80-
reversed_hex_to_uuid("C3D81328F118D5D4A9287B3CB1707655")
81-
.expect("failed to convert reversed hex to UUID"),
80+
reversed_hex_to_uuid("C3D81328F118D5D4A9287B3CB1707655").expect("failed to convert reversed hex to UUID"),
8281
uuid::uuid!("{82318D3C-811F-4D5D-9A82-B7C31B076755}")
8382
);
8483
}

crates/devolutions-pedm-hook/src/appinfo.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ extern "system" fn rpc_server_register_if_ex(
107107
}
108108

109109
type FnAiEnableDesktopRpcInterface = unsafe extern "system" fn() -> RPC_STATUS;
110-
pub unsafe fn ai_enable_desktop_rpc_interface() -> RPC_STATUS {
110+
pub fn ai_enable_desktop_rpc_interface() -> RPC_STATUS {
111111
static FUN: OnceLock<FnAiEnableDesktopRpcInterface> = OnceLock::new();
112112

113113
let init = || {
@@ -116,16 +116,16 @@ pub unsafe fn ai_enable_desktop_rpc_interface() -> RPC_STATUS {
116116
.resolve_symbol("AiEnableDesktopRpcInterface")
117117
.expect("failed to find AiEnableDesktopRpcInterface");
118118

119-
// SAFETY: We assume appinfo.dll's AiEnableDesktopRpcInterface has decompiled signature.
119+
// SAFETY: We assume appinfo.dll's AiEnableDesktopRpcInterface has the correct decompiled signature.
120120
unsafe { mem::transmute::<_, FnAiEnableDesktopRpcInterface>(orig) }
121121
};
122122

123-
// SAFETY: Calling the function pointer obtained from appinfo.dll.
123+
// SAFETY: Calling the dynamically loaded AiEnableDesktopRpcInterface function from appinfo.dll.
124124
unsafe { FUN.get_or_init(init)() }
125125
}
126126

127127
type FnAiDisableDesktopRpcInterface = unsafe extern "system" fn();
128-
pub unsafe fn ai_disable_desktop_rpc_interface() {
128+
pub fn ai_disable_desktop_rpc_interface() {
129129
static FUN: OnceLock<FnAiDisableDesktopRpcInterface> = OnceLock::new();
130130

131131
let init = || {
@@ -134,11 +134,11 @@ pub unsafe fn ai_disable_desktop_rpc_interface() {
134134
.resolve_symbol("AiDisableDesktopRpcInterface")
135135
.expect("failed to find AiDisableDesktopRpcInterface");
136136

137-
// SAFETY: We assume appinfo.dll's AiDisableDesktopRpcInterface has decompiled signature.
137+
// SAFETY: We assume appinfo.dll's AiDisableDesktopRpcInterface has the correct decompiled signature.
138138
unsafe { mem::transmute::<_, FnAiDisableDesktopRpcInterface>(orig) }
139139
};
140140

141-
// SAFETY: Calling the function pointer obtained from appinfo.dll.
141+
// SAFETY: Calling the dynamically loaded AiDisableDesktopRpcInterface function from appinfo.dll.
142142
unsafe { FUN.get_or_init(init)() }
143143
}
144144

@@ -150,16 +150,16 @@ pub fn dump_interfaces() -> Result<Box<[RpcServerInterfacePointer]>> {
150150
}
151151

152152
// SAFETY: Calling Windows API function to disable RPC interface.
153-
unsafe { ai_disable_desktop_rpc_interface() };
153+
ai_disable_desktop_rpc_interface();
154154
// SAFETY: Enabling the hook to intercept RPC calls.
155155
if let Err(err) = unsafe { rpc_server_register_if_ex_hook().enable() } {
156156
// SAFETY: Calling Windows API function to enable RPC interface.
157-
let _ = unsafe { ai_enable_desktop_rpc_interface() };
157+
let _ = ai_enable_desktop_rpc_interface();
158158
bail!(err);
159159
}
160160

161161
// SAFETY: Calling Windows API function to enable RPC interface.
162-
let _ = unsafe { ai_enable_desktop_rpc_interface() };
162+
let _ = ai_enable_desktop_rpc_interface();
163163
// SAFETY: Disabling the hook after capturing interface information.
164164
if let Err(err) = unsafe { rpc_server_register_if_ex_hook().disable() } {
165165
bail!(err);

0 commit comments

Comments
 (0)