dnlib | Reads and writes .NET assemblies and modules

 by   0xd4d C# Version: v3.6.0 License: MIT

kandi X-RAY | dnlib Summary

kandi X-RAY | dnlib Summary

dnlib is a C# library. dnlib has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

.NET module/assembly reader/writer library.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              dnlib has a medium active ecosystem.
              It has 1834 star(s) with 571 fork(s). There are 108 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 21 open issues and 392 have been closed. On average issues are closed in 58 days. There are 2 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of dnlib is v3.6.0

            kandi-Quality Quality

              dnlib has 0 bugs and 0 code smells.

            kandi-Security Security

              dnlib has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              dnlib code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              dnlib is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              dnlib releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of dnlib
            Get all kandi verified functions for this library.

            dnlib Key Features

            No Key Features are available at this moment for dnlib.

            dnlib Examples and Code Snippets

            No Code Snippets are available at this moment for dnlib.

            Community Discussions

            QUESTION

            How to generate C# code from IL Instructions
            Asked 2021-Oct-31 at 00:13

            I'm trying to generate c# code from IL instructions using the dnlib library.

            The code I'm trying to generate is this one:

            ...

            ANSWER

            Answered 2021-Oct-31 at 00:13

            while trying some stuff, I saw that I needed to be using the main object (from dnlib) that has the .NET module loaded (ModuleDefMD).

            So I did it this way:

            Source https://stackoverflow.com/questions/69782281

            QUESTION

            Some metadata tokens for local variable types invalid after rewrite with dnlib
            Asked 2021-May-16 at 10:18

            What I am doing (partly for fun and learning, partly hopefully as a serious virtualization effort someday) is merging my VM dll with a target assembly via ILMerge.

            Only afterwards I modify the newly created file with dnlib to replace the method bodies of selected methods with a call to my VM function. I pass the required metadata that is now absent in the method itself via a base64 encoded binary string and obviously the arguments and the old method body too (in the future I want to implement my own bytecode instruction set for that, but so far its just the original code base64-encoded).

            Since .initlocals is from my experience always set in a .NET method, what I want to do is save the type of every local as data in such a way that I can initialize my local array in the Virtualizer runtime with it.

            My current approach is just to save the MDToken writer.Write(local.Type.ToTypeDefOrRef().GetNonNestedTypeRefScope().MDToken.ToInt32());

            I write my changes to the assembly with the PreserveAll flag opts.MetadataOptions.Flags = dnlib.DotNet.Writer.MetadataFlags.PreserveAll;

            and in the runtime resolve the MDToken via

            ...

            ANSWER

            Answered 2021-May-16 at 10:18

            However, a metadata token is not a persistent identifier. Rather it is scoped to a specific metadata binary.

            What it's saying is that the metadata token is only meaningful within the scope of the module, you can't take the metadata token from one module and use it in another or even within a modified version of the same module (or at least not reliably).

            The reason for this makes more sense when you consider what the metadata token really is. The metadata token is a reference to a record in a metadata table within the module, and that record contains further details; the high-order byte of the metadata token indicates the type of token (and thus the table containing the record), while the remaining 3 bytes indicate the row number.

            If you take a metadata token from one module and try to use it in another module, you are assuming that the same record in each module represents the same thing. If you compile the same code with the same compiler, then this assumption may hold; but if you change the source or use a different compiler (or different version of the same compiler) then the row numbers may change for any number of reasons.

            And why does this problem not occur at all in the method body instructions? Many instructions encode an InlineType and Module.ResolveType has never failed there.

            Because the compiler emitting the IL with the metadata token is also emitting the tables into the same file. The compiler is able to keep these things in sync.

            And, more importantly, how to fix? How do I save a reliable type identifier in a binary form for the locals of a method?

            The only reliable way to reference a type between modules, is with the full type name and scope (the containing assembly, module or type in the case of a nested type).

            Source https://stackoverflow.com/questions/67456382

            QUESTION

            dnLib-Generated Assembly - TypeLoadException Thrown at Runtime
            Asked 2021-Mar-17 at 18:32

            I am using dnLib to generate MSIL assemblies dynamically from a custom language I'm writing, named CSASM:

            ...

            ANSWER

            Answered 2021-Mar-17 at 18:32

            After a very thorough examination of a dnLib DLL, the problem was due to me using Importer.ImportDeclaringType(Type).ToTypeDefOrRef(), which caused value-type TypeSigs to be registered as class-type TypeSigs instead.

            Even though the docs say to use Importer.ImportDeclaringType(Type) over Importer.ImportAsTypeSig(Type) for method and field declarations, you really shouldn't be using it.

            Source https://stackoverflow.com/questions/66480908

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install dnlib

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/0xd4d/dnlib.git

          • CLI

            gh repo clone 0xd4d/dnlib

          • sshUrl

            git@github.com:0xd4d/dnlib.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link