@@ -22,16 +22,15 @@ open System.Diagnostics.SymbolStore
2222open System.Runtime .InteropServices
2323open System.Runtime .CompilerServices
2424
25+
2526let DateTime1970Jan01 = new DateTime( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind.Utc) (* ECMA Spec (Oct2002), Part II, 24.2.2 PE File Header. *)
2627let absilWriteGetTimeStamp () = ( DateTime.UtcNow - DateTime1970Jan01) .TotalSeconds |> int
2728
28- #if ! FX_ NO_ LINKEDRESOURCES
2929// Force inline, so GetLastWin32Error calls are immediately after interop calls as seen by FxCop under Debug build.
3030let inline ignore _x = ()
3131
3232// Native Resource linking/unlinking
3333type IStream = System.Runtime.InteropServices.ComTypes.IStream
34- #endif
3534
3635let check _action ( hresult ) =
3736 if uint32 hresult >= 0x80000000 ul then
@@ -56,7 +55,6 @@ let bytesToQWord ((b0: byte), (b1: byte), (b2: byte), (b3: byte), (b4: byte), (b
5655let dwToBytes n = [| byte ( n &&& 0xff ) ; byte (( n >>> 8 ) &&& 0xff ) ; byte (( n >>> 16 ) &&& 0xff ) ; byte (( n >>> 24 ) &&& 0xff ) |], 4
5756let wToBytes ( n : int16 ) = [| byte ( n &&& 0xff s) ; byte (( n >>> 8 ) &&& 0xff s) |], 2
5857
59- #if ! FX_ NO_ LINKEDRESOURCES
6058// REVIEW: factor these classes under one hierarchy, use reflection for creation from buffer and toBytes()
6159// Though, everything I'd like to unify is static - metaclasses?
6260type IMAGE_FILE_HEADER ( m : int16 , secs : int16 , tds : int32 , ptst : int32 , nos : int32 , soh : int16 , c : int16 ) =
@@ -572,7 +570,7 @@ type ResFormatNode(tid: int32, nid: int32, lid: int32, dataOffset: int32, pbLink
572570
573571 ! size
574572
575- let linkNativeResources ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
573+ let linkNativeResourcesViaCVTres ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
576574 let nPEFileType = match fileType with X86 -> 0 | X64 -> 2
577575 let mutable tempResFiles : string list = []
578576 let mutable objBytes : byte [] = [||]
@@ -740,6 +738,39 @@ let linkNativeResources (unlinkedResources: byte[] list) (ulLinkedResourceBaseR
740738 // return the buffer
741739 pResBuffer
742740
741+ let linkNativeResourcesManaged ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
742+ ignore fileType
743+ ignore outputFilePath
744+
745+ let resources =
746+ unlinkedResources
747+ |> Seq.map ( fun s -> new MemoryStream( s))
748+ |> Seq.map ( fun s ->
749+ let res = CVTres.CvtResFile.ReadResFile s
750+ s.Dispose()
751+ res)
752+ |> Seq.collect id
753+ // See MakeWin32ResourceList https://github.com/dotnet/roslyn/blob/f40b89234db51da1e1153c14af184e618504be41/src/Compilers/Core/Portable/Compilation/Compilation.cs
754+ |> Seq.map ( fun r ->
755+ WriteNativeRes.Win32Resource( data = r.data, codePage = 0 u, languageId = uint32 r.LanguageId,
756+ id = int ( int16 r.pstringName.Ordinal), name = r.pstringName.theString,
757+ typeId = int ( int16 r.pstringType.Ordinal), typeName = r.pstringType.theString))
758+ let bb = new System.Reflection.Metadata.BlobBuilder()
759+ WriteNativeRes.NativeResourceWriter.SerializeWin32Resources( bb, resources, ulLinkedResourceBaseRVA)
760+ bb.ToArray()
761+
762+ let linkNativeResources ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
763+ #if ENABLE_ MONO_ SUPPORT
764+ if IL.runningOnMono then
765+ linkNativeResourcesManaged unlinkedResources ulLinkedResourceBaseRVA fileType outputFilePath
766+ else
767+ #endif
768+ #if ! FX_ NO_ LINKEDRESOURCES
769+ linkNativeResourcesViaCVTres unlinkedResources ulLinkedResourceBaseRVA fileType outputFilePath
770+ #else
771+ linkNativeResourcesManaged unlinkedResources ulLinkedResourceBaseRVA fileType outputFilePath
772+ #endif
773+
743774let unlinkResource ( ulLinkedResourceBaseRVA : int32 ) ( pbLinkedResource : byte []) =
744775 let mutable nResNodes = 0
745776
@@ -843,7 +874,6 @@ let unlinkResource (ulLinkedResourceBaseRVA: int32) (pbLinkedResource: byte[]) =
843874 resBufferOffset <- resBufferOffset + pResNodes.[ i]. Save( ulLinkedResourceBaseRVA, pbLinkedResource, pResBuffer, resBufferOffset)
844875
845876 pResBuffer
846- #endif
847877
848878#if ! FX_ NO_ PDB_ WRITER
849879// PDB Writing
0 commit comments