зеркало из https://github.com/mono/ikvm-fork.git
Fixed metadata header to account for the actual ImageRuntimeVersion string length, instead of assuming it to be "v2.0.50727".
This commit is contained in:
Родитель
ee0e906e21
Коммит
6e313c7ae3
|
@ -709,11 +709,42 @@ namespace IKVM.Reflection.Emit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetHeaderLength()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
4 + // Signature
|
||||||
|
2 + // MajorVersion
|
||||||
|
2 + // MinorVersion
|
||||||
|
4 + // Reserved
|
||||||
|
4 + // ImageRuntimeVersion Length
|
||||||
|
StringToPaddedUTF8Length(asm.ImageRuntimeVersion) +
|
||||||
|
2 + // Flags
|
||||||
|
2 + // Streams
|
||||||
|
4 + // #~ Offset
|
||||||
|
4 + // #~ Size
|
||||||
|
4 + // StringToPaddedUTF8Length("#~")
|
||||||
|
4 + // #Strings Offset
|
||||||
|
4 + // #Strings Size
|
||||||
|
12 + // StringToPaddedUTF8Length("#Strings")
|
||||||
|
4 + // #US Offset
|
||||||
|
4 + // #US Size
|
||||||
|
4 + // StringToPaddedUTF8Length("#US")
|
||||||
|
4 + // #GUID Offset
|
||||||
|
4 + // #GUID Size
|
||||||
|
8 + // StringToPaddedUTF8Length("#GUID")
|
||||||
|
(Blobs.IsEmpty ? 0 :
|
||||||
|
(
|
||||||
|
4 + // #Blob Offset
|
||||||
|
4 + // #Blob Size
|
||||||
|
8 // StringToPaddedUTF8Length("#Blob")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
internal int MetadataLength
|
internal int MetadataLength
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return (Blobs.IsEmpty ? 92 : 108 + Blobs.Length) + Tables.Length + Strings.Length + UserStrings.Length + Guids.Length;
|
return GetHeaderLength() + (Blobs.IsEmpty ? 0 : Blobs.Length) + Tables.Length + Strings.Length + UserStrings.Length + Guids.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,19 +758,18 @@ namespace IKVM.Reflection.Emit
|
||||||
mw.Write(version.Length); // Length
|
mw.Write(version.Length); // Length
|
||||||
mw.Write(version);
|
mw.Write(version);
|
||||||
mw.Write((ushort)0); // Flags
|
mw.Write((ushort)0); // Flags
|
||||||
int offset;
|
|
||||||
// #Blob is the only optional heap
|
// #Blob is the only optional heap
|
||||||
if (Blobs.IsEmpty)
|
if (Blobs.IsEmpty)
|
||||||
{
|
{
|
||||||
mw.Write((ushort)4); // Streams
|
mw.Write((ushort)4); // Streams
|
||||||
offset = 92;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mw.Write((ushort)5); // Streams
|
mw.Write((ushort)5); // Streams
|
||||||
offset = 108;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int offset = GetHeaderLength();
|
||||||
|
|
||||||
// Streams
|
// Streams
|
||||||
mw.Write(offset); // Offset
|
mw.Write(offset); // Offset
|
||||||
mw.Write(Tables.Length); // Size
|
mw.Write(Tables.Length); // Size
|
||||||
|
@ -778,6 +808,11 @@ namespace IKVM.Reflection.Emit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int StringToPaddedUTF8Length(string str)
|
||||||
|
{
|
||||||
|
return (System.Text.Encoding.UTF8.GetByteCount(str) + 4) & ~3;
|
||||||
|
}
|
||||||
|
|
||||||
private static byte[] StringToPaddedUTF8(string str)
|
private static byte[] StringToPaddedUTF8(string str)
|
||||||
{
|
{
|
||||||
byte[] buf = new byte[(System.Text.Encoding.UTF8.GetByteCount(str) + 4) & ~3];
|
byte[] buf = new byte[(System.Text.Encoding.UTF8.GetByteCount(str) + 4) & ~3];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче