Browse Source

Avoid copying resources into managed memory.

pull/1030/head
Daniel Grunwald 7 years ago
parent
commit
b4dd917949
  1. 22
      ICSharpCode.Decompiler/Metadata/Dom.cs
  2. 3
      ILSpy/Controls/ResourceObjectTable.xaml
  3. 2
      ILSpy/Controls/ResourceStringTable.xaml

22
ICSharpCode.Decompiler/Metadata/Dom.cs

@ -86,17 +86,25 @@ namespace ICSharpCode.Decompiler.Metadata @@ -86,17 +86,25 @@ namespace ICSharpCode.Decompiler.Metadata
return null;
var headers = Module.Reader.PEHeaders;
var resources = headers.CorHeader.ResourcesDirectory;
int index = headers.GetContainingSectionIndex(resources.RelativeVirtualAddress);
if (index < 0)
var sectionData = Module.Reader.GetSectionData(resources.RelativeVirtualAddress);
if (sectionData.Length == 0)
throw new BadImageFormatException("RVA could not be found in any section!");
var sectionHeader = headers.SectionHeaders[index];
var sectionData = Module.Reader.GetEntireImage();
int totalOffset = resources.RelativeVirtualAddress + sectionHeader.PointerToRawData - sectionHeader.VirtualAddress;
var reader = sectionData.GetReader();
reader.Offset += totalOffset;
reader.Offset += (int)This().Offset;
int length = reader.ReadInt32();
return new MemoryStream(reader.ReadBytes(length));
return new ResourceMemoryStream(Module.Reader, reader.CurrentPointer, length);
}
}
sealed unsafe class ResourceMemoryStream : UnmanagedMemoryStream
{
readonly PEReader peReader;
public ResourceMemoryStream(PEReader peReader, byte* data, long length)
: base(data, length, length, FileAccess.Read)
{
// Keep the PEReader alive while the stream in in use.
this.peReader = peReader;
}
}

3
ILSpy/Controls/ResourceObjectTable.xaml

@ -1,7 +1,8 @@ @@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<UserControl x:Class="ICSharpCode.ILSpy.Controls.ResourceObjectTable"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Cursor="Arrow">
<UserControl.CommandBindings>
<CommandBinding Command="ApplicationCommands.Copy"
Executed="ExecuteCopy"

2
ILSpy/Controls/ResourceStringTable.xaml

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<UserControl x:Class="ICSharpCode.ILSpy.Controls.ResourceStringTable"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
Cursor="Arrow">
<UserControl.CommandBindings>
<CommandBinding Command="ApplicationCommands.Copy"
Executed="ExecuteCopy"

Loading…
Cancel
Save