Exemplo n.º 1
0
        private void ReflectPESubsytemType(string archivePath, string uri, CompileProcess compileProcess)
        {
            try
            {
                string iconOutputPath = null;

                if (Helper.IsNullOrEmpty(compileProcess.IconFile))
                {
                    iconOutputPath = Application.UserAppDataPath + @"\" + Guid.NewGuid().GetHashCode().ToString() + ".ico";

                    compileProcess.IconFile           = iconOutputPath;
                    compileProcess.DeleteIconWhenDone = true;
                }

                PEFileInfo info;

                if (!PEFileInterrogator.TryGetPEFileInfo(archivePath, uri, iconOutputPath, out info))
                {
                    throw new Exception(string.Format(Rpx.Strings.Reflector_CouldNotReadPE, uri));
                }

                if (iconOutputPath != null && !File.Exists(iconOutputPath))
                {
                    compileProcess.IconFile           = null;
                    compileProcess.DeleteIconWhenDone = false;
                }

                if (compileProcess.ExecutableTypeLookupMode == ExecutableTypeMode.Reflected)
                {
                    if (info.Subsystem == SubsystemTypes.WindowsCni)
                    {
                        compileProcess.ExecutableType = ExecutableType.Console;
                    }
                    else if (info.Subsystem == SubsystemTypes.WindowsGui)
                    {
                        compileProcess.ExecutableType = ExecutableType.Forms;
                    }
                    else
                    {
                        SubsystemTypes SubsystemType = info.Subsystem;

                        throw new Exception(string.Format(Rpx.Strings.Error_0107, SubsystemType.ToString()));
                    }
                }
            }
            finally
            {
            }
        }
Exemplo n.º 2
0
        private AssemblyInfo ReflectAssemblyInfo(string archivePath, string uri, CompileProcess compileProcess)
        {
            AssemblyInfo info = new AssemblyInfo();

            AppDomain domain = null;

            try
            {
                string appDomainName = "Interrogator";

                AppDomainSetup domainSetup = new AppDomainSetup();
                domainSetup.ApplicationName = appDomainName;
                domainSetup.ApplicationBase = new FileInfo(Application.ExecutablePath).DirectoryName;

                domain = AppDomain.CreateDomain(appDomainName, null, domainSetup);

                AssemblyInterrogator remoteWorker = (AssemblyInterrogator)domain.CreateInstanceAndUnwrap(typeof(AssemblyInterrogator).Assembly.FullName, typeof(AssemblyInterrogator).FullName);

                string errorMessage, exceptionMessage;

                if (!remoteWorker.GetAssemblyInfo(archivePath, uri, out info, out errorMessage, out exceptionMessage))
                {
                    if (RC.ShouldWrite(ConsoleVerbosity.Debug) && String.IsNullOrEmpty(exceptionMessage) == false)
                    {
                        throw new Exception(errorMessage + Environment.NewLine + exceptionMessage);
                    }
                    else
                    {
                        throw new Exception(errorMessage);
                    }
                    //throw new Exception(string.Format("{0} : {1}", Rpx.Strings.Compiler_UnableToLoadAsm, uri));
                }

                info = AssemblyInfo.Clone(info);

                compileProcess.PassArguments = info.PassArgs;
            }
            finally
            {
                if (domain != null)
                {
                    AppDomain.Unload(domain);
                }
            }

            return(info);
        }
Exemplo n.º 3
0
        public static void Run()
        {
            ConsoleColorState state = RC.ColorState;            

            try
            {
                if (!Parser.HelpMode)
                {
                    #region Setup

                    if (VerboseSwitch.Defined)
                    {
                        RC.Verbosity = (ConsoleVerbosity)VerboseSwitch.Value;
                    }
                    else if (QuietSwitch.Defined)
                    {
                        RC.Verbosity = ConsoleVerbosity.Quiet;
                    }

                    if (WarningsAsErrors.Defined)
                    {
                        RC.WarningsAsErrors = WarningsAsErrors.Value;
                        RC.ReportWarnings = WarningsAsErrors.Value;
                    }                    

                    RC.IsBuildMode = BuildSwitch.Defined;

                    RC.WriteLine(ConsoleVerbosity.Normal, "");
                    RC.WriteLine(ConsoleVerbosity.Minimal, ConsoleThemeColor.TitleText, Title);
                    //RC.WriteLine(ConsoleVerbosity.Minimal, "");

                    RC.ForegroundThemeColor = ConsoleThemeColor.Text;

                    #endregion

                    #region Check First Argument

                    if (Helper.IsNullOrEmpty(PathString.Value))
                    {
                        RC.WriteError(0101, Strings.Error_0101);
                        return;
                    }

                    #endregion

                    #region Create Process

                    CompileProcess compressionProcess = new CompileProcess();

                    compressionProcess.LogToConsole = true;

                    // ExecutableTypeMode
                    if (ConsoleSwitch.Defined)
                    {
                        compressionProcess.ExecutableTypeLookupMode = ExecutableTypeMode.Explicit;
                        compressionProcess.ExecutableType = ConsoleSwitch.Value ? ExecutableType.Console : ExecutableType.Forms;
                    }
                    else
                    {
                        compressionProcess.ExecutableTypeLookupMode = ExecutableTypeMode.Reflected;
                        compressionProcess.ExecutableType = ExecutableType.Console;
                    }

                    #endregion

                    #region Parse Optional Arguments

                    #region ToolsCsv Argument Switch Arround

                    if (ToolsCsv.Defined)
                    {
                        if (!OutputPath.Defined)
                        {
                            // If the output path argument has not been defined then manually set its value
                            // to the value of the first argument. e.g. 'rug-tool.exe' 
                            OutputPath.Defined = true;
                            OutputPath.SetValue(PathString.Value);
                        }
                        else
                        {
                            // if the output path argument has been defined then the fist argument must be an
                            // additional .dll file so move the value to additional file list argument                            
                            FileList.Value.Add(PathString.Value);
                        }

                        // Zero the value of the fist argument
                        PathString.Reset();

                        if (compressionProcess.ExecutableTypeLookupMode != ExecutableTypeMode.Explicit)
                        {
                            compressionProcess.ExecutableTypeLookupMode = ExecutableTypeMode.Default;
                        }
                    }

                    #endregion

                    #region Additional Assembly Paths

                    List<string> assemblyPaths = new List<string>(FileList.Value.Count + 1);

                    if (PathString.Defined)
                    {
                        assemblyPaths.Add(PathString.Value);
                    }

                    foreach (object obj in FileList.Value)
                    {
                        assemblyPaths.Add(obj.ToString());
                    }

                    compressionProcess.Assemblys.AddRange(assemblyPaths);
                    compressionProcess.Compression.Files.AddRange(assemblyPaths);

                    #endregion

                    #region Output Path

                    string output;

                    if (OutputPath.Defined)
                    {
                        output = OutputPath.Value;
                    }
                    else if (PathString.Defined)
                    {
                        output = PathString.Value;
                    }
                    else
                    {
                        RC.WriteError(0104, Strings.Error_0104);
                        return;
                    }

                    #endregion

                    #region Initial Assembly Path

                    string initial;

                    if (PathString.Defined)
                    {
                        initial = PathString.Value;
                        initial = "/" + initial.Substring(initial.LastIndexOf('\\') + 1);
                    }
                    else
                    {
                        initial = null;
                    }

                    compressionProcess.InitialAssemblyPath = initial;

                    #endregion

                    #region Icon Path

                    string icon = "";

                    if (IconPath.Defined)
                    {
                        icon = IconPath.Value;
                    }

                    compressionProcess.IconFile = icon;

                    #endregion

                    #region AssemblyInfoPath

                    string assemblyinfoFile = null;

                    if (AssemblyInfoPath.Defined)
                    {
                        if (!File.Exists(AssemblyInfoPath.Value))
                        {
                            RC.WriteError(0102, string.Format(Strings.Error_0102, AssemblyInfoPath.Value));
                            return;
                        }

                        assemblyinfoFile = AssemblyInfoPath.Value;
                    }
                    else if (!PathString.Defined)
                    {
                        RC.WriteError(0106, Strings.Error_0106);
                        return;
                    }

                    compressionProcess.AssembyInfoSourceFilePath = assemblyinfoFile;

                    #endregion

                    #region Pass Arguments

                    bool passArgs = compressionProcess.ExecutableType == ExecutableType.Console ? true : false;

                    if (PassArgsSwitch.Defined)
                    {
                        passArgs = PassArgsSwitch.Value;
                    }

                    compressionProcess.PassArguments = passArgs;

                    #endregion

                    #region Decorate

                    compressionProcess.Decorate = DecorateSwitch.Defined;

                    #endregion

                    #region Protect Zip

                    compressionProcess.Compression.Protected = ProtectZipSwitch.Defined;
                    compressionProcess.Compression.Password = ProtectZipSwitch.Value;

                    #endregion

                    #region Build Tools

                    foreach (string toolString in ToolsCsv.Value)
                    {
                        int index = toolString.IndexOf(':');

                        if (index < 1)
                        {
                            RC.WriteError(0105, string.Format(Strings.Error_0105, toolString));
                            return;
                        }

                        string toolName = toolString.Substring(0, index);
                        string toolPath = toolString.Substring(index + 1);

                        compressionProcess.Tools.Add(toolName, toolPath);
                        compressionProcess.Compression.Files.Add(toolPath);
                    }

                    #endregion

                    #endregion

                    #region Execute Bundle and Compile

                    RC.ForegroundThemeColor = ConsoleThemeColor.Text;

                    compressionProcess.Compression.CreatePackage();

                    #endregion

                    if (compressionProcess.RunProcess(output))
                    {
                        #region Print Size Summary

                        RC.WriteLine(ConsoleVerbosity.Verbose, ConsoleThemeColor.TitleText, "\n\n" + Strings.Text_FinalSummary);
                        RC.WriteLine(ConsoleThemeColor.SubText, " " + new string(ConsoleChars.SingleLines[1], 41));

                        Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_UncompressedSize, CmdHelper.GetMemStringFromBytes(compressionProcess.InitialSize, true), RC.Theme[ConsoleThemeColor.Text]);

                        if (compressionProcess.IconFileSize > 0)
                        {
                            Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_IconFileSize, CmdHelper.GetMemStringFromBytes(compressionProcess.IconFileSize, true), RC.Theme[ConsoleThemeColor.Text]);
                            Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_TotalSize, CmdHelper.GetMemStringFromBytes(compressionProcess.InitialSize + compressionProcess.IconFileSize, true), RC.Theme[ConsoleThemeColor.Text]);
                        }

                        Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_StartupOverhead, CmdHelper.GetMemStringFromBytes(compressionProcess.OverheadSize, true), RC.Theme[ConsoleThemeColor.Text]);

                        ConsoleThemeColor compColor = ConsoleThemeColor.Text;

                        if (compressionProcess.FinalFileSize < compressionProcess.TotalInitialFileSize / 2)
                        {
                            compColor = ConsoleThemeColor.TextGood;
                        }
                        else if (compressionProcess.FinalFileSize < (compressionProcess.TotalInitialFileSize / 4) * 3)
                        {
                            compColor = ConsoleThemeColor.SubTextGood;
                        }
                        else if ((compressionProcess.FinalFileSize >= ((compressionProcess.TotalInitialFileSize / 4) * 3)) &&
                                 (compressionProcess.FinalFileSize < compressionProcess.TotalInitialFileSize))
                        {
                            compColor = ConsoleThemeColor.SubTextNutral;
                        }
                        else if (compressionProcess.FinalFileSize == compressionProcess.TotalInitialFileSize)
                        {
                            compColor = ConsoleThemeColor.Text;
                        }
                        else if (compressionProcess.FinalFileSize > compressionProcess.TotalInitialFileSize)
                        {
                            compColor = ConsoleThemeColor.TextBad;
                        }

                        Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_FinalSize, CmdHelper.GetMemStringFromBytes(compressionProcess.FinalFileSize, true), RC.Theme[compColor]);

                        RC.WriteLine(ConsoleThemeColor.SubText, " " + new string(ConsoleChars.SingleLines[1], 41));

                        RC.Write(ConsoleVerbosity.Minimal, ConsoleThemeColor.TitleText, " " + Strings.Text_OverallCompression);

                        #endregion

                        if (compressionProcess.FinalFileSize > 0)
                        {
                            #region Print Final Success Message

                            string valueString = ((100 - (((double)compressionProcess.FinalFileSize / (double)compressionProcess.TotalInitialFileSize) * 100.0)).ToString("N2") + "%");

                            RC.Write(ConsoleVerbosity.Minimal, ConsoleThemeColor.SubText, " :".PadRight(22 - valueString.Length, '.'));
                            RC.WriteLine(ConsoleVerbosity.Minimal, compColor, valueString);

                            int offset = 6;

                            if (compColor == ConsoleThemeColor.TextBad)
                            {
                                offset += 3;
                                RC.WriteLine("");
                                RC.WriteWarning(0103, " " + Strings.Error_0103);
                            }

                            if (RC.CanManipulateBuffer && (int)RC.Verbosity >= (int)ConsoleVerbosity.Normal)
                            {
                                Rug.Cmd.CmdHelper.WriteRuglandLogo(48, RC.CursorTop - offset, 3, 2, false, ConsoleShade.Opaque);
                            }

                            #endregion
                        }
                        else
                        {
                            #region The Final Size Is Invlaid So Print A Message

                            RC.Write(ConsoleVerbosity.Minimal, ConsoleThemeColor.SubText, new string('.', 19 - Strings.Text_Invalid.Length));
                            RC.WriteLine(ConsoleVerbosity.Minimal, ConsoleThemeColor.ErrorColor1, Strings.Text_Invalid);

                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                RC.WriteException(0199, ex);
            }
            finally
            {
                #region Reset The Color State
                
                RC.ColorState = state;
                RC.WriteLine(ConsoleVerbosity.Minimal, ""); 

                #endregion
            }
        }
