pepy
pepy (pronounced p-pie) is a python binding to the pe-parse parser.
pepy supports Python versions 3.6 and above.
The easiest way to use pepy is to install it via pip:
$ pip3 install pepy
Building
If you can build pe-parse and have a working python environment (headers and libraries) you can build pepy.
- Build pepy:
python3 setup.py build
- Install pepy:
python3 setup.py install
Building on Windows: Python 3.x is typically installed as python.exe, NOT python3.exe.
Using
Parsed object
There are a number of objects involved in pepy. The main one is the parsed object. This object is returned by the parse method.
import pepy
p = pepy.parse("/path/to/exe")
The parsed object has a number of methods:
get_entry_point: Return the entry point addressget_machine_as_str: Return the machine as a human readable stringget_subsystem_as_str: Return the subsystem as a human readable stringget_bytes: Return the first N bytes at a given addressget_sections: Return a list of section objectsget_imports: Return a list of import objectsget_exports: Return a list of export objectsget_relocations: Return a list of relocation objectsget_resources: Return a list of resource objects
The parsed object has a number of attributes:
signaturemachinenumberofsectionstimedatestampnumberofsymbolscharacteristicsmagicmajorlinkerverminorlinkervercodesizeinitdatasizeuninitdatasizeentrypointaddrbaseofcodebaseofdataimagebasesectionalignementfilealignmentmajorosverminorosverwin32verimagesizeheadersizechecksumsubsystemdllcharacteristicsstackreservesizestackcommitsizeheapreservesizeheapcommitsizeloaderflagsrvasandsize
Example:
import time
import pepy
p = pepy.parse("/path/to/exe")
print("Timedatestamp: %s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(p.timedatestamp)))
ep = p.get_entry_point()
print("Entry point: 0x%x" % ep)
The get_sections, get_imports, get_exports, get_relocations and
get_resources methods each return a list of objects. The type of object
depends upon the method called. get_sections returns a list of section
objects, get_imports returns a list of import objects, etc.
Section Object
The section object has the following attributes:
baselengthvirtaddrvirtsizenumrelocsnumlinenumscharacteristicsdata
Import Object
The import object has the following attributes:
symnameaddr
Export Object
The export object has the following attributes:
modfuncaddr
Relocation Object
The relocation object has the following attributes:
typeaddr
Resource Object
The resource object has the following attributes:
type_strname_strlang_strtypenamelangcodepageRVAsizedata
The resource object has the following methods:
type_as_str
Resources are stored in a directory structure. The first three levels of the
are called type, name and lang. Each of these levels can have
either a pre-defined value or a custom string. The pre-defined values are
stored in the type, name and lang attributes. If a custom string is
found it will be stored in the type_str, name_str and lang_str
attributes. The type_as_str method can be used to convert a pre-defined
type value to a string representation.
The following code shows how to iterate through resources:
import pepy
from hashlib import md5
import sys
p = pepy.parse(sys.argv[1])
resources = p.get_resources()
print("Resources: (%i)" % len(resources))
for resource in resources:
print("[+] MD5: (%i) %s" % (len(resource.data), md5(resource.data).hexdigest()))
if resource.type_str:
print("\tType string: %s" % resource.type_str)
else:
print("\tType: %s (%s)" % (hex(resource.type), resource.type_as_str()))
if resource.name_str:
print("\tName string: %s" % resource.name_str)
else:
print("\tName: %s" % hex(resource.name))
if resource.lang_str:
print("\tLang string: %s" % resource.lang_str)
else:
print("\tLang: %s" % hex(resource.lang))
print("\tCodepage: %s" % hex(resource.codepage))
print("\tRVA: %s" % hex(resource.RVA))
print("\tSize: %s" % hex(resource.size))
Note that some binaries (particularly packed) may have corrupt resource entries.
In these cases you may find that len(resource.data) is 0 but resource.size is
greater than 0. The size attribute is the size of the data as declared by the
resource data entry.
Authors
pe-parse was designed and implemented by Andrew Ruef (andrew@trailofbits.com).
pepy was written by Wesley Shields (wxs@atarininja.org).
Metadata
Release files for pepy 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pepy-2.1.1.tar.gz | 15.4 kB | Without provenance | Details for pepy-2.1.1.tar.gz |
Release files / pepy-2.1.1.tar.gz
| Download URL | pepy-2.1.1.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cec463c444b71d1664229121897b22df753dc91fabb2113d1c89992638c90829
|
|
BLAKE2b-256 checksum How to use checksums |
787e123d89ce0e999e957e53f0b985f734565c93b9a698af53586fc2a1be0dbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Security for pepy 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.