Registry / data / dnfile

dnfile

JSON →
library0.18.0pypypi✓ verified 68d ago

dnfile is a Python library designed to parse .NET executable files. It aims to parse as much as possible, even if the file is partially malformed, and provides an easy-to-use, object-oriented API developed with IDE autocompletion in mind. The current version is 0.18.0, with a release cadence of several updates per year.

pip install dnfile
INSTALL
IMPORT
SIG · DNFILE
D
dnfile
datapythonv0.18.0
Install
1.6s avg
Import
93ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.18.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.099s · 18.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.088s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dnPE
from dnfile import dnPE
The primary entry point for parsing a .NET executable file.
dnfile
import dnfile
Commonly imported directly to access top-level functions and classes like dnfile.dnPE, dnfile.stream, etc.

This quickstart demonstrates how to load and parse a .NET executable file using `dnfile`. It shows how to access the CLR header and iterate through some basic metadata streams. For a real use case, `filepath` should point to an actual .NET executable.

import sys import dnfile # For demonstration, create a dummy file or use a path to a real .NET exe # Replace 'dummy.exe' with a path to an actual .NET executable for real parsing # For a runnable quickstart, we'll simulate a file existence check. filepath = "path/to/your/dotnet_executable.exe" # Placeholder try: # In a real scenario, you'd ensure filepath points to a valid file. # For this example, we'll just demonstrate the parsing attempt. # A real application would handle FileNotFoundError or similar. pe = dnfile.dnPE(filepath) # Check if the .NET header exists if hasattr(pe, "net") and pe.net: print(f"Successfully parsed .NET executable: {filepath}") print(f"CLR Runtime Header Version: {pe.net.struct.MajorRuntimeVersion}.{pe.net.struct.MinorRuntimeVersion}") # Accessing metadata tables (example) if hasattr(pe.net, "mdtables") and pe.net.mdtables: print(f"Number of Metadata Tables: {len(pe.net.mdtables.tables_list)}") # Example: Iterate through some streams for s in pe.net.metadata.streams_list: print(f" Stream Name: {s.name}, Size: {s.size}") else: print(f"File {filepath} does not appear to be a .NET executable or parsing failed.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingStarting with version 0.14.0, `dnfile` requires Python 3.8 or newer. Attempts to use it with older Python versions will result in `ImportError` or other compatibility issues.
fix
Ensure your project environment uses Python 3.8 or a newer compatible version.
affects: >=0.14.0
breakingIn version 0.15.0, the behavior of heap stream's `.get()` method changed. It now returns a `HeapItem` object (e.g., `HeapItemString`, `HeapItemBinary`) instead of raw bytes.
fix
If you were expecting `bytes`, you'll now need to access the `.value` attribute of the returned `HeapItem` (e.g., `item.value`). Be aware that `HeapItemString.value` can be `None` if decoding fails.
affects: >=0.15.0
breakingAs of version 0.10.0, structure attributes no longer exist by default, and objects' attributes always exist but may be `None`. This means direct access to fields might require checks or use of the `.struct` attribute for raw values.
fix
When accessing specific fields, be prepared for attributes to be `None` or use the `.struct` attribute (e.g., `pe.net.struct.MajorRuntimeVersion`) to access raw structure values directly. Validate attribute existence and non-`None` values before use.
affects: >=0.10.0
gotchadnfile is designed to parse as much as possible, even if the .NET executable is partially malformed. This means that parsing a corrupted file might result in a `dnPE` object with incomplete or `None` attributes rather than raising an immediate error.
fix
Always check for the existence and validity of attributes (e.g., `if hasattr(pe, 'net') and pe.net:`) after parsing, especially when dealing with untrusted or potentially malformed input files.
affects: *
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dnfile'
The 'dnfile' library is not installed in the current Python environment or is not accessible via the Python path.
fix
Install the library using pip: `pip install dnfile`
AttributeError: 'NoneType' object has no attribute 'net'
The `dnfile.dnPE()` function returned `None` because the provided file path points to a file that is not a valid .NET Portable Executable (PE) file or could not be parsed, and subsequent code attempted to access the `.net` attribute on the `None` object.
fix
Always check if the `dnPE` object is `None` before attempting to access its attributes: `import dnfile; pe = dnfile.dnPE('path/to/your/file.exe'); if pe and hasattr(pe, 'net'): print(pe.net.struct) else: print('File is not a valid .NET PE or could not be parsed.')`
ValueError: invalid compressed int
This error occurs internally within `dnfile` when parsing a malformed .NET executable file where a compressed integer value (used in metadata streams) cannot be correctly interpreted, indicating corrupted or non-standard file content.
fix
Ensure the input file is a valid .NET executable. While `dnfile` attempts to parse malformed files, extreme corruption can lead to parsing errors. Consider using a `try-except ValueError` block to handle such cases gracefully: `try: pe = dnfile.dnPE('path/to/malformed.exe') # ... process pe object ... except ValueError as e: print(f'Error parsing file: {e}')`
Upgrade
Version history
0.18.0latest on PyPI · released Jan 31, 2026
Audit
Dependencies
pefilerequiredUsed internally for PE file parsing capabilities, as .NET executables are a type of PE file.
Agent activity
8 hits · last 30 days
node
8
Resources