Exemple #1
0
        static int ParseInt32(string s)
        {
            string error;
            var    v = NumberVMUtils.ParseInt32(s, int.MinValue, int.MaxValue, out error);

            if (!string.IsNullOrEmpty(error))
            {
                throw new ErrorException(error);
            }
            return(v);
        }
Exemple #2
0
        void ParseCommandLine(string[] args)
        {
            if (args.Length == 0)
            {
                throw new ErrorException(dnSpy_Console_Resources.MissingOptions);
            }

            bool      canParseCommands = true;
            ILanguage lang             = null;
            Dictionary <string, Tuple <IDecompilerOption, Action <string> > > langDict = null;

            for (int i = 0; i < args.Length; i++)
            {
                if (lang == null)
                {
                    lang     = GetLanguage();
                    langDict = CreateLanguageOptionsDictionary(lang);
                }
                var arg  = args[i];
                var next = i + 1 < args.Length ? args[i + 1] : null;
                if (arg.Length == 0)
                {
                    continue;
                }

                // **********************************************************************
                // If you add more '--' options here, also update 'string[] ourOptions'
                // **********************************************************************

                if (canParseCommands && arg[0] == '-')
                {
                    string error;
                    switch (arg.Remove(0, 1))
                    {
                    case "":
                        canParseCommands = false;
                        break;

                    case "r":
                    case "-recursive":
                        isRecursive = true;
                        break;

                    case "o":
                    case "-output-dir":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingOutputDir);
                        }
                        outputDir = next;
                        i++;
                        break;

                    case "l":
                    case "-lang":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingLanguageName);
                        }
                        language = next;
                        i++;
                        if (GetLanguage() == null)
                        {
                            throw new ErrorException(string.Format(dnSpy_Console_Resources.LanguageDoesNotExist, language));
                        }
                        lang     = null;
                        langDict = null;
                        break;

                    case "-asm-path":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingAsmSearchPath);
                        }
                        asmPaths.AddRange(next.Split(new char[] { PATHS_SEP }, StringSplitOptions.RemoveEmptyEntries));
                        i++;
                        break;

                    case "-user-gac":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingUserGacPath);
                        }
                        userGacPaths.AddRange(next.Split(new char[] { PATHS_SEP }, StringSplitOptions.RemoveEmptyEntries));
                        i++;
                        break;

                    case "-no-gac":
                        useGac = false;
                        break;

                    case "-no-stdlib":
                        addCorlibRef = false;
                        break;

                    case "-no-sln":
                        createSlnFile = false;
                        break;

                    case "-sln-name":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingSolutionName);
                        }
                        slnName = next;
                        i++;
                        if (Path.IsPathRooted(slnName))
                        {
                            throw new ErrorException(string.Format(dnSpy_Console_Resources.InvalidSolutionName, slnName));
                        }
                        break;

                    case "-threads":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingNumberOfThreads);
                        }
                        i++;
                        numThreads = NumberVMUtils.ParseInt32(next, int.MinValue, int.MaxValue, out error);
                        if (!string.IsNullOrEmpty(error))
                        {
                            throw new ErrorException(error);
                        }
                        break;

                    case "-vs":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingVSVersion);
                        }
                        i++;
                        int vsVer;
                        vsVer = NumberVMUtils.ParseInt32(next, int.MinValue, int.MaxValue, out error);
                        if (!string.IsNullOrEmpty(error))
                        {
                            throw new ErrorException(error);
                        }
                        switch (vsVer)
                        {
                        case 2005: projectVersion = ProjectVersion.VS2005; break;

                        case 2008: projectVersion = ProjectVersion.VS2008; break;

                        case 2010: projectVersion = ProjectVersion.VS2010; break;

                        case 2012: projectVersion = ProjectVersion.VS2012; break;

                        case 2013: projectVersion = ProjectVersion.VS2013; break;

                        case 2015: projectVersion = ProjectVersion.VS2015; break;

                        default: throw new ErrorException(string.Format(dnSpy_Console_Resources.InvalidVSVersion, vsVer));
                        }
                        break;

                    case "-no-resources":
                        unpackResources = false;
                        break;

                    case "-no-resx":
                        createResX = false;
                        break;

                    case "-no-baml":
                        decompileBaml = false;
                        break;

                    case "t":
                    case "-type":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingTypeName);
                        }
                        i++;
                        typeName = next;
                        break;

                    case "-md":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingMDToken);
                        }
                        i++;
                        mdToken = NumberVMUtils.ParseInt32(next, int.MinValue, int.MaxValue, out error);
                        if (!string.IsNullOrEmpty(error))
                        {
                            throw new ErrorException(error);
                        }
                        break;

                    case "-gac-file":
                        if (next == null)
                        {
                            throw new ErrorException(dnSpy_Console_Resources.MissingGacFile);
                        }
                        i++;
                        gacFiles.Add(next);
                        break;

                    case "-project-guid":
                        if (next == null || !Guid.TryParse(next, out projectGuid))
                        {
                            throw new ErrorException(dnSpy_Console_Resources.InvalidGuid);
                        }
                        i++;
                        break;

                    default:
                        Tuple <IDecompilerOption, Action <string> > tuple;
                        if (langDict.TryGetValue(arg, out tuple))
                        {
                            bool hasArg = tuple.Item1.Type != typeof(bool);
                            if (hasArg && next == null)
                            {
                                throw new ErrorException(dnSpy_Console_Resources.MissingOptionArgument);
                            }
                            if (hasArg)
                            {
                                i++;
                            }
                            tuple.Item2(next);
                            break;
                        }

                        throw new ErrorException(string.Format(dnSpy_Console_Resources.InvalidOption, arg));
                    }
                }
                else
                {
                    files.Add(arg);
                }
            }
        }