Пример #1
0
        public void Run()
        {
            const string kTestData = "Hello, World!";
            var          factory   = new PofStreamsFactoryImpl(threadingProxy, streamFactory, serializer);
            var          ms1       = streamFactory.CreateMemoryStream();
            var          ms2       = streamFactory.CreateMemoryStream();

            // Write test data into ms1
            var helperStream = factory.CreatePofStream(ms1);

            helperStream.Write(kTestData);
            ms1.Position = 0;

            // Read from ms1 stream with mainStream
            var mainStream = factory.CreatePofStream(ms1.Reader, ms2.Writer);

            AssertEquals(kTestData, mainStream.Read <string>());

            // Write to ms2 stream with mainStream
            mainStream.Write(kTestData);

            // Assert the data was written to ms2 as expected
            ms2.Position = 0;
            helperStream = factory.CreatePofStream(ms2);
            AssertEquals(kTestData, helperStream.Read <string>());
        }
Пример #2
0
 public PortableObjectBox ConvertToDataTransferObject <T>(T methodArguments)
 {
     using (var outerMs = streamFactory.CreateMemoryStream()) {
         pofSerializer.Serialize(outerMs.Writer, methodArguments);
         return(new PortableObjectBox(outerMs.GetBuffer(), 0, (int)outerMs.Length));
     }
 }
Пример #3
0
        private void HandleGetBootstrapArguments(LimitedDSPExSession session, TransactionInitialMessage message)
        {
            if (message.DataLength != 4)
            {
                logger.Warn($"Expected {GetType().Name} initial message to have at least 4 bytes");
            }
            else
            {
                // In the future, we should validate that the PID is the expected PID.
                var pid = BitConverter.ToUInt32(message.DataBuffer, message.DataOffset);
                logger.Info($"GetBootstrapArguments: sender pid is {pid}");
            }

            // Send response data - properties and flags
            using (var ms = streamFactory.CreateMemoryStream()) {
                var writer = ms.Writer;

                var configuration = bootstrapConfigurationGenerator.Build(startupConfiguration.Components);
                var properties    = configuration.Properties;
                writer.Write((uint)properties.Count);
                foreach (var property in properties)
                {
                    writer.WriteLongText(property.Key);
                    writer.WriteLongText(property.Value);
                }

                var flags = configuration.Flags;
                writer.Write((uint)flags.Count);
                foreach (var flag in flags)
                {
                    writer.WriteLongText(flag);
                }

                var data = ms.ToArray();
                session.SendMessage(new TransactionMessage(
                                        message.TransactionId,
                                        data,
                                        0,
                                        data.Length
                                        ));
            }
        }
        public void SpawnTrinket(IProcess targetProcess, TrinketSpawnConfiguration trinketSpawnConfiguration)
        {
            var components = new List <TrinketComponent>();

            if (trinketSpawnConfiguration.IsDebugEnabled)
            {
                components.Add(new DebugComponent());
            }
            if (trinketSpawnConfiguration.IsFileSystemHookingEnabled)
            {
                components.Add(new FilesystemComponent(trinketSpawnConfiguration.IsFileSystemOverridingEnabled));
            }
            if (trinketSpawnConfiguration.Name != null)
            {
                components.Add(new NameComponent(trinketSpawnConfiguration.Name));
            }
            if (trinketSpawnConfiguration.IsLoggingEnabled)
            {
                components.Add(new VerboseLoggerComponent());
            }
            if (trinketSpawnConfiguration.IsCommandingEnabled)
            {
                components.Add(new CommandListComponent(trinketSpawnConfiguration.CommandList));
            }
            if (trinketSpawnConfiguration.IsProcessSuspensionEnabled)
            {
                components.Add(new ProcessSuspensionComponent(trinketSpawnConfiguration.SuspendedProcessNames));
            }

            var targetProcessId      = targetProcess.Id;
            var startupConfiguration = new TrinketStartupConfigurationImpl(targetProcessId, components);

            using (var ms = streamFactory.CreateMemoryStream()) {
                pofSerializer.Serialize(ms.Writer, startupConfiguration);
                exeggutorService.SpawnHatchling(
                    kTrinketEggName,
                    new SpawnConfiguration {
                    Arguments    = ms.ToArray(),
                    InstanceName = kTrinketEggName + "_" + targetProcessId,
                    StartFlags   = HatchlingStartFlags.StartAsynchronously
                });
            }
        }