Browse Source

Update to Mono.Cecil 0.9.5-95-g9f3c0f8.

This fixes a crash when opening a portable library project targeting .NET 4.5. (jbevain/cecil#101)
pull/28/head
Daniel Grunwald 13 years ago
parent
commit
49248ddb98
  1. 1
      src/Libraries/Mono.Cecil/Mono.Cecil.PE/Image.cs
  2. 10
      src/Libraries/Mono.Cecil/Mono.Cecil.PE/ImageReader.cs
  3. 25
      src/Libraries/Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs
  4. 11
      src/Libraries/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs
  5. 8
      src/Libraries/Mono.Cecil/Mono.Cecil/AssemblyReader.cs
  6. 1
      src/Libraries/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs
  7. 1
      src/Libraries/Mono.Cecil/Mono.Cecil/GenericParameter.cs
  8. 5
      src/Libraries/Mono.Cecil/Mono.Cecil/MetadataSystem.cs
  9. 8
      src/Libraries/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs
  10. 10
      src/Libraries/Mono.Cecil/Mono.Cecil/ModuleKind.cs
  11. 2
      src/Libraries/Mono.Cecil/Mono.Cecil/TypeParser.cs
  12. 9
      src/Libraries/Mono.Cecil/Mono.Cecil/TypeReference.cs
  13. 5
      src/Libraries/Mono.Cecil/Mono.Cecil/TypeSpecification.cs
  14. 31
      src/Libraries/Mono.Cecil/Mono.Cecil/TypeSystem.cs

1
src/Libraries/Mono.Cecil/Mono.Cecil.PE/Image.cs

@ -41,6 +41,7 @@ namespace Mono.Cecil.PE { @@ -41,6 +41,7 @@ namespace Mono.Cecil.PE {
public ModuleKind Kind;
public TargetRuntime Runtime;
public TargetArchitecture Architecture;
public ModuleCharacteristics Characteristics;
public string FileName;
public Section [] Sections;

10
src/Libraries/Mono.Cecil/Mono.Cecil.PE/ImageReader.cs

@ -99,13 +99,14 @@ namespace Mono.Cecil.PE { @@ -99,13 +99,14 @@ namespace Mono.Cecil.PE {
// Characteristics 2
ushort characteristics = ReadUInt16 ();
ushort subsystem;
ReadOptionalHeaders (out subsystem);
ushort subsystem, dll_characteristics;
ReadOptionalHeaders (out subsystem, out dll_characteristics);
ReadSections (sections);
ReadCLIHeader ();
ReadMetadata ();
image.Kind = GetModuleKind (characteristics, subsystem);
image.Characteristics = (ModuleCharacteristics) dll_characteristics;
}
TargetArchitecture ReadArchitecture ()
@ -136,7 +137,7 @@ namespace Mono.Cecil.PE { @@ -136,7 +137,7 @@ namespace Mono.Cecil.PE {
return ModuleKind.Console;
}
void ReadOptionalHeaders (out ushort subsystem)
void ReadOptionalHeaders (out ushort subsystem, out ushort dll_characteristics)
{
// - PEOptionalHeader
// - StandardFieldsHeader
@ -176,6 +177,7 @@ namespace Mono.Cecil.PE { @@ -176,6 +177,7 @@ namespace Mono.Cecil.PE {
subsystem = ReadUInt16 ();
// DLLFlags 2
dll_characteristics = ReadUInt16 ();
// StackReserveSize 4 || 8
// StackCommitSize 4 || 8
// HeapReserveSize 4 || 8
@ -192,7 +194,7 @@ namespace Mono.Cecil.PE { @@ -192,7 +194,7 @@ namespace Mono.Cecil.PE {
// CertificateTable 8
// BaseRelocationTable 8
Advance (pe64 ? 90 : 74);
Advance (pe64 ? 88 : 72);
// Debug 8
image.Debug = ReadDataDirectory ();

25
src/Libraries/Mono.Cecil/Mono.Cecil.PE/ImageWriter.cs

@ -235,7 +235,7 @@ namespace Mono.Cecil.PE { @@ -235,7 +235,7 @@ namespace Mono.Cecil.PE {
WriteByte (8); // LMajor
WriteByte (0); // LMinor
WriteUInt32 (text.SizeOfRawData); // CodeSize
WriteUInt32 (reloc != null ? reloc.SizeOfRawData : 0
WriteUInt32 ((reloc != null ? reloc.SizeOfRawData : 0)
+ (rsrc != null ? rsrc.SizeOfRawData : 0)); // InitializedDataSize
WriteUInt32 (0); // UninitializedDataSize
@ -267,7 +267,7 @@ namespace Mono.Cecil.PE { @@ -267,7 +267,7 @@ namespace Mono.Cecil.PE {
WriteUInt32 (0); // Checksum
WriteUInt16 (GetSubSystem ()); // SubSystem
WriteUInt16 (0x8540); // DLLFlags
WriteUInt16 ((ushort) module.Characteristics); // DLLFlags
const ulong stack_reserve = 0x100000;
const ulong stack_commit = 0x1000;
@ -754,17 +754,18 @@ namespace Mono.Cecil.PE { @@ -754,17 +754,18 @@ namespace Mono.Cecil.PE {
return 0;
var public_key = module.Assembly.Name.PublicKey;
if (public_key.IsNullOrEmpty ())
return 0;
if (public_key != null) {
// in fx 2.0 the key may be from 384 to 16384 bits
// so we must calculate the signature size based on
// the size of the public key (minus the 32 byte header)
int size = public_key.Length;
if (size > 32)
return size - 32;
// note: size == 16 for the ECMA "key" which is replaced
// by the runtime with a 1024 bits key (128 bytes)
}
// in fx 2.0 the key may be from 384 to 16384 bits
// so we must calculate the signature size based on
// the size of the public key (minus the 32 byte header)
int size = public_key.Length;
if (size > 32)
return size - 32;
// note: size == 16 for the ECMA "key" which is replaced
// by the runtime with a 1024 bits key (128 bytes)
return 128; // default strongname signature size
}

11
src/Libraries/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs

@ -98,7 +98,7 @@ namespace Mono.Cecil { @@ -98,7 +98,7 @@ namespace Mono.Cecil {
}
public byte [] PublicKey {
get { return public_key; }
get { return public_key ?? Empty<byte>.Array; }
set {
public_key = value;
HasPublicKey = !public_key.IsNullOrEmpty ();
@ -116,7 +116,7 @@ namespace Mono.Cecil { @@ -116,7 +116,7 @@ namespace Mono.Cecil {
Array.Copy (hash, (hash.Length - 8), public_key_token, 0, 8);
Array.Reverse (public_key_token, 0, 8);
}
return public_key_token;
return public_key_token ?? Empty<byte>.Array;
}
set {
public_key_token = value;
@ -175,9 +175,10 @@ namespace Mono.Cecil { @@ -175,9 +175,10 @@ namespace Mono.Cecil {
builder.Append (sep);
builder.Append ("PublicKeyToken=");
if (this.PublicKeyToken != null && public_key_token.Length > 0) {
for (int i = 0 ; i < public_key_token.Length ; i++) {
builder.Append (public_key_token [i].ToString ("x2"));
var pk_token = PublicKeyToken;
if (!pk_token.IsNullOrEmpty () && pk_token.Length > 0) {
for (int i = 0 ; i < pk_token.Length ; i++) {
builder.Append (pk_token [i].ToString ("x2"));
}
} else
builder.Append ("null");

8
src/Libraries/Mono.Cecil/Mono.Cecil/AssemblyReader.cs

@ -778,8 +778,12 @@ namespace Mono.Cecil { @@ -778,8 +778,12 @@ namespace Mono.Cecil {
var nested_types = new MemberDefinitionCollection<TypeDefinition> (type, mapping.Length);
for (int i = 0; i < mapping.Length; i++)
nested_types.Add (GetTypeDefinition (mapping [i]));
for (int i = 0; i < mapping.Length; i++) {
var nested_type = GetTypeDefinition (mapping [i]);
if (nested_type != null)
nested_types.Add (nested_type);
}
metadata.RemoveNestedTypeMapping (type);

1
src/Libraries/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs

@ -85,6 +85,7 @@ namespace Mono.Cecil { @@ -85,6 +85,7 @@ namespace Mono.Cecil {
public override IMetadataScope Scope {
get { return function.ReturnType.Scope; }
set { throw new InvalidOperationException (); }
}
public override bool IsFunctionPointer {

1
src/Libraries/Mono.Cecil/Mono.Cecil/GenericParameter.cs

@ -107,6 +107,7 @@ namespace Mono.Cecil { @@ -107,6 +107,7 @@ namespace Mono.Cecil {
? ((MethodReference) owner).DeclaringType.Scope
: ((TypeReference) owner).Scope;
}
set { throw new InvalidOperationException (); }
}
public override ModuleDefinition Module {

5
src/Libraries/Mono.Cecil/Mono.Cecil/MetadataSystem.cs

@ -106,7 +106,7 @@ namespace Mono.Cecil { @@ -106,7 +106,7 @@ namespace Mono.Cecil {
return;
var scope = type.scope;
if (scope == null || scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference || scope.Name != "mscorlib")
if (scope == null || scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference)
return;
Row<ElementType, bool> primitive_data;
@ -124,9 +124,6 @@ namespace Mono.Cecil { @@ -124,9 +124,6 @@ namespace Mono.Cecil {
if (type.Namespace != "System")
return false;
if (!type.HasImage || !type.Module.IsCorlib ())
return false;
Row<ElementType, bool> primitive_data;
if (TryGetPrimitiveData (type, out primitive_data) && primitive_data.Col1.IsPrimitive ()) {
etype = primitive_data.Col1;

8
src/Libraries/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs

@ -208,6 +208,7 @@ namespace Mono.Cecil { @@ -208,6 +208,7 @@ namespace Mono.Cecil {
TargetRuntime runtime;
TargetArchitecture architecture;
ModuleAttributes attributes;
ModuleCharacteristics characteristics;
Guid mvid;
internal AssemblyDefinition assembly;
@ -247,6 +248,11 @@ namespace Mono.Cecil { @@ -247,6 +248,11 @@ namespace Mono.Cecil {
set { attributes = value; }
}
public ModuleCharacteristics Characteristics {
get { return characteristics; }
set { characteristics = value; }
}
public string FullyQualifiedName {
get { return fq_name; }
}
@ -442,6 +448,7 @@ namespace Mono.Cecil { @@ -442,6 +448,7 @@ namespace Mono.Cecil {
this.runtime = image.Runtime;
this.architecture = image.Architecture;
this.attributes = image.Attributes;
this.characteristics = image.Characteristics;
this.fq_name = image.FileName;
this.reader = new MetadataReader (this);
@ -866,6 +873,7 @@ namespace Mono.Cecil { @@ -866,6 +873,7 @@ namespace Mono.Cecil {
architecture = parameters.Architecture,
mvid = Guid.NewGuid (),
Attributes = ModuleAttributes.ILOnly,
Characteristics = (ModuleCharacteristics) 0x8540,
};
if (parameters.AssemblyResolver != null)

10
src/Libraries/Mono.Cecil/Mono.Cecil/ModuleKind.cs

@ -51,4 +51,14 @@ namespace Mono.Cecil { @@ -51,4 +51,14 @@ namespace Mono.Cecil {
StrongNameSigned = 8,
Preferred32Bit = 0x00020000,
}
[Flags]
public enum ModuleCharacteristics {
HighEntropyVA = 0x0020,
DynamicBase = 0x0040,
NoSEH = 0x0400,
NXCompat = 0x0100,
AppContainer = 0x1000,
TerminalServerAware = 0x8000,
}
}

2
src/Libraries/Mono.Cecil/Mono.Cecil/TypeParser.cs

@ -272,7 +272,7 @@ namespace Mono.Cecil { @@ -272,7 +272,7 @@ namespace Mono.Cecil {
public static TypeReference ParseType (ModuleDefinition module, string fullname)
{
if (fullname == null)
if (string.IsNullOrEmpty (fullname))
return null;
var parser = new TypeParser (fullname);

9
src/Libraries/Mono.Cecil/Mono.Cecil/TypeReference.cs

@ -147,6 +147,15 @@ namespace Mono.Cecil { @@ -147,6 +147,15 @@ namespace Mono.Cecil {
return scope;
}
set {
var declaring_type = this.DeclaringType;
if (declaring_type != null) {
declaring_type.Scope = value;
return;
}
scope = value;
}
}
public bool IsNested {

5
src/Libraries/Mono.Cecil/Mono.Cecil/TypeSpecification.cs

@ -42,16 +42,17 @@ namespace Mono.Cecil { @@ -42,16 +42,17 @@ namespace Mono.Cecil {
public override string Name {
get { return element_type.Name; }
set { throw new NotSupportedException (); }
set { throw new InvalidOperationException (); }
}
public override string Namespace {
get { return element_type.Namespace; }
set { throw new NotSupportedException (); }
set { throw new InvalidOperationException (); }
}
public override IMetadataScope Scope {
get { return element_type.Scope; }
set { throw new InvalidOperationException (); }
}
public override ModuleDefinition Module {

31
src/Libraries/Mono.Cecil/Mono.Cecil/TypeSystem.cs

@ -34,14 +34,23 @@ namespace Mono.Cecil { @@ -34,14 +34,23 @@ namespace Mono.Cecil {
public abstract class TypeSystem {
sealed class CorlibTypeSystem : TypeSystem {
sealed class CoreTypeSystem : TypeSystem {
public CorlibTypeSystem (ModuleDefinition module)
public CoreTypeSystem (ModuleDefinition module)
: base (module)
{
}
internal override TypeReference LookupType (string @namespace, string name)
{
var type = LookupTypeDefinition (@namespace, name) ?? LookupTypeForwarded (@namespace, name);
if (type != null)
return type;
throw new NotSupportedException ();
}
TypeReference LookupTypeDefinition (string @namespace, string name)
{
var metadata = module.MetadataSystem;
if (metadata.Types == null)
@ -64,6 +73,22 @@ namespace Mono.Cecil { @@ -64,6 +73,22 @@ namespace Mono.Cecil {
});
}
TypeReference LookupTypeForwarded (string @namespace, string name)
{
if (!module.HasExportedTypes)
return null;
var exported_types = module.ExportedTypes;
for (int i = 0; i < exported_types.Count; i++) {
var exported_type = exported_types [i];
if (exported_type.Name == name && exported_type.Namespace == @namespace)
return exported_type.CreateReference ();
}
return null;
}
static void Initialize (object obj)
{
}
@ -159,7 +184,7 @@ namespace Mono.Cecil { @@ -159,7 +184,7 @@ namespace Mono.Cecil {
internal static TypeSystem CreateTypeSystem (ModuleDefinition module)
{
if (module.IsCorlib ())
return new CorlibTypeSystem (module);
return new CoreTypeSystem (module);
return new CommonTypeSystem (module);
}

Loading…
Cancel
Save