Exemplo n.º 4
0
        private AssemblyInfo ReflectAssemblyInfo(string archivePath, string uri, CompileProcess compileProcess)
        {
            AssemblyInfo info = new AssemblyInfo();

            AppDomain domain = null;

            try
            {
                string appDomainName = "Interrogator";                

                AppDomainSetup domainSetup = new AppDomainSetup();
                domainSetup.ApplicationName = appDomainName;
                domainSetup.ApplicationBase = new FileInfo(Application.ExecutablePath).DirectoryName; 

                domain = AppDomain.CreateDomain(appDomainName, null, domainSetup);

                AssemblyInterrogator remoteWorker = (AssemblyInterrogator)domain.CreateInstanceAndUnwrap(typeof(AssemblyInterrogator).Assembly.FullName, typeof(AssemblyInterrogator).FullName);

				string errorMessage, exceptionMessage;

				if (!remoteWorker.GetAssemblyInfo(archivePath, uri, out info, out errorMessage, out exceptionMessage))
                {
					if (RC.ShouldWrite(ConsoleVerbosity.Debug) && String.IsNullOrEmpty(exceptionMessage) == false)
					{
						throw new Exception(errorMessage + Environment.NewLine + exceptionMessage);
					}
					else
					{
						throw new Exception(errorMessage); 
					}
                    //throw new Exception(string.Format("{0} : {1}", Rpx.Strings.Compiler_UnableToLoadAsm, uri));					
                }
            
                info = AssemblyInfo.Clone(info); 

                compileProcess.PassArguments = info.PassArgs;
            }
            finally
            {
                if (domain != null)
                    AppDomain.Unload(domain);
            }

            return info;
        }
