public async Task <Dictionary <string, string> > ReadEnvironmentAsync(Stream continuation, CancellationToken token = default(CancellationToken)) { var env = new Dictionary <string, string>(); using var memoryStream = new MemoryStream(); await continuation.CopyToAsync(memoryStream, (16 << 10) /* 16KiB */, token); memoryStream.Seek(0, SeekOrigin.Begin); byte[] envBlock = memoryStream.ToArray(); if (envBlock.Length != (long)ExpectedSizeInBytes) { throw new ApplicationException($"ProcessEnvironment continuation length did not match expected length. Expected: {ExpectedSizeInBytes} bytes, Received: {envBlock.Length} bytes"); } int cursor = 0; UInt32 nElements = BitConverter.ToUInt32(envBlock, cursor); cursor += sizeof(UInt32); while (cursor < envBlock.Length) { string pair = IpcHelpers.ReadString(envBlock, ref cursor); int equalsIdx = pair.IndexOf('='); env[pair.Substring(0, equalsIdx)] = equalsIdx != pair.Length - 1 ? pair.Substring(equalsIdx + 1) : ""; } return(env); }
/// <summary> /// Parses a ProcessInfo2 payload. /// </summary> internal static ProcessInfo ParseV2(byte[] payload) { int index = 0; ProcessInfo processInfo = ParseCommon(payload, ref index); processInfo.ManagedEntrypointAssemblyName = IpcHelpers.ReadString(payload, ref index); processInfo.ClrProductVersionString = IpcHelpers.ReadString(payload, ref index); return(processInfo); }
private static ProcessInfo ParseCommon(byte[] payload, ref int index) { ProcessInfo processInfo = new ProcessInfo(); processInfo.ProcessId = BitConverter.ToUInt64(payload, index); index += sizeof(UInt64); byte[] cookieBuffer = new byte[GuidSizeInBytes]; Array.Copy(payload, index, cookieBuffer, 0, GuidSizeInBytes); processInfo.RuntimeInstanceCookie = new Guid(cookieBuffer); index += GuidSizeInBytes; processInfo.CommandLine = IpcHelpers.ReadString(payload, ref index); processInfo.OperatingSystem = IpcHelpers.ReadString(payload, ref index); processInfo.ProcessArchitecture = IpcHelpers.ReadString(payload, ref index); return(processInfo); }
private Dictionary <string, string> ReadEnvironmentCore(MemoryStream stream) { stream.Seek(0, SeekOrigin.Begin); byte[] envBlock = stream.ToArray(); if (envBlock.Length != (long)ExpectedSizeInBytes) { throw new ApplicationException($"ProcessEnvironment continuation length did not match expected length. Expected: {ExpectedSizeInBytes} bytes, Received: {envBlock.Length} bytes"); } var env = new Dictionary <string, string>(); int cursor = 0; UInt32 nElements = BitConverter.ToUInt32(envBlock, cursor); cursor += sizeof(UInt32); while (cursor < envBlock.Length) { string pair = IpcHelpers.ReadString(envBlock, ref cursor); int equalsIdx = pair.IndexOf('='); env[pair.Substring(0, equalsIdx)] = equalsIdx != pair.Length - 1 ? pair.Substring(equalsIdx + 1) : ""; } return(env); }