Question

I want my application, written in ocaml, to read a managed DLL and retrieve the class definitions contained therein. Where can I find the public documentation / example code on how to do it?

[edit: Since I'm writing this application in ocaml, I'm looking for actual file format definitions, since I can't use the .NET's own assembly inspection functions]

Thank you!

Était-ce utile?

La solution 3

Okay, I've found some relevant pieces of information about reading a PE file and the CLI metadata. Specifically, this article http://wyday.com/blog/2010/how-to-detect-net-assemblies-x86-x64-anycpu/ has an example source code in C# and links to the PE/COFF specification, and to the CLI Metadata specification . It seems they will be enough to get started.

I will still leave this question open, though, if someone would like to share more specific information / example source code. Thanks again for everyone that answered!

Autres conseils

There is no formal file specification available, mostly because it is subject to change and has changed several times (.NET 1.1, 2.0 and 4.0). A structural description of the metadata tables in the assembly manifest is available in Ecma 335. The Windows SDK's CorHdr.h file contains essential declarations, but is only directly usable from C or C++.

Nobody ever tries to read the file directly. Instead you use the metadata api, IMetaDataImport2. Good examples are widely available, the name googles well. The SSCLI20 project has source code for ildasm and the C# compiler that shows this interface being used. The CCI Metadata project could be very useful as well, designed to help you implement compilers, short from it probably not being useful directly in OCaml.

Beware that IMetaDataImport is a COM interface so the degree of pain you'll suffer trying to port this to OCaml will depend a great deal on how well your implementation supports COM.

This Code should help you to start

 Assembly dLL = Assembly.LoadFile(assemblyPath);
 foreach (Type type in dLL.GetTypes())
 {
  //...play with type here
 }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top