diff options
author | jbevain <jbevain@gmail.com> | 2011-04-05 13:26:11 +0400 |
---|---|---|
committer | jbevain <jbevain@gmail.com> | 2011-04-05 13:26:11 +0400 |
commit | be27067ba31a9fd138c24deb446e9ec9647d670b (patch) | |
tree | f17dfa8cc3dc76527907b607ea1c668ef4b591a3 /Mono.Cecil | |
parent | 379737fe9be14b5fa6a868bfb4fe5e8e13395f85 (diff) |
Add support for #- heap
Diffstat (limited to 'Mono.Cecil')
-rw-r--r-- | Mono.Cecil/AssemblyReader.cs | 87 |
1 files changed, 69 insertions, 18 deletions
diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index 83ba814..50b617a 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -1128,14 +1128,19 @@ namespace Mono.Cecil { var fields = new MemberDefinitionCollection<FieldDefinition> (type, (int) fields_range.Length); this.context = type; - MoveTo (Table.Field, fields_range.Start); - for (uint i = 0; i < fields_range.Length; i++) - fields.Add (ReadField (fields_range.Start + i)); + if (!MoveTo (Table.FieldPtr, fields_range.Start)) { + if (!MoveTo (Table.Field, fields_range.Start)) + return fields; + + for (uint i = 0; i < fields_range.Length; i++) + ReadField (fields_range.Start + i, fields); + } else + ReadPointers (Table.FieldPtr, Table.Field, fields_range, fields, ReadField); return fields; } - FieldDefinition ReadField (uint field_rid) + void ReadField (uint field_rid, Collection<FieldDefinition> fields) { var attributes = (FieldAttributes) ReadUInt16 (); var name = ReadString (); @@ -1145,7 +1150,10 @@ namespace Mono.Cecil { field.token = new MetadataToken (TokenType.Field, field_rid); metadata.AddFieldDefinition (field); - return field; + if (IsDeleted (field)) + return; + + fields.Add (field); } void InitializeFields () @@ -1313,18 +1321,24 @@ namespace Mono.Cecil { metadata.RemoveEventsRange (type); - if (range.Length == 0 || !MoveTo (Table.Event, range.Start)) + if (range.Length == 0) return events; this.context = type; - for (uint i = 0; i < range.Length; i++) - events.Add (ReadEvent (range.Start + i)); + if (!MoveTo (Table.EventPtr, range.Start)) { + if (!MoveTo (Table.Event, range.Start)) + return events; + + for (uint i = 0; i < range.Length; i++) + ReadEvent (range.Start + i, events); + } else + ReadPointers (Table.EventPtr, Table.Event, range, events, ReadEvent); return events; } - EventDefinition ReadEvent (uint event_rid) + void ReadEvent (uint event_rid, Collection<EventDefinition> events) { var attributes = (EventAttributes) ReadUInt16 (); var name = ReadString (); @@ -1332,7 +1346,11 @@ namespace Mono.Cecil { var @event = new EventDefinition (name, attributes, event_type); @event.token = new MetadataToken (TokenType.Event, event_rid); - return @event; + + if (IsDeleted (@event)) + return; + + events.Add (@event); } void InitializeEvents () @@ -1380,18 +1398,23 @@ namespace Mono.Cecil { var properties = new MemberDefinitionCollection<PropertyDefinition> (type, (int) range.Length); - if (range.Length == 0 || !MoveTo (Table.Property, range.Start)) + if (range.Length == 0) return properties; this.context = type; - for (uint i = 0; i < range.Length; i++) - properties.Add (ReadProperty (range.Start + i)); + if (!MoveTo (Table.PropertyPtr, range.Start)) { + if (!MoveTo (Table.Property, range.Start)) + return properties; + for (uint i = 0; i < range.Length; i++) + ReadProperty (range.Start + i, properties); + } else + ReadPointers (Table.PropertyPtr, Table.Property, range, properties, ReadProperty); return properties; } - PropertyDefinition ReadProperty (uint property_rid) + void ReadProperty (uint property_rid, Collection<PropertyDefinition> properties) { var attributes = (PropertyAttributes) ReadUInt16 (); var name = ReadString (); @@ -1413,7 +1436,10 @@ namespace Mono.Cecil { property.HasThis = has_this; property.token = new MetadataToken (TokenType.Property, property_rid); - return property; + if (IsDeleted (property)) + return; + + properties.Add (property); } void InitializeProperties () @@ -1582,14 +1608,36 @@ namespace Mono.Cecil { return new MemberDefinitionCollection<MethodDefinition> (type); var methods = new MemberDefinitionCollection<MethodDefinition> (type, (int) methods_range.Length); + if (!MoveTo (Table.MethodPtr, methods_range.Start)) { + if (!MoveTo (Table.Method, methods_range.Start)) + return methods; - MoveTo (Table.Method, methods_range.Start); - for (uint i = 0; i < methods_range.Length; i++) - ReadMethod (methods_range.Start + i, methods); + for (uint i = 0; i < methods_range.Length; i++) + ReadMethod (methods_range.Start + i, methods); + } else + ReadPointers (Table.MethodPtr, Table.Method, methods_range, methods, ReadMethod); return methods; } + void ReadPointers<TMember> (Table ptr, Table table, Range range, Collection<TMember> members, Action<uint, Collection<TMember>> reader) + where TMember : IMemberDefinition + { + for (uint i = 0; i < range.Length; i++) { + MoveTo (ptr, range.Start + i); + + var rid = ReadTableIndex (table); + MoveTo (table, rid); + + reader (rid, members); + } + } + + static bool IsDeleted (IMemberDefinition member) + { + return member.IsSpecialName && member.Name == "_Deleted"; + } + void InitializeMethods () { if (metadata.Methods != null) @@ -1607,6 +1655,9 @@ namespace Mono.Cecil { method.Name = ReadString (); method.token = new MetadataToken (TokenType.Method, method_rid); + if (IsDeleted (method)) + return; + methods.Add (method); // attach method var signature = ReadBlobIndex (); |