private int RunLibTool(CpuPlatform cpu, string fileName, string directory)
        {
            if (string.IsNullOrEmpty(this.InputValues.LibToolPath))
            {
                return(0);
            }
            string libraryFileNameRoot = IlAsm.GetLibraryFileNameRoot(fileName);
            string defFile             = this.CreateDefFile(cpu, directory, libraryFileNameRoot);

            try
            {
                return(this.RunLibToolCore(cpu, directory, defFile));
            }
            catch (Exception ex)
            {
                this.Notifier.Notify(1, DllExportLogginCodes.LibToolLooging, Resources.An_error_occurred_while_calling_0_1_, (object)"lib.exe", (object)ex.Message);
                return(-1);
            }
            finally
            {
                if (File.Exists(defFile))
                {
                    File.Delete(defFile);
                }
            }
        }
예제 #2
0
        private string CreateDefFile(CpuPlatform cpu, string directory, string libraryName)
        {
            string path = Path.Combine(directory, libraryName + "." + cpu + ".def");

            try
            {
                using (var swriter = new StreamWriter(path, false, Encoding.UTF8))
                {
                    var data = new List <string>()
                    {
                        $"LIBRARY {libraryName}.dll",
                        "",
                        "EXPORTS"
                    };

                    data.AddRange(Exports.ClassesByName.Values
                                  .SelectMany(c =>
                                              c.Methods.Select(m => m.ExportName)));

                    swriter.WriteLine(String.Join(Environment.NewLine, data));
                }

                return(path);
            }
            catch
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                throw;
            }
        }
예제 #3
0
        private int RunCore(CpuPlatform cpu, string fileName, string ressourceParam, string ilSuffix)
        {
            string str = (string)null;

            if (!string.IsNullOrEmpty(this.InputValues.KeyFile))
            {
                str = Path.GetFullPath(this.InputValues.KeyFile);
            }
            if (!string.IsNullOrEmpty(str) && !File.Exists(str))
            {
                if (!string.IsNullOrEmpty(this.InputValues.RootDirectory) && Directory.Exists(this.InputValues.RootDirectory))
                {
                    str = Path.Combine(this.InputValues.RootDirectory, this.InputValues.KeyFile);
                }
                if (!File.Exists(str))
                {
                    throw new FileNotFoundException(string.Format(Resources.Provided_key_file_0_cannot_be_found, (object)str));
                }
            }

            int ret = IlParser.RunIlTool
                      (
                String.IsNullOrWhiteSpace(InputValues.OurILAsmPath) ? InputValues.FrameworkPath : InputValues.OurILAsmPath,
                "ilasm.exe",
                null,
                null,
                "ILAsmPath",
                GetCommandLineArguments(cpu, fileName, ressourceParam, ilSuffix, str),
                DllExportLogginCodes.IlAsmLogging,
                DllExportLogginCodes.VerboseToolLogging,
                Notifier,
                Timeout,
                line =>
            {
                int col = line.IndexOf(": ");
                if (col > 0)
                {
                    line = line.Substring(col + 1);
                }

                return(IlAsm
                       ._NormalizeIlErrorLineRegex
                       .Replace(line, "")
                       .ToLowerInvariant()
                       .StartsWith("warningnonvirtualnonabstractinstancemethodininterfacesettosuch"));
            }
                      );

            if (ret != 0)
            {
                return(ret);
            }

            ret = CheckPE(cpu, fileName);
            if (ret == 0)
            {
                RunLibTool(cpu, fileName, Path.GetFullPath(Path.GetDirectoryName(fileName)));
            }
            return(ret);
        }
