示例#1
0
        public bool ChangeInfo(ModuleDefinition assembly, CorFlagsSettings args)
        {
            var flags = assembly.Attributes;

                        #if DEBUG
            Console.WriteLine(assembly.Attributes);
                        #endif
            if (args.ILONLY)
            {
                assembly.Attributes |= ModuleAttributes.ILOnly;
            }
            else if (args.NOT_ILONLY)
            {
                assembly.Attributes &= ~ModuleAttributes.ILOnly;
            }

            if (args.THIRTYTWO_BITPREFERRED)
            {
                assembly.Attributes |= ModuleAttributes.Preferred32Bit;
            }
            else if (args.THIRTYTWO_NOT_BITPREFERRED)
            {
                assembly.Attributes &= ~ModuleAttributes.Preferred32Bit;
            }

            if (args.THIRTYTWO_BITREQUIRED)
            {
                assembly.Attributes |= ModuleAttributes.Required32Bit;
            }
            else if (args.THIRTYTWO_NOT_BITREQUIRED)
            {
                assembly.Attributes &= ~ModuleAttributes.Required32Bit;
            }
            // CLR Header: 2.0 indicates a .Net 1.0 or .Net 1.1 (Everett) image
            //		 while 2.5 indicates a .Net 2.0 (Whidbey) image.
            // corflags : error CF014 : It is invalid to revert the CLR header on an image with a version of v4.0.30319
            bool runtimechanged = false;
            if (args.UpgradeCLRHeader)
            {
                assembly.RuntimeVersion = "4.0";
                assembly.Runtime        = TargetRuntime.Net_4_0;
                runtimechanged          = true;
            }
            else if (args.RevertCLRHeader)
            {
                assembly.RuntimeVersion = "1.1";
                assembly.Runtime        = TargetRuntime.Net_1_1;
                runtimechanged          = true;
            }

                        #if DEBUG
            Console.WriteLine(assembly.Attributes);
                        #endif

            return(flags != assembly.Attributes || runtimechanged);
        }
示例#2
0
        public CorFlagsSettings ParseArguments(string[] args)
        {
            var settings = new CorFlagsSettings();

            if (!ParseArguments(settings, args))
            {
                return(null);
            }

            return(settings);
        }
示例#3
0
        public ModuleDefinition OpenAssembly(CorFlagsSettings setting, string aFileName, Report report, out string fullAssemblyPath)
        {
            var dataPath = Path.GetDirectoryName(Environment.GetEnvironmentVariable("PWD"));

            fullAssemblyPath = Path.Combine(dataPath, aFileName);
            var fullPath = Path.GetFullPath(aFileName);

            if (!File.Exists(fullPath))
            {
                                #if DEBUG
                output.WriteLine(fullPath);
                                #endif
                throw new FileNotFoundException();
            }

            var targetModule = ModuleDefinition.ReadModule(fullPath);
            if (!IsMarked(targetModule))
            {
                // Console.WriteLine("isMarked?");
            }
            return(targetModule);
        }
示例#4
0
        //
        // This parses the -arg and /arg options
        //
        ParseResult ParseOption(string option, ref string[] args, CorFlagsSettings settings)
        {
            int    idx = option.IndexOf(':');
            string arg, value;

            if (idx == -1)
            {
                arg   = option;
                value = "";
            }
            else
            {
                arg = option.Substring(0, idx);

                value = option.Substring(idx + 1);
            }

            switch (arg.ToUpperInvariant())
            {
            case "/NOLOGO":
                settings.NoLogo = true;
                return(ParseResult.Success);

            case "/HELP":
            case "/?":
                Header();
                Usage();
                return(ParseResult.Stop);

            case "/ABOUT":
                About();
                return(ParseResult.Stop);

            case "/VERSION":
            case "/V":
                Version();
                return(ParseResult.Stop);

            case "/ISSUE":
            case "/BUGREPORT":
                output.WriteLine("To file bug reports, please visit: https://github.com/sushihangover/CorFlags/issues");
                return(ParseResult.Stop);

            case "/FORCE":
                settings.InfoOnly = false;
                settings.Force    = true;
                return(ParseResult.Success);

            case "/32BIT":
            case "/32BIT+":
            case "/32BITREQ+":
                settings.InfoOnly = false;
                settings.THIRTYTWO_BITREQUIRED     = true;
                settings.THIRTYTWO_NOT_BITREQUIRED = false;
                return(ParseResult.Success);

            case "/32BIT-":
            case "/32BITREQ-":
                settings.InfoOnly = false;
                settings.THIRTYTWO_BITREQUIRED     = false;
                settings.THIRTYTWO_NOT_BITREQUIRED = true;
                return(ParseResult.Success);

            case "/32BITPREF":
            case "/32BITPREF+":
                settings.InfoOnly = false;
                settings.THIRTYTWO_BITPREFERRED     = true;
                settings.THIRTYTWO_NOT_BITPREFERRED = false;
                return(ParseResult.Success);

            case "/32BITPREF-":
                settings.InfoOnly = false;
                settings.THIRTYTWO_BITPREFERRED     = false;
                settings.THIRTYTWO_NOT_BITPREFERRED = true;
                return(ParseResult.Success);

            case "/ILONLY":
            case "/ILONLY+":
                settings.InfoOnly   = false;
                settings.ILONLY     = true;
                settings.NOT_ILONLY = false;
                return(ParseResult.Success);

            case "/ILONLY-":
                settings.InfoOnly   = false;
                settings.ILONLY     = false;
                settings.NOT_ILONLY = true;
                return(ParseResult.Success);

            case "/REVERTCLRHEADER":
                settings.InfoOnly         = false;
                settings.RevertCLRHeader  = true;
                settings.UpgradeCLRHeader = false;
                return(ParseResult.Success);

            case "/UPGRADECLRHEADER":
                settings.InfoOnly         = false;
                settings.RevertCLRHeader  = false;
                settings.UpgradeCLRHeader = true;
                return(ParseResult.Success);


            case "/debug":
                if (value.Equals("+", StringComparison.OrdinalIgnoreCase) || value.Equals("full", StringComparison.OrdinalIgnoreCase) || value.Equals("pdbonly", StringComparison.OrdinalIgnoreCase) || idx < 0)
                {
                    return(ParseResult.Success);
                }

                return(ParseResult.Error);

            default:
                return(ParseResult.UnknownOption);
            }
        }
示例#5
0
        public bool ParseArguments(CorFlagsSettings settings, string[] args)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            bool parsing_options = true;

            stop_argument     = false;
            source_file_index = new Dictionary <string, int> ();

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg.Length == 0)
                {
                    continue;
                }

                if (arg[0] == '@')
                {
                    string[] extra_args;
                    string   response_file = arg.Substring(1);

                    extra_args = LoadArgs(response_file);
                    if (extra_args == null)
                    {
//						report.Error (2011, "Unable to open response file: " + response_file);
                        return(false);
                    }

                    args = AddArgs(args, extra_args);
                    continue;
                }

                if (parsing_options)
                {
                    if (arg == "--")
                    {
                        parsing_options = false;
                        continue;
                    }

                    bool dash_opt  = arg[0] == '-';
                    bool slash_opt = arg[0] == '/';
                    if (dash_opt || slash_opt)
                    {
                        string csc_opt = dash_opt ? "/" + arg.Substring(1) : arg;
                        settings.ArgList.Add(arg);
                        switch (ParseOption(csc_opt, ref args, settings))
                        {
                        case ParseResult.Error:
                        case ParseResult.Success:
                            continue;

                        case ParseResult.UnknownOption:
                            if ((slash_opt && arg.Length > 3 && arg.IndexOf('/', 2) > 0))
                            {
                                break;
                            }

                            if (UnknownOptionHandler != null)
                            {
                                var ret = UnknownOptionHandler(args, i);
                                if (ret != -1)
                                {
                                    i = ret;
                                    continue;
                                }
                            }

                            Error_WrongOption(arg);
                            return(false);

                        case ParseResult.Stop:
                            stop_argument = true;
                            return(true);
                        }
                    }
                }

                ProcessSourceFiles(arg, false, settings.SourceFiles);
            }

            return(true);
        }