Skip to content

Commit 529bf14

Browse files
authored
Fix PE header generator (#16)
1 parent 72d0371 commit 529bf14

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

source/MetadataProcessor.Core/nanoAssemblyDefinition.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ public void Write(
6666
{
6767
// this replicates the original struct CLR_RECORD_ASSEMBLY
6868

69+
// marker
6970
writer.WriteString(c_NFAssemblyMarker_v1);
7071

72+
// need to set position because marker could be shorter
73+
writer.BaseStream.Seek(c_HeaderCrc32Position, SeekOrigin.Begin);
74+
7175
// header CRC32
7276
writer.WriteUInt32(0);
7377

@@ -79,12 +83,7 @@ public void Write(
7983
writer.WriteUInt32(0);
8084

8185
// native methods CRC32
82-
writer.WriteUInt32(writer.IsBigEndian ? _context.NativeMethodsCrc.Current : 0x00);
83-
84-
// the existing MDP seems to have a bug because it's adding an extra byte at this place in the struct
85-
// right between the NativeMethodsChecksum and PatchEntryOffset fields.
86-
//// need this here to pad the structure in order to have a PE exactly as the one being generated now
87-
//writer.WriteByte(0);
86+
writer.WriteUInt32(writer.IsBigEndian ? _context.NativeMethodsCrc.Current : 0);
8887

8988
// Native methods offset
9089
writer.WriteUInt32(0xFFFFFFFF);

0 commit comments

Comments
 (0)