void PatchResources() { ManifestResourceTable resourceTable = (ManifestResourceTable)stripped_tables [ManifestResourceTable.RId]; if (resourceTable == null) { return; } for (int i = 0; i < resourceTable.Rows.Count; i++) { ManifestResourceRow resourceRow = resourceTable [i]; if (resourceRow.Implementation.RID != 0) { continue; } foreach (Resource resource in assembly.MainModule.Resources) { EmbeddedResource er = resource as EmbeddedResource; if (er == null) { continue; } if (resource.Name != original.MetadataRoot.Streams.StringsHeap [resourceRow.Name]) { continue; } resourceRow.Offset = metadata_writer.AddResource(er.Data); } } }
void AddManifestResource(uint offset, string name, ManifestResourceAttributes flags, MetadataToken impl) { ManifestResourceTable mrTable = m_tableWriter.GetManifestResourceTable(); ManifestResourceRow mrRow = m_rowWriter.CreateManifestResourceRow( offset, flags, m_mdWriter.AddString(name), impl); mrTable.Rows.Add(mrRow); }
public override void VisitResourceCollection(ResourceCollection resources) { if (!m_tHeap.HasTable(ManifestResourceTable.RId)) { return; } ManifestResourceTable mrTable = m_tableReader.GetManifestResourceTable(); FileTable fTable = m_tableReader.GetFileTable(); BinaryReader br; for (int i = 0; i < mrTable.Rows.Count; i++) { ManifestResourceRow mrRow = mrTable [i]; if (mrRow.Implementation.RID == 0) { EmbeddedResource eres = new EmbeddedResource( ReadString(mrRow.Name), mrRow.Flags); br = m_ir.MetadataReader.GetDataReader( m_img.CLIHeader.Resources.VirtualAddress); br.BaseStream.Position += mrRow.Offset; eres.Data = br.ReadBytes(br.ReadInt32()); resources.Add(eres); continue; } switch (mrRow.Implementation.TokenType) { case TokenType.File: FileRow fRow = fTable [(int)mrRow.Implementation.RID - 1]; LinkedResource lres = new LinkedResource( ReadString(mrRow.Name), mrRow.Flags, ReadString(fRow.Name)); lres.Hash = ReadBlob(fRow.HashValue); resources.Add(lres); break; case TokenType.AssemblyRef: AssemblyNameReference asm = m_module.AssemblyReferences [(int)mrRow.Implementation.RID - 1]; AssemblyLinkedResource alr = new AssemblyLinkedResource( ReadString(mrRow.Name), mrRow.Flags, asm); resources.Add(alr); break; } } }