|
|
|
@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy
@@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
{ |
|
|
|
|
this.assemblyList = assemblyList ?? throw new ArgumentNullException(nameof(assemblyList)); |
|
|
|
|
this.fileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.assemblyTask = Task.Factory.StartNew(LoadAssembly, stream); // requires that this.fileName is set
|
|
|
|
|
this.shortName = Path.GetFileNameWithoutExtension(fileName); |
|
|
|
|
} |
|
|
|
@ -145,20 +145,23 @@ namespace ICSharpCode.ILSpy
@@ -145,20 +145,23 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
|
|
|
|
|
PEFile LoadAssembly(object state) |
|
|
|
|
{ |
|
|
|
|
var stream = state as Stream; |
|
|
|
|
PEFile module; |
|
|
|
|
MetadataReaderOptions options; |
|
|
|
|
if (DecompilerSettingsPanel.CurrentDecompilerSettings.ApplyWindowsRuntimeProjections) { |
|
|
|
|
options = MetadataReaderOptions.ApplyWindowsRuntimeProjections; |
|
|
|
|
} else { |
|
|
|
|
options = MetadataReaderOptions.None; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PEFile module; |
|
|
|
|
// runs on background thread
|
|
|
|
|
if (stream != null) |
|
|
|
|
{ |
|
|
|
|
if (state is Stream stream) { |
|
|
|
|
// Read the module from a precrafted stream
|
|
|
|
|
module = new PEFile(fileName, stream, metadataOptions: DecompilerSettingsPanel.CurrentDecompilerSettings.ApplyWindowsRuntimeProjections ? MetadataReaderOptions.ApplyWindowsRuntimeProjections : MetadataReaderOptions.None); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
module = new PEFile(fileName, stream, metadataOptions: options); |
|
|
|
|
} else { |
|
|
|
|
// Read the module from disk (by default)
|
|
|
|
|
module = new PEFile(fileName, new FileStream(fileName, FileMode.Open, FileAccess.Read), PEStreamOptions.PrefetchEntireImage, |
|
|
|
|
metadataOptions: DecompilerSettingsPanel.CurrentDecompilerSettings.ApplyWindowsRuntimeProjections ? MetadataReaderOptions.ApplyWindowsRuntimeProjections : MetadataReaderOptions.None); |
|
|
|
|
stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); |
|
|
|
|
module = new PEFile(fileName, stream, PEStreamOptions.PrefetchEntireImage, |
|
|
|
|
metadataOptions: options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (DecompilerSettingsPanel.CurrentDecompilerSettings.UseDebugSymbols) { |
|
|
|
@ -175,7 +178,7 @@ namespace ICSharpCode.ILSpy
@@ -175,7 +178,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
} |
|
|
|
|
return module; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LoadSymbols(PEFile module) |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
@ -242,17 +245,17 @@ namespace ICSharpCode.ILSpy
@@ -242,17 +245,17 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
|
|
|
|
|
[ThreadStatic] |
|
|
|
|
static int assemblyLoadDisableCount; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static IDisposable DisableAssemblyLoad() |
|
|
|
|
{ |
|
|
|
|
assemblyLoadDisableCount++; |
|
|
|
|
return new DecrementAssemblyLoadDisableCount(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sealed class DecrementAssemblyLoadDisableCount : IDisposable |
|
|
|
|
{ |
|
|
|
|
bool disposed; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
if (!disposed) { |
|
|
|
@ -263,16 +266,16 @@ namespace ICSharpCode.ILSpy
@@ -263,16 +266,16 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sealed class MyAssemblyResolver : IAssemblyResolver |
|
|
|
|
{ |
|
|
|
|
readonly LoadedAssembly parent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MyAssemblyResolver(LoadedAssembly parent) |
|
|
|
|
{ |
|
|
|
|
this.parent = parent; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PEFile Resolve(Decompiler.Metadata.IAssemblyReference reference) |
|
|
|
|
{ |
|
|
|
|
return parent.LookupReferencedAssembly(reference)?.GetPEFileOrNull(); |
|
|
|
@ -283,7 +286,7 @@ namespace ICSharpCode.ILSpy
@@ -283,7 +286,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
return parent.LookupReferencedModule(mainModule, moduleName)?.GetPEFileOrNull(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IAssemblyResolver GetAssemblyResolver() |
|
|
|
|
{ |
|
|
|
|
return new MyAssemblyResolver(this); |
|
|
|
@ -298,7 +301,7 @@ namespace ICSharpCode.ILSpy
@@ -298,7 +301,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
return null; |
|
|
|
|
return debugInfoProvider; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LoadedAssembly LookupReferencedAssembly(Decompiler.Metadata.IAssemblyReference reference) |
|
|
|
|
{ |
|
|
|
|
if (reference == null) |
|
|
|
@ -371,7 +374,7 @@ namespace ICSharpCode.ILSpy
@@ -371,7 +374,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
} |
|
|
|
|
loadingAssemblies.Add(file, asm); |
|
|
|
|
} |
|
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)delegate() { |
|
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)delegate () { |
|
|
|
|
lock (assemblyList.assemblies) { |
|
|
|
|
assemblyList.assemblies.Add(asm); |
|
|
|
|
} |
|
|
|
@ -437,7 +440,7 @@ namespace ICSharpCode.ILSpy
@@ -437,7 +440,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
{ |
|
|
|
|
return this.assemblyTask.ContinueWith(onAssemblyLoaded, default(CancellationToken), TaskContinuationOptions.RunContinuationsAsynchronously, taskScheduler); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wait until the assembly is loaded.
|
|
|
|
|
/// Throws an AggregateException when loading the assembly fails.
|
|
|
|
|