microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.23k stars 475 forks source link

CreateProcessEx #3030

Closed RoFred2 closed 3 months ago

RoFred2 commented 3 months ago

Suggestion

While attempting to port a reverse shell client made in C# to Rust, I came across an issue. The windows crate doesn't seem to have any function called CreateProcessEx, or similar, despite STARTUPINFOEXW existing.

The function is imported as such in C#:

    [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "CreateProcess")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool CreateProcessEx(string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFOEX lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
ChrisDenton commented 3 months ago

As the docs for CreateProcess says:

[in] lpStartupInfo

A pointer to a STARTUPINFO or STARTUPINFOEX structure.

In other words you can use either structure with CreateProcessW. You just might need to cast the pointer.

riverar commented 3 months ago

Also note the EntryPoint = "CreateProcess" on your import. Closing this for now as there's no work to be done but feel free to keep the discussion going.