예제 #4
0
        public int ReassembleFile(string outputFile, string ilSuffix, CpuPlatform cpu)
        {
            string currentDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(TempDirectory);

            try
            {
                string directoryName = Path.GetDirectoryName(outputFile);
                if (directoryName != null && !Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }

                using (IlParser ilParser = new IlParser(ServiceProvider)) {
                    ReassembleFile(ilParser, ilSuffix, cpu);
                }

                return(Run(outputFile, ilSuffix, cpu));
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
        private string CreateDefFile(CpuPlatform cpu, string directory, string libraryName)
        {
            string path = Path.Combine(directory, libraryName + "." + (object)cpu + ".def");

            try
            {
                using (FileStream fileStream = new FileStream(path, FileMode.Create))
                {
                    using (StreamWriter streamWriter = new StreamWriter((Stream)fileStream, Encoding.UTF8))
                    {
                        streamWriter.WriteLine("LIBRARY {0}.dll", (object)libraryName);
                        streamWriter.WriteLine();
                        streamWriter.WriteLine("EXPORTS");
                        foreach (ExportedClass exportedClass in this.Exports.ClassesByName.Values)
                        {
                            foreach (ExportedMethod method in exportedClass.Methods)
                            {
                                streamWriter.WriteLine(method.ExportName);
                            }
                        }
                    }
                }
                return(path);
            }
            catch (Exception ex)
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                throw;
            }
        }
예제 #6
0
        private string GetCommandLineArguments(CpuPlatform cpu, string fileName, string ressourceParam, string ilSuffix, string keyFile)
        {
            if (String.IsNullOrEmpty(keyFile))
            {
                keyFile = String.IsNullOrEmpty(InputValues.KeyContainer) ? null : "\"/Key=@" + InputValues.KeyContainer + "\"";
            }
            else
            {
                keyFile = "\"/Key=" + keyFile + '"';
            }

            return(string.Format
                   (
                       CultureInfo.InvariantCulture,
                       "/nologo \"/out:{0}\" \"{1}.il\" {2} {3} {4} {5} {6} {7}",
                       fileName,
                       Path.Combine(TempDirectory, Path.GetFileNameWithoutExtension(InputValues.InputFileName)) + ilSuffix,
                       "/" + Path.GetExtension(fileName).Trim(new char[] { '.', '"' }).ToUpperInvariant(),
                       ressourceParam,
                       InputValues.EmitDebugSymbols ? "/debug" : "/optimize",
                       cpu == CpuPlatform.X86 ? "" : (" /PE64 " + (cpu == CpuPlatform.Itanium ? " /ITANIUM" : " /X64")),
                       keyFile,
                       GetKeysToCustomILAsm()
                   ));
        }
 private string GetCommandLineArguments(
     CpuPlatform cpu,
     string fileName,
     string ressourceParam,
     string ilSuffix,
     string keyFile)
 {
     return(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "/nologo \"/out:{0}\" \"{1}.il\" /DLL{2} {3} {4} {5}", (object)fileName, (object)(Path.Combine(this.TempDirectory, Path.GetFileNameWithoutExtension(this.InputValues.InputFileName)) + ilSuffix), (object)ressourceParam, this.InputValues.EmitDebugSymbols ? (object)"/debug" : (object)"/optimize", cpu == CpuPlatform.X86 ? (object)"" : (object)(" /PE64 " + (cpu == CpuPlatform.Itanium ? " /ITANIUM" : " /X64")), string.IsNullOrEmpty(keyFile) ? (!string.IsNullOrEmpty(this.InputValues.KeyContainer) ? (object)("\"/Key=@" + this.InputValues.KeyContainer + "\"") : (object)(string)null) : (object)("\"/Key=" + keyFile + (object)'"')));
 }
예제 #8
0
 private int reassembleFile(IlAsm ilAsm, string outputFile, string ilSuffix, CpuPlatform cpu)
 {
     try {
         return(ilAsm.ReassembleFile(outputFile, ilSuffix, cpu));
     }
     finally {
         cleanup(ilAsm);
     }
 }