Exemplo n.º 5
0
        private void ReflectPESubsytemType(string archivePath, string uri, CompileProcess compileProcess)
        {
            try
            {
                string iconOutputPath = null;

                if (Helper.IsNullOrEmpty(compileProcess.IconFile))
                {
                    iconOutputPath = Application.UserAppDataPath + @"\" + Guid.NewGuid().GetHashCode().ToString() + ".ico";

                    compileProcess.IconFile = iconOutputPath;
                    compileProcess.DeleteIconWhenDone = true; 
                }
                
                PEFileInfo info;

				if (!PEFileInterrogator.TryGetPEFileInfo(archivePath, uri, iconOutputPath, out info))
				{ 
                    throw new Exception(string.Format(Rpx.Strings.Reflector_CouldNotReadPE, uri));
				}

                if (iconOutputPath != null && !File.Exists(iconOutputPath))
                {
                    compileProcess.IconFile = null;
                    compileProcess.DeleteIconWhenDone = false;
                }

                if (compileProcess.ExecutableTypeLookupMode == ExecutableTypeMode.Reflected)
                {
                    if (info.Subsystem == SubsystemTypes.WindowsCni)
                        compileProcess.ExecutableType = ExecutableType.Console;
                    else if (info.Subsystem == SubsystemTypes.WindowsGui)
                        compileProcess.ExecutableType = ExecutableType.Forms;
                    else
                    {
                        SubsystemTypes SubsystemType = info.Subsystem;

                        throw new Exception(string.Format(Rpx.Strings.Error_0107, SubsystemType.ToString()));
                    }
                }
            }
            finally
            {                
            }
        }