Skip to content

Commit 16dc74d

Browse files
committed
Use the same buffer size as SRM
1 parent 7acd667 commit 16dc74d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

Mono.Cecil.PE/ImageReader.cs

+24-4
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,33 @@ void ReadCLIHeader ()
289289
// ManagedNativeHeader 8
290290
}
291291

292-
void ReadMetadata ()
292+
void CopyTo(ref NativeMemory memory)
293293
{
294-
MoveTo (metadata);
294+
var destination = memory.Pointer;
295+
var size = memory.Length;
295296

297+
var buffer = new byte[Math.Min(81920, size)];
298+
while (size > 0) {
299+
int readSize = Math.Min(size, buffer.Length);
300+
int bytesRead = Read(buffer, 0, readSize);
301+
302+
if (bytesRead <= 0 || bytesRead > readSize) {
303+
throw new IOException();
304+
}
305+
306+
Marshal.Copy(buffer, 0, (IntPtr) destination, bytesRead);
307+
308+
destination += bytesRead;
309+
size -= bytesRead;
310+
}
311+
}
312+
313+
void ReadMetadata ()
314+
{
296315
image.Metadata = new NativeMemory((int)metadata.Size);
297-
var bytes = ReadBytes ((int)metadata.Size);
298-
Marshal.Copy (bytes, 0, (IntPtr)image.Metadata.Pointer, image.Metadata.Length);
316+
317+
MoveTo (metadata);
318+
CopyTo (ref image.Metadata);
299319

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

0 commit comments

Comments
 (0)