Parse .NET executable files.
Project description
dnfile
Parse .NET executable files.
Free software: MIT license
Features
Parse as much as we can, even if the file is partially malformed.
Easy to use. Developed with IDE autocompletion in mind.
Quick Start
pip install dnfile
Then create a simple program that loads a .NET binary, parses it, and displays information about the streams and Metadata Tables.
import sys
import dnfile
filepath = sys.argv[1]
pe = dnfile.dnPE(filepath)
pe.print_info()
Everything is an object, and raw structure values are stored in an object’s “struct” attribute. The CLR directory entry object is accessible from the “net” attribute of a dnPE object.
import dnfile
import hashlib
pe = dnfile.dnPE(FILEPATH)
# access the directory entry raw structure values
pe.net.struct
# access the metadata raw structure values
pe.net.metadata.struct
# access the streams
for s in pe.net.metadata.streams_list:
if isinstance(s, dnfile.stream.MetaDataTables):
# how many Metadata tables are defined in the binary?
num_of_tables = len(s.tables_list)
# the last Metadata tables stream can also be accessed by a shortcut
num_of_tables = len(pe.net.mdtables.tables_list)
# create a set to hold the hashes of all resources
res_hash = set()
# access the resources
for r in pe.net.resources:
# if resource data is a simple byte stream
if isinstance(r.data, bytes):
# hash it and add the hash to the set
res_hash.add(hashlib.sha256(r.data).hexdigest())
# if resource data is a ResourceSet, a dotnet-specific datatype
elif isinstance(r.data, dnfile.resource.ResourceSet):
# if there are no entries
if not r.data.entries:
# skip it
continue
# for each entry in the ResourceSet
for entry in r.data.entries:
# if it has data
if entry.data:
# hash it and add the hash to the set
res_hash.add(hashlib.sha256(entry.data).hexdigest())
TODO
more tests
Documentation on readthedocs
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.11.0 (2022)
FEATURE: access .NET resources (not same as PE resources!) by a shortcut
BUGFIX: dnstrings example
more attributes default to None
update dev dependencies
remove some warnings
0.10.0 (2022)
BREAKING CHANGE: structure attributes no longer exist by default
BREAKING CHANGE: objects’ attributes always exist, but may be None
BUGFIX: use last stream if multiple of same name
CI: added mypy type checking
when duplicate stream names, behave like runtime and use last one for shortcuts
add user_strings shortcut
able to access MetaDataTables like a 0-based list, with square brackets
added use of logging module for warnings
better type hints for IDEs
more better source comments
more tests
0.9.0 (2021)
bugfix: row indices parsed in structures are one-based, not zero-based
bugfix: TypeDefRow was not parsing Extends coded index
bugfix: incorrect BLOBS_MASK and add EXTRA_DATA skip if flag set
added CI using github workflow
added tests and submodule dnfile-testfiles
added style consistency using pycodestyle and isort
added more examples
parse MetaData tables’ list-type indexes into lists of MDTableRow objects
0.8.0 (2021)
bugfix: Metadata Table indexes (i.e. indexes into other tables) were off by one
0.7.1 (2021)
bugfix: coded index always None
0.7.0 (2021)
bugfix: improper data length check
0.6.0 (2021)
bugfix: referenced wrong object
parse utf-16 strings in #US stream
0.5.0 (2021-01-29)
First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dnfile-0.11.0.tar.gz
.
File metadata
- Download URL: dnfile-0.11.0.tar.gz
- Upload date:
- Size: 40.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c276a2a35e7121efbb01f38b7720947b3e1d758595a3a7d5607ed9738eedefe |
|
MD5 | afe18caaea9862271f319c2117f11e98 |
|
BLAKE2b-256 | d991a5755ef464fbc6ff639398b4a8e1a819570c78057a7ac64424ab0b8ab4f2 |
Provenance
File details
Details for the file dnfile-0.11.0-py2.py3-none-any.whl
.
File metadata
- Download URL: dnfile-0.11.0-py2.py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02736726387f340dcacd708536cfb2a61121deb2e023344b2156b28a41073636 |
|
MD5 | b3cc7c8d4ca87cc17a74c1bbebba0e1a |
|
BLAKE2b-256 | 850e36b34bc9542b5a7678cd7ed32e7e416bdffe98357a0b26bba6801fbdebdd |