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; } } using (FileStream fileStream = new FileStream(Path.Combine(this.TempDirectory, this.InputValues.FileName + ilSuffix + ".il"), FileMode.Create)) { using (StreamWriter streamWriter = new StreamWriter((Stream)fileStream, Encoding.Unicode)) { foreach (string str in stringList) { streamWriter.WriteLine(str); } } } } return(this.Run(outputFile, ilSuffix, cpu)); } finally { Directory.SetCurrentDirectory(currentDirectory); } }
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; } }
public static Dictionary <ParserState, IParserStateAction> GetActionsByState( IlParser parser) { Dictionary <ParserState, IParserStateAction> dictionary = new Dictionary <ParserState, IParserStateAction>() { { ParserState.ClassDeclaration, (IParserStateAction) new ClassDeclarationParserAction() }, { ParserState.Class, (IParserStateAction) new ClassParserAction() }, { ParserState.DeleteExportAttribute, (IParserStateAction) new DeleteExportAttributeParserAction() }, { ParserState.MethodDeclaration, (IParserStateAction) new MethodDeclarationParserAction() }, { ParserState.Method, (IParserStateAction) new MethodParserAction() }, { ParserState.MethodProperties, (IParserStateAction) new MethodPropertiesParserAction() }, { ParserState.Normal, (IParserStateAction) new NormalParserAction() } }; foreach (IParserStateAction parserStateAction in dictionary.Values) { parserStateAction.Parser = parser; } return(dictionary); }
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)); } } string fullPath = Path.GetFullPath(Path.GetDirectoryName(fileName)); int num1 = IlParser.RunIlTool(this.InputValues.FrameworkPath, "ILAsm.exe", (string)null, (string)null, "ILAsmPath", this.GetCommandLineArguments(cpu, fileName, ressourceParam, ilSuffix, str), DllExportLogginCodes.IlAsmLogging, DllExportLogginCodes.VerboseToolLogging, this.Notifier, this.Timeout, (Func <string, bool>)(line => { int num2 = line.IndexOf(": "); if (num2 > 0) { line = line.Substring(num2 + 1); } return(IlAsm._NormalizeIlErrorLineRegex.Replace(line, "").ToLowerInvariant().StartsWith("warningnonvirtualnonabstractinstancemethodininterfacesettosuch")); })); if (num1 == 0) { this.RunLibTool(cpu, fileName, fullPath); } return(num1); }
public int Run() { return(IlParser.RunIlTool(this.InputValues.SdkPath, "ildasm.exe", (string)null, (string)null, "ILDasmPath", string.Format((IFormatProvider)CultureInfo.InvariantCulture, "/quoteallnames /unicode /nobar{2}\"/out:{0}.il\" \"{1}\"", (object)Path.Combine(this.TempDirectory, this.InputValues.FileName), (object)this.InputValues.InputFileName, this.InputValues.EmitDebugSymbols ? (object)" /linenum " : (object)" "), DllExportLogginCodes.IlDasmLogging, DllExportLogginCodes.VerboseToolLogging, this.Notifier, this.Timeout, (Func <string, bool>)null)); }
internal static int RunIlTool( string installPath, string toolFileName, string requiredPaths, string workingDirectory, string settingsName, string arguments, string toolLoggingCode, string verboseLoggingCode, IDllExportNotifier notifier, int timeout, Func <string, bool> suppressErrorOutputLine = null) { using (notifier.CreateContextName((object)null, toolFileName)) { if (suppressErrorOutputLine != null) { Func <string, bool> suppressErrorOutputLineCore = suppressErrorOutputLine; suppressErrorOutputLine = (Func <string, bool>)(line => { if (line != null) { return(suppressErrorOutputLineCore(line)); } return(false); }); } else { suppressErrorOutputLine = (Func <string, bool>)(l => false); } string fileName = Path.GetFileName(toolFileName); string exePath = IlParser.GetExePath(fileName, installPath, settingsName); string withoutExtension = Path.GetFileNameWithoutExtension(fileName); int num; Exception outerException = null; for (int i = 0; i < 3; i++) { try { using (Process process = new Process()) { notifier.Notify(-2, toolLoggingCode, Resources.calling_0_with_1_, (object)exePath, (object)arguments); ProcessStartInfo processStartInfo = new ProcessStartInfo(exePath, arguments) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true }; if (!string.IsNullOrEmpty(workingDirectory)) { processStartInfo.WorkingDirectory = Path.GetFullPath(workingDirectory); } if (!string.IsNullOrEmpty(requiredPaths)) { processStartInfo.EnvironmentVariables["PATH"] = requiredPaths.Trim(';') + ";" + (processStartInfo.EnvironmentVariables.ContainsKey("PATH") ? processStartInfo.EnvironmentVariables["PATH"] : (string)null); } process.StartInfo = processStartInfo; process.Start(); Stopwatch stopwatch = Stopwatch.StartNew(); StringBuilder stringBuilder1 = new StringBuilder(); StringBuilder stringBuilder2 = new StringBuilder(); Action <IEnumerable <string>, StringBuilder> appendLines = (Action <IEnumerable <string>, StringBuilder>)((lines, sb) => lines.Aggregate <string, StringBuilder>(sb, (Func <StringBuilder, string, StringBuilder>)((r, line) => r.AppendLine(line)))); Action <StreamReader, StringBuilder> action1 = (Action <StreamReader, StringBuilder>)((sr, sb) => appendLines(IlParser.EnumerateStreamLines(sr), sb)); Action <StreamReader, StringBuilder> action2 = (Action <StreamReader, StringBuilder>)((sr, sb) => appendLines(IlParser.EnumerateStreamLines(sr).Where <string>((Func <string, bool>)(line => !suppressErrorOutputLine(line))), sb)); while (stopwatch.ElapsedMilliseconds < (long)timeout && !process.HasExited) { action1(process.StandardOutput, stringBuilder1); action2(process.StandardError, stringBuilder2); } bool hasExited = process.HasExited; action1(process.StandardOutput, stringBuilder1); action2(process.StandardError, stringBuilder2); if (hasExited) { notifier.Notify(-2, toolLoggingCode, Resources.R_0_1_returned_gracefully, (object)withoutExtension, (object)exePath); int exitCode = process.ExitCode; if (exitCode != 0) { throw new InvalidOperationException((stringBuilder2.Length > 0 ? (object)stringBuilder2 : (object)stringBuilder1).ToString()); } if (stringBuilder2.Length > 0) { notifier.Notify(-3, verboseLoggingCode, stringBuilder2.ToString()); } if (stringBuilder1.Length > 0) { notifier.Notify(-3, verboseLoggingCode, stringBuilder1.ToString()); } num = exitCode; } else { bool flag = false; Exception exception = (Exception)null; try { process.Kill(); flag = true; } catch (Exception ex) { exception = ex; } if (flag) { throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.R_0_did_not_return_after_1_ms, (object)withoutExtension, (object)timeout)); } throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, Resources.R_0_did_not_return_after_1_ms_and_it_could_not_be_stopped, (object)withoutExtension, (object)timeout, (object)exception.Message)); } return(num); } } catch (Exception ex) { outerException = ex; } } throw outerException; } }