예제 #9
0
        public int ReassembleFile(string outputFile, string ilSuffix, CpuPlatform cpu)
        {
            string currentDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(this.TempDirectory);
            try
            {
                string directoryName = Path.GetDirectoryName(outputFile);
                if (directoryName != null && !Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }
                using (IlParser ilParser = new IlParser(this.ServiceProvider))
                {
                    ilParser.Exports       = this.Exports;
                    ilParser.InputValues   = this.InputValues;
                    ilParser.TempDirectory = this.TempDirectory;
                    List <string> stringList = new List <string>(ilParser.GetLines(cpu));
                    if (stringList.Count > 0)
                    {
                        string input = stringList[stringList.Count - 1];
                        if (!input.NullSafeCall <string, bool>((Func <string, bool>)(l => {
                            if (!l.EndsWith("\\r"))
                            {
                                return(l.EndsWith("\\n"));
                            }
                            return(true);
                        })))
                        {
                            stringList[stringList.Count - 1] = input + Environment.NewLine;
                        }
                    }

                    Stream stream = null;
                    try {
                        stream = new FileStream(Path.Combine(TempDirectory, InputValues.FileName + ilSuffix + ".il"), FileMode.Create);
                        using (StreamWriter swriter = new StreamWriter(stream, Encoding.Unicode))
                        {
                            stream = null; // avoid CA2202
                            swriter.WriteLine(String.Join(Environment.NewLine, stringList));
                        }
                    }
                    finally {
                        if (stream != null)
                        {
                            stream.Dispose();
                        }
                    }
                }
                return(this.Run(outputFile, ilSuffix, cpu));
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
예제 #10
0
        internal static int GetCorFlags(this CpuPlatform cpu)
        {
            switch (cpu)
            {
            case CpuPlatform.X86:
                return(2);

            case CpuPlatform.X64:
                return(0);

            default:
                throw new ArgumentOutOfRangeException(nameof(cpu), cpu, null);
            }
        }
예제 #11
0
        private int Run(string outputFile, string ilSuffix, CpuPlatform cpu)
        {
            StringBuilder stringBuilder = new StringBuilder(100);

            foreach (string file in Directory.GetFiles(this.TempDirectory, "*.res"))
            {
                if (string.Equals(Path.GetExtension(file).NullSafeTrimStart('.'), "res", StringComparison.OrdinalIgnoreCase))
                {
                    stringBuilder.Append(" \"/resource=").Append(file).Append("\" ");
                }
            }
            string ressourceParam = stringBuilder.ToString();

            if (string.IsNullOrEmpty(ressourceParam))
            {
                ressourceParam = " ";
            }
            string str1 = "";

            if (string.Equals(this.InputValues.InputFileName, outputFile, StringComparison.OrdinalIgnoreCase))
            {
                string str2 = this.InputValues.InputFileName + ".bak";
                int    num  = 1;
                do
                {
                    str1 = str2 + (object)num;
                    ++num;
                }while(File.Exists(str1));
                File.Move(this.InputValues.InputFileName, str1);
            }

            // https://github.com/3F/coreclr/blob/05afa4f81fdf671429b54467c64d65cde6b5fadc/src/debug/ildbsymlib/symwrite.cpp#L308
            // Due to possible incorrect ISymUnmanagedWriter when exists initial pdb data for non-modified asm.
            // \- Part of https://github.com/3F/DllExport/issues/90
            File.Delete(Path.ChangeExtension(InputValues.InputFileName, ".pdb"));

            try {
                return(this.RunCore(cpu, outputFile, ressourceParam, ilSuffix));
            }
            finally
            {
                if (!string.IsNullOrEmpty(str1) && File.Exists(str1))
                {
                    File.Delete(str1);
                }
            }
        }
        private int RunLibToolCore(CpuPlatform cpu, string directory, string defFileName)
        {
            string path = Path.Combine(directory, Path.GetFileNameWithoutExtension(this.InputValues.OutputFileName)) + ".lib";

            try
            {
                return(IlParser.RunIlTool(this.InputValues.LibToolPath, "Lib.exe", string.IsNullOrEmpty(this.InputValues.LibToolDllPath) || !Directory.Exists(this.InputValues.LibToolDllPath) ? (string)null : this.InputValues.LibToolDllPath, (string)null, "LibToolPath", string.Format("\"/def:{0}\" /machine:{1} \"/out:{2}\"", (object)defFileName, (object)cpu, (object)path), DllExportLogginCodes.LibToolLooging, DllExportLogginCodes.LibToolVerboseLooging, this.Notifier, this.Timeout, (Func <string, bool>)null));
            }
            catch (Exception ex)
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                throw;
            }
        }
예제 #13
0
        private string CreateDefFile(CpuPlatform cpu, string directory, string libraryName)
        {
            string path = Path.Combine(directory, libraryName + "." + (object)cpu + ".def");

            try
            {
                Stream stream = null;
                try {
                    stream = new FileStream(path, FileMode.Create);
                    using (StreamWriter swriter = new StreamWriter(stream, Encoding.UTF8))
                    {
                        stream = null; // avoid CA2202

                        var data = new List <string>()
                        {
                            $"LIBRARY {libraryName}.dll",
                            "",
                            "EXPORTS"
                        };

                        data.AddRange(Exports.ClassesByName.Values
                                      .SelectMany(c =>
                                                  c.Methods.Select(m => m.ExportName)));

                        swriter.WriteLine(String.Join(Environment.NewLine, data));
                    }
                }
                finally {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                }

                return(path);
            }
            catch
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                throw;
            }
        }
        private int Run(string outputFile, string ilSuffix, CpuPlatform cpu)
        {
            StringBuilder stringBuilder = new StringBuilder(100);

            foreach (string file in Directory.GetFiles(this.TempDirectory, "*.res"))
            {
                if (string.Equals(Path.GetExtension(file).NullSafeTrimStart('.'), "res", StringComparison.OrdinalIgnoreCase))
                {
                    stringBuilder.Append(" \"/resource=").Append(file).Append("\" ");
                }
            }
            string ressourceParam = stringBuilder.ToString();

            if (string.IsNullOrEmpty(ressourceParam))
            {
                ressourceParam = " ";
            }
            string str1 = "";

            if (string.Equals(this.InputValues.InputFileName, outputFile, StringComparison.OrdinalIgnoreCase))
            {
                string str2 = this.InputValues.InputFileName + ".bak";
                int    num  = 1;
                do
                {
                    str1 = str2 + (object)num;
                    ++num;
                }while (File.Exists(str1));
                File.Move(this.InputValues.InputFileName, str1);
            }
            try
            {
                return(this.RunCore(cpu, outputFile, ressourceParam, ilSuffix));
            }
            finally
            {
                if (!string.IsNullOrEmpty(str1) && File.Exists(str1))
                {
                    File.Delete(str1);
                }
            }
        }
예제 #15
0
        /// <param name="cpu"></param>
        /// <param name="file">Modified PE-file.</param>
        private int CheckPE(CpuPlatform cpu, string pefile)
        {
            int ret = 0;

            if (InputValues.PeCheck == PeCheckType.None)
            {
                return(ret);
            }

            using (var pe = new net.r_eg.Conari.PE.PEFile(pefile))
            {
                var ilMethods = Exports.ClassesByName.Values
                                .SelectMany(c => c.Methods.Select(m => m.ExportName))
                                .ToArray();

                var peMethods = pe.ExportedProcNames.ToArray();

                if ((InputValues.PeCheck & PeCheckType.Pe1to1) == PeCheckType.Pe1to1)
                {
                    Notifier.Notify(-2, DllExportLogginCodes.PeCheck1to1, $"{nameof(PeCheckType.Pe1to1)} is activated.");
                    if (!CheckPE1to1(ilMethods, peMethods, pefile))
                    {
                        ret = -1;
                    }
                }

                if ((InputValues.PeCheck & PeCheckType.PeIl) == PeCheckType.PeIl)
                {
                    Notifier.Notify(-2, DllExportLogginCodes.PeCheckIl, $"{nameof(PeCheckType.PeIl)} is activated.");
                    if (!CheckPEIl(ilMethods, peMethods, pefile))
                    {
                        ret = -1;
                    }
                }
            }

            return(ret);
        }
