Skip to main content

A library for reading .NET modules

Project description

dnpy

A pure-Python library for parsing .NET assemblies. It reads PE files containing ECMA-335 metadata and CIL bytecode, and exposes them through a typed object model.

The current focus is reading. Writing assemblies back to disk is deliberately out of scope until the read path is fully hardened

Installation

pip install dnpy

Quick start

from dnpy import Module

module = Module.from_path("MyAssembly.exe")

if module.assembly:
    a = module.assembly
    print(f"{a.name} v{a.major_version}.{a.minor_version}.{a.build_number}.{a.revision_number}")

for type_def in module.types:
    print(type_def.full_name)
    for method in type_def.methods:
        print(f"  {method.name}")
        for instruction in method.instructions:
            print(f"    {instruction}")

Module.from_bytes(data) is also available for in-memory binaries.

Documentation

The docs/ directory has longer-form material:

  • Getting started – installation, the first script, and recipes for the most common tasks.
  • Architecture – how a Module is layered on top of the PE file, metadata streams, tables, and heaps.
  • Walking IL – the instruction stream, branch targets, exception handlers, and operand resolution.
  • API reference – the public surface of the dnpy.Module, TypeDef, MethodDef, and friends.

Out of scope

The following are not implemented:

  • Writing or modifying assemblies
  • Reading PDB / .pdb symbol files
  • Strong-name signing or verification
  • Decompilation back to C#

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnpy-1.0.0.tar.gz (65.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dnpy-1.0.0-py3-none-any.whl (67.4 kB view details)

Uploaded Python 3

File details

Details for the file dnpy-1.0.0.tar.gz.

File metadata

  • Download URL: dnpy-1.0.0.tar.gz
  • Upload date:
  • Size: 65.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.8

File hashes

Hashes for dnpy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 953d919ed0fb0745a07852f3150674c3cb727f61a4b719741b511729f2e80801
MD5 065cc535bf18605aea8a9795251fe3cc
BLAKE2b-256 9574893a23837dc54ef759d1fbfd50dc47a3852c7c25ccad6382b356596aa860

See more details on using hashes here.

File details

Details for the file dnpy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dnpy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 67.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.8

File hashes

Hashes for dnpy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdd1996359fa7f7e97ea425c783b98adf4fa27692d866821bab5d5429eca58e0
MD5 1ec80b7822a3e1afb7d900b22f2926e0
BLAKE2b-256 d9faf6cef6aa0c17e53b27f60ae854d3ca3f1917e7abee54f8eaa6e5d359aa06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page