How do I find out if a .NET assembly contains unma

2019-01-19 13:43发布

.NET assemblies that contain a mixture of managed and unmanaged code cannot be ILMerged with other assemblies.

How can I verify if a given .NET assembly contains purely managed code, or a mix of managed and unmanaged code?

8条回答
该账号已被封号
2楼-- · 2019-01-19 14:16

To get the PE flags from C#, use the System.Reflection API: http://www.example8.com/category/view/id/6027

...

Assembly a = Assembly.GetExecutingAssembly();
Module m = a.ManifestModule;

PortableExecutableKinds peKinds;
ImageFileMachine imageFileMachine;
m.GetPEKind(out peKinds, out imageFileMachine);

if ((peKinds & PortableExecutableKinds.ILOnly) != 0)

...

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-19 14:17

Improving on the answer provided above Wim...

  1. Locate your "PEVerify.exe" - you have it if you have VS installed.- COPY THE FULL PATH TO THE PEVerify.exe file, your path will be different - - Here's an example: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\PEVerify.exe

  2. Open Visual Studio Command prompt (don't "Run as Administrator")

  3. Type in: cd C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools

  4. your command prompt should now be this long text instead of just C:\ or something....it will point to the path of where PEVerify.exe is located.

  5. Now type in: peverify "your full path to your dll you want to check - THen Press Enter - Here is my example : peverify "G:\TestFolder\My_Managed_OR_Unmanaged.dll"

  6. After you press Enter and you get a message as below, its 100% managed dll - All Classes and Methods in My_Managed_OR_Unmanaged.dll Verified."

查看更多
登录 后发表回答