ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

Support for WebCIL

Open christophwille opened this issue 1 year ago • 10 comments

Specification see https://github.com/dotnet/runtime/blob/main/docs/design/mono/webcil.md (basically a "firewall-evading" repackaging of Windows DLLs)

I started a discussion on how others could read that format without rolling their own implementation https://github.com/dotnet/runtime/discussions/86587 (Transport feed NuGet might be a solution sometime https://github.com/dotnet/runtime/issues/86597)

Code in question: https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil (WasmModuleReader is of interest)

BlazorWebCilPublishDemo.zip publish output see bin\Release\net8.0\browser-wasm\publish\wwwroot_framework

christophwille avatar Jun 07 '23 16:06 christophwille

From https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-8-preview-5/

"In .NET 8 Preview 5 we’ve improved the Webcil format by adding a standard WebAssembly wrapper. This means that Webcil files are now just WebAssembly files that have the standard .wasm extension.

Webcil is now the default packaging format when you publish a Blazor WebAssembly app. If you wish to disable the use of Webcil, you may do so by setting <WasmEnableWebcil>false</WasmEnableWebcil> in your project file."

christophwille avatar Jun 16 '23 07:06 christophwille

WebCIL project moved to https://github.com/dotnet/runtime/tree/main/src/tasks/Microsoft.NET.WebAssembly.Webcil

christophwille avatar Nov 05 '23 10:11 christophwille

@christophwille Did you try to use the WebcilReader-class from that Microsoft.NET.WebAssembly.Webcil project to read a .wasm file en extract the PE bytes?

I want to create a MetadataReference based on the PE bytes like:

MetadataReference.CreateFromImage(bytes);

StefH avatar Jan 03 '24 11:01 StefH

At the moment, this is only a tracking issue, no PoC or other code exists.

christophwille avatar Jan 03 '24 11:01 christophwille

@christophwille FYI I got some reverse decoding working, I can get the original PE dll bytes, however I'm missing the PE header: image

So that's a blocker I think, or I still need to find a way to extract this (but I don't think its present)

Do you know a way to generate a valid PE header ?

StefH avatar Jan 06 '24 09:01 StefH

I have to read up on WebCil again but I think I saw that no header was one of the features.

christophwille avatar Jan 06 '24 09:01 christophwille

I want to create a MetadataReference based on the PE bytes like:\n\nMetadataReference.CreateFromImage(bytes);

@StefH How is your question related to ILSpy or WebCIL support in ILSpy? We don't use Roslyn's MetadataReference in ILSpy at all.

I think for most of the features in ILSpy just reading the ECMA-335 portion of the file should be sufficient, but I haven't looked into it in depth.

If you need Roslyn support for WebCIL I'd suggest asking in their repository directly. Thank you very much!

siegfriedpammer avatar Jan 06 '24 16:01 siegfriedpammer

@siegfriedpammer Thanks for your reply. I'll investigate some more and report any other questions or issues to the Roslyn repository.

StefH avatar Jan 08 '24 07:01 StefH

In case anyone is interested:

I create a project which can create a valid MetadataReference based on the Webcil WASM wrapped file : https://github.com/StefH/ProtoBufJsonConverter/tree/main/src-webcil

StefH avatar Feb 04 '24 13:02 StefH

@StefH thanks for posting your research results, unfortunately this does not help in our case, because we need to read the WebCIL image as-is without generating a PE file.

siegfriedpammer avatar Feb 06 '24 21:02 siegfriedpammer