Browse Source

Fix #2295: Don't attempt to decompile bundle; instead show info from bundle header.

pull/2308/head
Daniel Grunwald 4 years ago
parent
commit
fa9351c89f
  1. 5
      ILSpy/LoadedPackage.cs
  2. 72
      ILSpy/TreeNodes/AssemblyTreeNode.cs

5
ILSpy/LoadedPackage.cs

@ -49,6 +49,8 @@ namespace ICSharpCode.ILSpy @@ -49,6 +49,8 @@ namespace ICSharpCode.ILSpy
public PackageKind Kind { get; }
internal SingleFileBundle.Header BundleHeader { get; set; }
/// <summary>
/// List of all entries, including those in sub-directories within the package.
/// </summary>
@ -115,6 +117,7 @@ namespace ICSharpCode.ILSpy @@ -115,6 +117,7 @@ namespace ICSharpCode.ILSpy
var manifest = SingleFileBundle.ReadManifest(view, bundleHeaderOffset);
var entries = manifest.Entries.Select(e => new BundleEntry(fileName, view, e)).ToList();
var result = new LoadedPackage(PackageKind.Bundle, entries);
result.BundleHeader = manifest;
view = null; // don't dispose the view, we're still using it in the bundle entries
return result;
}
@ -210,7 +213,7 @@ namespace ICSharpCode.ILSpy @@ -210,7 +213,7 @@ namespace ICSharpCode.ILSpy
public abstract string FullName { get; }
}
class PackageFolder : IAssemblyResolver
sealed class PackageFolder : IAssemblyResolver
{
/// <summary>
/// Gets the short name of the folder.

72
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -90,8 +90,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -90,8 +90,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
var loadResult = LoadedAssembly.GetLoadResultAsync().Result;
if (loadResult.Package != null)
{
return loadResult.Package.Kind switch
{
return loadResult.Package.Kind switch {
LoadedPackage.PackageKind.Zip => Images.NuGet,
_ => Images.Library,
};
@ -316,30 +315,57 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -316,30 +315,57 @@ namespace ICSharpCode.ILSpy.TreeNodes
try
{
LoadedAssembly.WaitUntilLoaded(); // necessary so that load errors are passed on to the caller
}
catch (AggregateException ex)
{
language.WriteCommentLine(output, LoadedAssembly.FileName);
switch (ex.InnerException)
var loadResult = LoadedAssembly.GetLoadResultAsync().GetAwaiter().GetResult();
if (loadResult.PEFile != null)
{
language.DecompileAssembly(LoadedAssembly, output, options);
}
else if (loadResult.Package != null)
{
output.WriteLine("// " + LoadedAssembly.FileName);
DecompilePackage(loadResult.Package, output);
}
else
{
case BadImageFormatException badImage:
HandleException(badImage, "This file does not contain a managed assembly.");
return;
case FileNotFoundException fileNotFound:
HandleException(fileNotFound, "The file was not found.");
return;
case DirectoryNotFoundException dirNotFound:
HandleException(dirNotFound, "The directory was not found.");
return;
case PEFileNotSupportedException notSupported:
HandleException(notSupported, notSupported.Message);
return;
default:
throw;
LoadedAssembly.GetPEFileOrNullAsync().GetAwaiter().GetResult();
}
}
language.DecompileAssembly(LoadedAssembly, output, options);
catch (BadImageFormatException badImage)
{
HandleException(badImage, "This file does not contain a managed assembly.");
}
catch (FileNotFoundException fileNotFound)
{
HandleException(fileNotFound, "The file was not found.");
}
catch (DirectoryNotFoundException dirNotFound)
{
HandleException(dirNotFound, "The directory was not found.");
}
catch (PEFileNotSupportedException notSupported)
{
HandleException(notSupported, notSupported.Message);
}
}
private void DecompilePackage(LoadedPackage package, ITextOutput output)
{
switch (package.Kind)
{
case LoadedPackage.PackageKind.Zip:
output.WriteLine("// File format: .zip file");
break;
case LoadedPackage.PackageKind.Bundle:
var header = package.BundleHeader;
output.WriteLine($"// File format: .NET bundle {header.MajorVersion}.{header.MinorVersion}");
break;
}
output.WriteLine();
output.WriteLine("Entries:");
foreach (var entry in package.Entries)
{
output.WriteLine(" " + entry.Name);
}
}
public override bool Save(TabPageModel tabPage)

Loading…
Cancel
Save