mirror of https://github.com/dotnet/runtime
Fix PEReader creation and caching (#1742)
Can't use a fixed stack-based pointer to initialize something on the heap and expect it to continue working :)
This commit is contained in:
parent
27b1f2c81b
commit
eb8244be5e
|
@ -2,18 +2,19 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using ILCompiler.Reflection.ReadyToRun;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.Collections.Immutable;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ILCompiler.Reflection.ReadyToRun;
|
||||
|
||||
namespace R2RDump
|
||||
{
|
||||
|
@ -90,12 +91,9 @@ namespace R2RDump
|
|||
|
||||
private static unsafe MetadataReader Open(string filename)
|
||||
{
|
||||
byte[] Image = File.ReadAllBytes(filename);
|
||||
byte[] image = File.ReadAllBytes(filename);
|
||||
|
||||
fixed (byte* p = Image)
|
||||
{
|
||||
IntPtr ptr = (IntPtr)p;
|
||||
PEReader peReader = new PEReader(p, Image.Length);
|
||||
PEReader peReader = new PEReader(Unsafe.As<byte[], ImmutableArray<byte>>(ref image));
|
||||
|
||||
if (!peReader.HasMetadata)
|
||||
{
|
||||
|
@ -105,7 +103,6 @@ namespace R2RDump
|
|||
return peReader.GetMetadataReader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Dumper
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue