Adds initial support for reading parameters passed to consent UI

This commit is contained in:
Ryan Newington
2023-11-11 16:09:12 +11:00
parent d5b3b24870
commit 28de11ee97
35 changed files with 952 additions and 19 deletions
@@ -0,0 +1,59 @@
using System;
using System.Runtime.InteropServices;
using Lithnet.CredentialProvider.Interop;
namespace Lithnet.CredentialProvider
{
/// <summary>
/// Represents the data structure passed to consent UI when a user is trying to elevate an executable
/// </summary>
public class ConsentUIDataExe : ConsentUIData
{
private IntPtr hFile;
/// <summary>
/// The path to the process that the user has requested to be launched as an administrator
/// </summary>
public string ExecutablePath { get; }
/// <summary>
/// A currently unknown value. In most cases it seems to be the same as <see cref="ExecutablePath"/>
/// </summary>
public string Unknown1 { get; }
/// <summary>
/// The full command line, including arguments that will be used to launch the executable
/// </summary>
public string CommandLine { get; }
/// <summary>
/// A currently unknown parameter
/// </summary>
public string Unknown2 { get; }
/// <summary>
/// Gets a handle to the executable that the user has requested to be launched as an administrator
/// </summary>
/// <returns>A handle to the executable</returns>
public SafeHandle GetExecutableHandle()
{
return DuplicateHandleInternal(this.hFile);
}
internal ConsentUIDataExe(IntPtr pData, int expectedSize) : base(pData, expectedSize)
{
if (this.header.Type != ConsentUIType.Exe)
{
throw new InvalidOperationException("The data structure is not of type EXE");
}
var s = Marshal.PtrToStructure<ConsentUIStructureExe>(pData);
this.hFile = s.hFile;
this.ExecutablePath = this.GetStringValueIfValid(pData, (int)s.oExecutablePath1);
this.Unknown1 = this.GetStringValueIfValid(pData, (int)s.oExecutablePath2);
this.CommandLine = this.GetStringValueIfValid(pData, (int)s.oCommandLine);
this.Unknown2 = this.GetStringValueIfValid(pData, (int)s.oUnknown0);
}
}
}