Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 18 additions & 16 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down