void PatchMethods() { MethodTable methodTable = (MethodTable)stripped_tables [MethodTable.RId]; if (methodTable == null) { return; } RVA method_rva = RVA.Zero; for (int i = 0; i < methodTable.Rows.Count; i++) { MethodRow methodRow = methodTable[i]; methodRow.ImplFlags |= MethodImplAttributes.NoInlining; MetadataToken methodToken = MetadataToken.FromMetadataRow(TokenType.Method, i); MethodDefinition method = (MethodDefinition)assembly.MainModule.LookupByToken(methodToken); if (method.HasBody) { method_rva = method_rva != RVA.Zero ? method_rva : reflection_writer.CodeWriter.WriteMethodBody(method); methodRow.RVA = method_rva; } else { methodRow.RVA = RVA.Zero; } } }
void ReadProperties() { if (!m_tHeap.HasTable(PropertyTable.RId)) { m_properties = new PropertyDefinition [0]; return; } PropertyTable propsTable = m_tableReader.GetPropertyTable(); PropertyMapTable pmapTable = m_tableReader.GetPropertyMapTable(); m_properties = new PropertyDefinition [propsTable.Rows.Count]; for (int i = 0; i < pmapTable.Rows.Count; i++) { PropertyMapRow pmapRow = pmapTable [i]; if (pmapRow.Parent == 0) { continue; } TypeDefinition owner = GetTypeDefAt(pmapRow.Parent); GenericContext context = new GenericContext(owner); int start = (int)pmapRow.PropertyList, last = propsTable.Rows.Count + 1, end; if (i < pmapTable.Rows.Count - 1) { end = (int)pmapTable [i + 1].PropertyList; } else { end = last; } if (end > last) { end = last; } for (int j = start; j < end; j++) { PropertyRow prow = propsTable [j - 1]; PropertySig psig = m_sigReader.GetPropSig(prow.Type); PropertyDefinition pdef = new PropertyDefinition( m_root.Streams.StringsHeap [prow.Name], GetTypeRefFromSig(psig.Type, context), prow.Flags); pdef.MetadataToken = MetadataToken.FromMetadataRow(TokenType.Property, j - 1); pdef.PropertyType = GetModifierType(psig.CustomMods, pdef.PropertyType); if (!IsDeleted(pdef)) { owner.Properties.Add(pdef); } m_properties [j - 1] = pdef; } } }
void ReadEvents() { if (!m_tHeap.HasTable(EventTable.RId)) { m_events = new EventDefinition [0]; return; } EventTable evtTable = m_tableReader.GetEventTable(); EventMapTable emapTable = m_tableReader.GetEventMapTable(); m_events = new EventDefinition [evtTable.Rows.Count]; for (int i = 0; i < emapTable.Rows.Count; i++) { EventMapRow emapRow = emapTable [i]; if (emapRow.Parent == 0) { continue; } TypeDefinition owner = GetTypeDefAt(emapRow.Parent); GenericContext context = new GenericContext(owner); int start = (int)emapRow.EventList, last = evtTable.Rows.Count + 1, end; if (i < (emapTable.Rows.Count - 1)) { end = (int)emapTable [i + 1].EventList; } else { end = last; } if (end > last) { end = last; } for (int j = start; j < end; j++) { EventRow erow = evtTable [j - 1]; EventDefinition edef = new EventDefinition( m_root.Streams.StringsHeap [erow.Name], GetTypeDefOrRef(erow.EventType, context), erow.EventFlags); edef.MetadataToken = MetadataToken.FromMetadataRow(TokenType.Event, j - 1); if (!IsDeleted(edef)) { owner.Events.Add(edef); } m_events [j - 1] = edef; } } }
public override void VisitModuleReferenceCollection(ModuleReferenceCollection modules) { if (!m_tHeap.HasTable(ModuleRefTable.RId)) { return; } ModuleRefTable mrTable = m_tableReader.GetModuleRefTable(); for (int i = 0; i < mrTable.Rows.Count; i++) { ModuleRefRow mrRow = mrTable [i]; ModuleReference mod = new ModuleReference(ReadString(mrRow.Name)); mod.MetadataToken = MetadataToken.FromMetadataRow(TokenType.ModuleRef, i); modules.Add(mod); } }