예제 #16
0
        private string GetCommandLineArguments(CpuPlatform cpu, string fileName, string ressourceParam, string ilSuffix, string keyFile)
        {
            if (String.IsNullOrEmpty(keyFile))
            {
                keyFile = String.IsNullOrEmpty(InputValues.KeyContainer) ? null : "\"/Key=@" + InputValues.KeyContainer + "\"";
            }
            else
            {
                keyFile = "\"/Key=" + keyFile + '"';
            }

            string cvtres;

            if (!String.IsNullOrWhiteSpace(InputValues.OurILAsmPath))
            {
                // https://github.com/3F/coreclr/issues/2
                // Only our new ILAsm 4.5.1+ may detect cvtres.exe automatically if the path is not presented at all. However, we can also provide CVR key
                cvtres = String.IsNullOrWhiteSpace(InputValues.FrameworkPath) ? "" : $"/CVRES=\"{InputValues.FrameworkPath}/\"";
            }
            else
            {
                cvtres = String.Empty; // original coreclr \ ILAsm does not support /CVRES
            }

            return(String.Format(
                       CultureInfo.InvariantCulture,
                       "/nologo \"/out:{0}\" \"{1}.il\" {2} {3} {4} {5} {6} {7}",
                       fileName,
                       Path.Combine(TempDirectory, Path.GetFileNameWithoutExtension(InputValues.InputFileName)) + ilSuffix,
                       "/" + Path.GetExtension(fileName).Trim(new char[] { '.', '"' }).ToUpperInvariant(),
                       ressourceParam,
                       InputValues.EmitDebugSymbols ? "/debug" : "/optimize",
                       cpu == CpuPlatform.X86 ? "" : (" /PE64 " + (cpu == CpuPlatform.Itanium ? " /ITANIUM" : " /X64")),
                       keyFile,
                       cvtres
                       ));
        }
예제 #17
0
        private void ReassembleFile(IlParser ilParser, string ilSuffix, CpuPlatform cpu)
        {
            ilParser.Exports       = Exports;
            ilParser.InputValues   = InputValues;
            ilParser.TempDirectory = TempDirectory;

            var stringList = new List <string>(ilParser.GetLines(cpu));

            if (stringList.Count > 0)
            {
                string input = stringList[stringList.Count - 1];

                if (!input.NullSafeCall(l => !l.EndsWith("\\r") ? l.EndsWith("\\n") : true))
                {
                    stringList[stringList.Count - 1] = input + Environment.NewLine;
                }
            }

            var dest = Path.Combine(TempDirectory, InputValues.FileName + ilSuffix + ".il");

            using (var swriter = new StreamWriter(dest, false, Encoding.Unicode)) {
                swriter.WriteLine(String.Join(Environment.NewLine, stringList));
            }
        }
예제 #18
0
 public static int GetCoreFlagsForPlatform(CpuPlatform cpu)
 {
     return(cpu != CpuPlatform.X86 ? 0 : 2);
 }
예제 #19
0
        private int RunLibTool(CpuPlatform cpu, string fileName, string directory)
        {
            if (!InputValues.GenExpLib)
            {
                return(0);
            }

            string libFileRoot = IlAsm.GetLibraryFileNameRoot(fileName);
            string defFile     = CreateDefFile(cpu, directory, libFileRoot);
            string path        = Path.Combine(directory, Path.GetFileNameWithoutExtension(InputValues.OutputFileName)) + ".lib";
            string cfg         = $"\"/def:{defFile}\" /machine:{cpu} \"/out:{path}\"";

            try
            {
                Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"VsDevCmd: {InputValues.VsDevCmd}");
                if (!String.IsNullOrWhiteSpace(InputValues.VsDevCmd))
                {
                    int code = RunLibToolCore(
                        "cmd",
                        $"/C \"\"{InputValues.VsDevCmd}\" -no_logo -arch={(cpu == CpuPlatform.X64 ? "amd64" : "x86")} && lib.exe {cfg}\""
                        );

                    Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"lib tool via VsDevCmd: {code}");
                    if (code == 0)
                    {
                        return(code);
                    }
                }

                Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"LibToolPath: {InputValues.LibToolPath}");
                if (!String.IsNullOrWhiteSpace(InputValues.LibToolPath))
                {
                    string reqPath = (String.IsNullOrEmpty(InputValues.LibToolDllPath) || !Directory.Exists(InputValues.LibToolDllPath)) ? null : InputValues.LibToolDllPath;
                    int    code    = RunLibToolCore("Lib.exe", cfg, InputValues.LibToolPath, reqPath);

                    Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"lib tool via LibToolPath: {code}");
                    if (code == 0)
                    {
                        return(code);
                    }
                }

                Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"VcVarsAll: {InputValues.VcVarsAll}");
                if (!String.IsNullOrWhiteSpace(InputValues.VcVarsAll))
                {
                    int code = RunLibToolCore(
                        "cmd",
                        $"/C \"\"{InputValues.VcVarsAll}\" {(cpu == CpuPlatform.X64 ? "x64" : "x86")} && lib.exe {cfg}\""
                        );

                    Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"lib tool via VcVarsAll: {code}");
                    if (code == 0)
                    {
                        return(code);
                    }
                }

                int ret = RunLibToolCore("lib.exe", cfg, String.Empty, InputValues.LibToolDllPath);
                Notifier.Notify(0, DllExportLogginCodes.LibToolLooging, $"lib tool via LibToolDllPath '{InputValues.LibToolDllPath}': {ret}");
                if (ret != -1)
                {
                    return(ret);
                }

                throw new FileNotFoundException("The library manager still cannot be found or something went wrong.");
            }
            catch (Exception ex)
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                Notifier.Notify(1, DllExportLogginCodes.LibToolLooging, Resources.An_error_occurred_while_calling_0_1_, "lib.exe", ex.Message);
                return(-1);
            }
            finally
            {
                if (File.Exists(defFile))
                {
                    File.Delete(defFile);
                }
            }
        }
