diff --git a/src/absil/ilread.fs b/src/absil/ilread.fs index 7dc2a49eee1..7a1ea0445ed 100644 --- a/src/absil/ilread.fs +++ b/src/absil/ilread.fs @@ -3231,14 +3231,18 @@ and seekReadManifestResources (ctxt: ILMetadataReader) (mdv: BinaryView) (pectxt let scoref = seekReadImplAsScopeRef ctxt mdv implIdx let location = - match scoref with - | ILScopeRef.Local -> - let start = pectxtEager.anyV2P ("resource", offset + pectxtEager.resourcesAddr) - let resourceLength = seekReadInt32 pevEager start - let offsetOfBytesFromStartOfPhysicalPEFile = start + 4 - ILResourceLocation.LocalIn (ctxt.fileName, offsetOfBytesFromStartOfPhysicalPEFile, resourceLength) - | ILScopeRef.Module mref -> ILResourceLocation.File (mref, offset) - | ILScopeRef.Assembly aref -> ILResourceLocation.Assembly aref + match scoref with + | ILScopeRef.Local -> + let start = pectxtEager.anyV2P ("resource", offset + pectxtEager.resourcesAddr) + let resourceLength = seekReadInt32 pevEager start + let offsetOfBytesFromStartOfPhysicalPEFile = start + 4 + if pectxtEager.noFileOnDisk then + ILResourceLocation.LocalOut (seekReadBytes pevEager offsetOfBytesFromStartOfPhysicalPEFile resourceLength) + else + ILResourceLocation.LocalIn (ctxt.fileName, offsetOfBytesFromStartOfPhysicalPEFile, resourceLength) + + | ILScopeRef.Module mref -> ILResourceLocation.File (mref, offset) + | ILScopeRef.Assembly aref -> ILResourceLocation.Assembly aref let r = { Name= readStringHeap ctxt nameIdx diff --git a/src/absil/ilwrite.fs b/src/absil/ilwrite.fs index 00aacad5e18..1a536756a89 100644 --- a/src/absil/ilwrite.fs +++ b/src/absil/ilwrite.fs @@ -2682,22 +2682,24 @@ and GenEventPass3 cenv env (md: ILEventDef) = let rec GetResourceAsManifestResourceRow cenv r = let data, impl = - match r.Location with - | ILResourceLocation.LocalIn _ - | ILResourceLocation.LocalOut _ -> - let bytes = r.GetBytes() - // Embedded managed resources must be word-aligned. However resource format is - // not specified in ECMA. Some mscorlib resources appear to be non-aligned - it seems it doesn't matter.. - let offset = cenv.resources.Position - let alignedOffset = (align 0x8 offset) - let pad = alignedOffset - offset - let resourceSize = bytes.Length - cenv.resources.EmitPadding pad - cenv.resources.EmitInt32 resourceSize - cenv.resources.EmitBytes bytes - Data (alignedOffset, true), (i_File, 0) - | ILResourceLocation.File (mref, offset) -> ULong offset, (i_File, GetModuleRefAsFileIdx cenv mref) - | ILResourceLocation.Assembly aref -> ULong 0x0, (i_AssemblyRef, GetAssemblyRefAsIdx cenv aref) + let embedManagedResources (bytes:byte[]) = + // Embedded managed resources must be word-aligned. However resource format is + // not specified in ECMA. Some mscorlib resources appear to be non-aligned - it seems it doesn't matter.. + let offset = cenv.resources.Position + let alignedOffset = (align 0x8 offset) + let pad = alignedOffset - offset + let resourceSize = bytes.Length + cenv.resources.EmitPadding pad + cenv.resources.EmitInt32 resourceSize + cenv.resources.EmitBytes bytes + Data (alignedOffset, true), (i_File, 0) + + match r.Location with + | ILResourceLocation.LocalIn _ -> embedManagedResources (r.GetBytes()) + | ILResourceLocation.LocalOut bytes -> embedManagedResources bytes + | ILResourceLocation.File (mref, offset) -> ULong offset, (i_File, GetModuleRefAsFileIdx cenv mref) + | ILResourceLocation.Assembly aref -> ULong 0x0, (i_AssemblyRef, GetAssemblyRefAsIdx cenv aref) + UnsharedRow [| data ULong (match r.Access with ILResourceAccess.Public -> 0x01 | ILResourceAccess.Private -> 0x02)