/// <nodoc /> public static SandboxedProcessInfo Deserialize(Stream stream, LoggingContext loggingContext, IDetoursEventListener detoursEventListener) { using (var reader = new BuildXLReader(false, stream, true)) { string arguments = reader.ReadNullableString(); string commandLine = reader.ReadNullableString(); bool disableConHostSharing = reader.ReadBoolean(); string fileName = reader.ReadNullableString(); Encoding standardInputEncoding = reader.ReadNullable(r => r.ReadEncoding()); Encoding standardOutputEncoding = reader.ReadNullable(r => r.ReadEncoding()); Encoding standardErrorEncoding = reader.ReadNullable(r => r.ReadEncoding()); string workingDirectory = reader.ReadNullableString(); IBuildParameters buildParameters = null; var envVars = reader.ReadNullable(r => r.ReadReadOnlyList(r2 => new KeyValuePair <string, string>(r2.ReadString(), r2.ReadString()))); if (envVars != null) { buildParameters = BuildParameters.GetFactory().PopulateFromDictionary(envVars.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); } string[] allowedSurvivingChildNames = reader.ReadNullable(r => r.ReadReadOnlyList(r2 => r2.ReadString()))?.ToArray(); int maxLengthInMemory = reader.ReadInt32(); TimeSpan? timeout = reader.ReadNullableStruct(r => r.ReadTimeSpan()); TimeSpan nestedProcessTerminationTimeout = reader.ReadTimeSpan(); long pipSemiStableHash = reader.ReadInt64(); string timeoutDumpDirectory = reader.ReadNullableString(); SandboxKind sandboxKind = (SandboxKind)reader.ReadByte(); string pipDescription = reader.ReadNullableString(); SandboxedProcessStandardFiles sandboxedProcessStandardFiles = SandboxedProcessStandardFiles.Deserialize(reader); StandardInputInfo standardInputSourceInfo = reader.ReadNullable(r => StandardInputInfo.Deserialize(r)); SandboxObserverDescriptor standardObserverDescriptor = reader.ReadNullable(r => SandboxObserverDescriptor.Deserialize(r)); FileAccessManifest fam = reader.ReadNullable(r => FileAccessManifest.Deserialize(stream)); return(new SandboxedProcessInfo( new PathTable(), new StandardFileStorage(sandboxedProcessStandardFiles), fileName, fam, disableConHostSharing, // TODO: serialize/deserialize container configuration. containerConfiguration: ContainerConfiguration.DisabledIsolation, loggingContext: loggingContext, detoursEventListener: detoursEventListener) { m_arguments = arguments, m_commandLine = commandLine, StandardInputEncoding = standardInputEncoding, StandardOutputEncoding = standardOutputEncoding, StandardErrorEncoding = standardErrorEncoding, WorkingDirectory = workingDirectory, EnvironmentVariables = buildParameters, AllowedSurvivingChildProcessNames = allowedSurvivingChildNames, MaxLengthInMemory = maxLengthInMemory, Timeout = timeout, NestedProcessTerminationTimeout = nestedProcessTerminationTimeout, PipSemiStableHash = pipSemiStableHash, TimeoutDumpDirectory = timeoutDumpDirectory, SandboxKind = sandboxKind, PipDescription = pipDescription, SandboxedProcessStandardFiles = sandboxedProcessStandardFiles, StandardInputSourceInfo = standardInputSourceInfo, StandardObserverDescriptor = standardObserverDescriptor }); } }
/// <summary> /// Tests file access manifest. /// </summary> public static void TestManifestRetrieval(IEnumerable <ValidationData> validationData, FileAccessManifest fam, bool serializeManifest) { foreach (var line in fam.Describe()) { Console.WriteLine(line); } if (serializeManifest) { var writtenFlag = fam.Flag; var writtenDirectoryTranslator = fam.DirectoryTranslator; using (var stream = new MemoryStream()) { fam.Serialize(stream); stream.Position = 0; fam = FileAccessManifest.Deserialize(stream); } XAssert.AreEqual(writtenFlag, fam.Flag); XAssert.AreEqual(writtenDirectoryTranslator == null, fam.DirectoryTranslator == null); if (writtenDirectoryTranslator != null) { XAssert.AreEqual(writtenDirectoryTranslator.Count, fam.DirectoryTranslator.Count); var writtenTranslations = writtenDirectoryTranslator.Translations.ToArray(); var readTranslations = fam.DirectoryTranslator.Translations.ToArray(); for (int i = 0; i < writtenTranslations.Length; ++i) { XAssert.AreEqual(writtenTranslations[i].SourcePath, readTranslations[i].SourcePath); XAssert.AreEqual(writtenTranslations[i].TargetPath, readTranslations[i].TargetPath); } } } byte[] manifestTreeBytes = fam.GetManifestTreeBytes(); foreach (ValidationData dataItem in validationData) { uint nodePolicy; uint conePolicy; uint pathId; Usn expectedUsn; bool success = global::BuildXL.Native.Processes.Windows.ProcessUtilitiesWin.FindFileAccessPolicyInTree( manifestTreeBytes, dataItem.Path, new UIntPtr((uint)dataItem.Path.Length), out conePolicy, out nodePolicy, out pathId, out expectedUsn); XAssert.IsTrue(success, "Unable to find path in manifest"); XAssert.AreEqual( unchecked ((uint)dataItem.PathId), pathId, "PathId for '{0}' did not match", dataItem.Path); if (dataItem.NodePolicy.HasValue) { XAssert.AreEqual( unchecked ((uint)dataItem.NodePolicy.Value), nodePolicy, "Policy for '{0}' did not match", dataItem.Path); } if (dataItem.ConePolicy.HasValue) { XAssert.AreEqual( unchecked ((uint)dataItem.ConePolicy.Value), conePolicy, "Policy for '{0}' did not match", dataItem.Path); } XAssert.AreEqual( dataItem.ExpectedUsn, expectedUsn, "Usn for '{0}' did not match", dataItem.Path); } }