예제 #20
0
        public IEnumerable <string> GetLines(CpuPlatform cpu)
        {
            using (this.GetNotifier().CreateContextName((object)this, Resources.ParseILContextName))
            {
                Dictionary <ParserState, IParserStateAction> actionsByState = IlParser.ParserStateAction.GetActionsByState(this);
                List <string>     stringList1 = new List <string>(1000000);
                ParserStateValues state       = new ParserStateValues(cpu, (IList <string>)stringList1)
                {
                    State = ParserState.Normal
                };
                Stopwatch stopwatch1 = Stopwatch.StartNew();

                var dest = Path.Combine(TempDirectory, InputValues.FileName + ".il");
                using (var sreader = new StreamReader(new FileStream(dest, FileMode.Open), Encoding.Unicode))
                {
                    while (!sreader.EndOfStream)
                    {
                        stringList1.Add(sreader.ReadLine());
                    }
                }

                Action <IParserStateAction, string> action1 = (Action <IParserStateAction, string>)((action, trimmedLine) => {
                    string name = action.GetType().Name;
                    using (this.GetNotifier().CreateContextName((object)action, name))
                        action.Execute(state, trimmedLine);
                });
                if (this.ProfileActions)
                {
                    Action <IParserStateAction, string> executeActionCore = action1;
                    action1 = (Action <IParserStateAction, string>)((action, trimmedLine) => {
                        Stopwatch stopwatch = Stopwatch.StartNew();
                        executeActionCore(action, trimmedLine);
                        stopwatch.Stop();
                        action.Milliseconds += stopwatch.ElapsedMilliseconds;
                    });
                }
                Dictionary <string, int> usedScopeNames = new Dictionary <string, int>();
                for (int index = 0; index < stringList1.Count; ++index)
                {
                    state.InputPosition = index;
                    string str1 = stringList1[index];
                    IlParsingUtils.ParseIlSnippet(str1, ParsingDirection.Forward, (Func <IlParsingUtils.IlSnippetLocation, bool>)(current => {
                        if (!current.WithinString && (int)current.CurrentChar == 93 && (current.LastIdentifier != null && !usedScopeNames.ContainsKey(current.LastIdentifier)))
                        {
                            usedScopeNames.Add(current.LastIdentifier, usedScopeNames.Count);
                        }
                        return(true);
                    }), (Action <IlParsingUtils.IlSnippetFinalizaton>)null);
                    string str2 = str1.NullSafeTrim();
                    state.AddLine = true;
                    IParserStateAction parserStateAction;
                    if (!actionsByState.TryGetValue(state.State, out parserStateAction))
                    {
                        this.GetNotifier().Notify(2, DllExportLogginCodes.NoParserActionError, Resources.No_action_for_parser_state_0_, (object)state.State);
                    }
                    else
                    {
                        action1(parserStateAction, str2);
                    }
                    if (state.AddLine)
                    {
                        state.Result.Add(str1);
                    }
                }
                List <string> stringList2 = state.Result;
                if (state.ExternalAssemlyDeclarations.Count > 0)
                {
                    stringList2 = new List <string>(state.Result.Count);
                    stringList2.AddRange((IEnumerable <string>)state.Result);
                    List <ExternalAssemlyDeclaration> assemlyDeclarationList = new List <ExternalAssemlyDeclaration>(state.ExternalAssemlyDeclarations.Count);
                    Dictionary <string, int>          foundAliases           = new Dictionary <string, int>();
                    foreach (string inputText in stringList2)
                    {
                        if (inputText.Length >= 3 && inputText.Contains("["))
                        {
                            IlParsingUtils.ParseIlSnippet(inputText, ParsingDirection.Forward, (Func <IlParsingUtils.IlSnippetLocation, bool>)(current => {
                                if (current.WithinScope && !current.WithinString && (current.LastIdentifier != null && !foundAliases.ContainsKey(current.LastIdentifier)))
                                {
                                    foundAliases.Add(current.LastIdentifier, foundAliases.Count);
                                }
                                return(true);
                            }), (Action <IlParsingUtils.IlSnippetFinalizaton>)null);
                        }
                    }
                    foreach (ExternalAssemlyDeclaration assemlyDeclaration in (IEnumerable <ExternalAssemlyDeclaration>)state.ExternalAssemlyDeclarations)
                    {
                        if (!foundAliases.ContainsKey(assemlyDeclaration.AliasName))
                        {
                            assemlyDeclarationList.Add(assemlyDeclaration);
                        }
                    }
                    if (assemlyDeclarationList.Count > 0)
                    {
                        assemlyDeclarationList.Reverse();
                        foreach (ExternalAssemlyDeclaration assemlyDeclaration in assemlyDeclarationList)
                        {
                            int num1 = 0;
                            int num2 = -1;
                            for (int inputLineIndex = assemlyDeclaration.InputLineIndex; inputLineIndex < stringList2.Count; ++inputLineIndex)
                            {
                                string str = stringList2[inputLineIndex].TrimStart();
                                if (str == "{")
                                {
                                    ++num1;
                                }
                                else if (str == "}")
                                {
                                    if (num1 == 1)
                                    {
                                        num2 = inputLineIndex;
                                        break;
                                    }
                                    --num1;
                                }
                            }
                            if (num2 > -1)
                            {
                                this.GetNotifier().Notify(-2, DllExportLogginCodes.RemovingReferenceToDllExportAttributeAssembly, string.Format(Resources.Deleting_reference_to_0_, (object)assemlyDeclaration.AssemblyName, assemlyDeclaration.AliasName != assemlyDeclaration.AssemblyName ? (object)string.Format(Resources.AssemblyAlias, (object)assemlyDeclaration.AliasName) : (object)""));
                                stringList2.RemoveRange(assemlyDeclaration.InputLineIndex, num2 - assemlyDeclaration.InputLineIndex + 1);
                            }
                        }
                    }
                }
                stopwatch1.Stop();
                this.GetNotifier().Notify(-2, "EXPPERF02", Resources.Parsing_0_lines_of_IL_took_1_ms_, (object)stringList1.Count, (object)stopwatch1.ElapsedMilliseconds);
                if (this.ProfileActions)
                {
                    foreach (KeyValuePair <ParserState, IParserStateAction> keyValuePair in actionsByState)
                    {
                        this.GetNotifier().Notify(-1, "EXPPERF03", Resources.Parsing_action_0_took_1_ms, (object)keyValuePair.Key, (object)keyValuePair.Value.Milliseconds);
                    }
                }
                return((IEnumerable <string>)stringList2);
            }
        }
예제 #21
0
 public ParserStateValues(CpuPlatform cpu, IList<string> inputLines)
 {
     this._Cpu = cpu;
     this._InputLines = new ReadOnlyCollection<string>(inputLines);
     this._ReadonlyExternalAssemlyDeclarations = (IList<ExternalAssemlyDeclaration>)this._ExternalAssemlyDeclarations.AsReadOnly();
 }