@@ -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 ) =
@@ -583,7 +581,7 @@ type ResFormatNode(tid: int32, nid: int32, lid: int32, dataOffset: int32, pbLink
583581
584582 ! size
585583
586- let linkNativeResources ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
584+ let linkNativeResourcesViaCVTres ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
587585 let nPEFileType = match fileType with X86 -> 0 | X64 -> 2
588586 let mutable tempResFiles : string list = []
589587 let mutable objBytes : byte [] = [||]
@@ -751,6 +749,39 @@ let linkNativeResources (unlinkedResources: byte[] list) (ulLinkedResourceBaseR
751749 // return the buffer
752750 pResBuffer
753751
752+ let linkNativeResourcesManaged ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
753+ ignore fileType
754+ ignore outputFilePath
755+
756+ let resources =
757+ unlinkedResources
758+ |> Seq.map ( fun s -> new MemoryStream( s))
759+ |> Seq.map ( fun s ->
760+ let res = CVTres.CvtResFile.ReadResFile s
761+ s.Dispose()
762+ res)
763+ |> Seq.collect id
764+ // See MakeWin32ResourceList https://github.com/dotnet/roslyn/blob/f40b89234db51da1e1153c14af184e618504be41/src/Compilers/Core/Portable/Compilation/Compilation.cs
765+ |> Seq.map ( fun r ->
766+ WriteNativeRes.Win32Resource( data = r.data, codePage = 0 u, languageId = uint32 r.LanguageId,
767+ id = int ( int16 r.pstringName.Ordinal), name = r.pstringName.theString,
768+ typeId = int ( int16 r.pstringType.Ordinal), typeName = r.pstringType.theString))
769+ let bb = new System.Reflection.Metadata.BlobBuilder()
770+ WriteNativeRes.NativeResourceWriter.SerializeWin32Resources( bb, resources, ulLinkedResourceBaseRVA)
771+ bb.ToArray()
772+
773+ let linkNativeResources ( unlinkedResources : byte [] list ) ( ulLinkedResourceBaseRVA : int32 ) ( fileType : PEFileType ) ( outputFilePath : string ) =
774+ #if ENABLE_ MONO_ SUPPORT
775+ if IL.runningOnMono then
776+ linkNativeResourcesManaged unlinkedResources ulLinkedResourceBaseRVA fileType outputFilePath
777+ else
778+ #endif
779+ #if ! FX_ NO_ LINKEDRESOURCES
780+ linkNativeResourcesViaCVTres unlinkedResources ulLinkedResourceBaseRVA fileType outputFilePath
781+ #else
782+ linkNativeResourcesManaged unlinkedResources ulLinkedResourceBaseRVA fileType outputFilePath
783+ #endif
784+
754785let unlinkResource ( ulLinkedResourceBaseRVA : int32 ) ( pbLinkedResource : byte []) =
755786 let mutable nResNodes = 0
756787
@@ -854,7 +885,6 @@ let unlinkResource (ulLinkedResourceBaseRVA: int32) (pbLinkedResource: byte[]) =
854885 resBufferOffset <- resBufferOffset + pResNodes.[ i]. Save( ulLinkedResourceBaseRVA, pbLinkedResource, pResBuffer, resBufferOffset)
855886
856887 pResBuffer
857- #endif
858888
859889#if ! FX_ NO_ PDB_ WRITER
860890// PDB Writing
0 commit comments