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

72
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -90,8 +90,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
var loadResult = LoadedAssembly.GetLoadResultAsync().Result; var loadResult = LoadedAssembly.GetLoadResultAsync().Result;
if (loadResult.Package != null) if (loadResult.Package != null)
{ {
return loadResult.Package.Kind switch return loadResult.Package.Kind switch {
{
LoadedPackage.PackageKind.Zip => Images.NuGet, LoadedPackage.PackageKind.Zip => Images.NuGet,
_ => Images.Library, _ => Images.Library,
}; };
@ -316,30 +315,57 @@ namespace ICSharpCode.ILSpy.TreeNodes
try try
{ {
LoadedAssembly.WaitUntilLoaded(); // necessary so that load errors are passed on to the caller var loadResult = LoadedAssembly.GetLoadResultAsync().GetAwaiter().GetResult();
} if (loadResult.PEFile != null)
catch (AggregateException ex) {
{ language.DecompileAssembly(LoadedAssembly, output, options);
language.WriteCommentLine(output, LoadedAssembly.FileName); }
switch (ex.InnerException) else if (loadResult.Package != null)
{
output.WriteLine("// " + LoadedAssembly.FileName);
DecompilePackage(loadResult.Package, output);
}
else
{ {
case BadImageFormatException badImage: LoadedAssembly.GetPEFileOrNullAsync().GetAwaiter().GetResult();
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;
} }
} }
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) public override bool Save(TabPageModel tabPage)

Loading…
Cancel
Save