Skip to content

Commit

Permalink
Use the same buffer size as SRM
Browse files Browse the repository at this point in the history
  • Loading branch information
jbevain committed Dec 4, 2019
1 parent 7acd667 commit cb4a8c5
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Mono.Cecil.PE/ImageReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,33 @@ void ReadCLIHeader ()
// ManagedNativeHeader 8
}

void ReadMetadata ()
void CopyTo (ref NativeMemory memory)
{
MoveTo (metadata);
var destination = memory.Pointer;
var size = memory.Length;

var buffer = new byte [Math.Min (81920, size)];
while (size > 0) {
int readSize = Math.Min (size, buffer.Length);
int bytesRead = Read (buffer, 0, readSize);

if (bytesRead <= 0 || bytesRead > readSize) {
throw new IOException ();
}

Marshal.Copy (buffer, 0, (IntPtr) destination, bytesRead);

destination += bytesRead;
size -= bytesRead;
}
}

void ReadMetadata ()
{
image.Metadata = new NativeMemory((int)metadata.Size);
var bytes = ReadBytes ((int)metadata.Size);
Marshal.Copy (bytes, 0, (IntPtr)image.Metadata.Pointer, image.Metadata.Length);

MoveTo (metadata);
CopyTo (ref image.Metadata);

var buffer = new PByteBuffer (image.Metadata.Pointer, (uint) image.Metadata.Length);

Expand Down

0 comments on commit cb4a8c5

Please sign in to comment.