private void RunIlAsm(string tempDir) { using (IlAsm ilAsm = PrepareIlAsm(tempDir ?? throw new ArgumentNullException(nameof(tempDir)))) { RunIlAsm(ilAsm); } }
private void cleanup(IlAsm ilAsm) { foreach (var _class in ilAsm.Exports.ClassesByName.Values) { _class.ResetExportedMethods(); } }
private int reassembleFile(IlAsm ilAsm, string outputFile, string ilSuffix, CpuPlatform cpu) { try { return(ilAsm.ReassembleFile(outputFile, ilSuffix, cpu)); } finally { cleanup(ilAsm); } }
private IlAsm PrepareIlAsm(string tempDirectory) { using (this.GetNotifier().CreateContextName((object)this, "PrepareIlAsm")) { IlAsm instance = new IlAsm((IServiceProvider)this, this.InputValues); instance.Timeout = this.Timeout; return(instance.TryInitialize <IlAsm>((Action <IlAsm>)(ilAsm => { ilAsm.TempDirectory = tempDirectory; ilAsm.Exports = this.Exports; }))); } }
public void Run() { if (this.Exports == null) { IExportAssemblyInspector assemblyInspector = Utilities.CreateAssemblyInspector(this.InputValues); using (this.GetNotifier().CreateContextName((object)this, Resources.ExtractExportsContextName)) this.Exports = assemblyInspector.ExtractExports(); using (this.GetNotifier().CreateContextName((object)this, Resources.FindDuplicateExportMethodsContextName)) { foreach (DuplicateExports duplicateExportMethod in this.Exports.DuplicateExportMethods) { if (duplicateExportMethod.Duplicates.Count > 0) { StringBuilder stringBuilder = new StringBuilder(200).AppendFormat("{0}.{1}", (object)duplicateExportMethod.UsedExport.ExportedClass.NullSafeCall <ExportedClass, string>((Func <ExportedClass, string>)(ec => ec.FullTypeName)), (object)duplicateExportMethod.UsedExport.Name); foreach (ExportedMethod duplicate in (IEnumerable <ExportedMethod>)duplicateExportMethod.Duplicates) { stringBuilder.AppendFormat(", {0}.{1}", (object)duplicate.ExportedClass.NullSafeCall <ExportedClass, string>((Func <ExportedClass, string>)(ec => ec.FullTypeName)), (object)duplicate.Name); } } } } } if (this.Exports.Count == 0) { return; } using (this.GetNotifier().CreateContextName((object)this, Resources.CreateTempDirectoryContextName)) { using (ValueDisposable <string> tempDirectory = Utilities.CreateTempDirectory()) { this.RunIlDasm(tempDirectory.Value); bool flag = ((IEnumerable <string>) new string[2] { "true", "yes" }).Any <string>((Func <string, bool>)(t => t.Equals(this.InputValues.LeaveIntermediateFiles, StringComparison.InvariantCultureIgnoreCase))); if (flag) { using (this.GetNotifier().CreateContextName((object)this, Resources.CopyBeforeContextName)) DllExportWeaver.CopyDirectory(tempDirectory.Value, Path.Combine(Path.GetDirectoryName(this.InputValues.OutputFileName), "Before"), true); } using (IlAsm ilAsm = this.PrepareIlAsm(tempDirectory.Value)) this.RunIlAsm(ilAsm); if (!flag) { return; } using (this.GetNotifier().CreateContextName((object)this, Resources.CopyAfterContextName)) DllExportWeaver.CopyDirectory(tempDirectory.Value, Path.Combine(Path.GetDirectoryName(this.InputValues.OutputFileName), "After"), true); } } }
private void RunIlAsm(IlAsm ilAsm) { using (GetNotifier().CreateContextName(this, "RunIlAsm")) { if (InputValues.Cpu != CpuPlatform.AnyCpu) { reassembleFile(ilAsm, InputValues.OutputFileName, "", InputValues.Cpu); return; } string dir = Path.GetDirectoryName(InputValues.OutputFileName) ?? ""; string fileName = Path.GetFileName(InputValues.OutputFileName); if (!Directory.Exists(dir)) { throw new DirectoryNotFoundException(String.Format(Resources.Directory_0_does_not_exist, dir)); } reassembleFile(ilAsm, Path.Combine(Path.Combine(dir, "x86"), fileName), ".x86", CpuPlatform.X86); reassembleFile(ilAsm, Path.Combine(Path.Combine(dir, "x64"), fileName), ".x64", CpuPlatform.X64); } }
private void RunIlAsm(IlAsm ilAsm) { using (this.GetNotifier().CreateContextName((object)this, "RunIlAsm")) { if (this.InputValues.Cpu == CpuPlatform.AnyCpu) { string str = Path.GetDirectoryName(this.InputValues.OutputFileName) ?? ""; string fileName = Path.GetFileName(this.InputValues.OutputFileName); if (!Directory.Exists(str)) { throw new DirectoryNotFoundException(string.Format(Resources.Directory_0_does_not_exist, (object)str)); } this.GetNotifier().Notify(1, DllExportLogginCodes.CreatingBinariesForEachPlatform, Resources.Platform_is_0_creating_binaries_for_each_CPU_platform_in_a_separate_subfolder, (object)this.InputValues.Cpu); ilAsm.ReassembleFile(Path.Combine(Path.Combine(str, "x86"), fileName), ".x86", CpuPlatform.X86); ilAsm.ReassembleFile(Path.Combine(Path.Combine(str, "x64"), fileName), ".x64", CpuPlatform.X64); } else { ilAsm.ReassembleFile(this.InputValues.OutputFileName, "", this.InputValues.Cpu); } } }