Python

Parser

lief.PE.parse(*args) lief.PE.Binary | None
lief.PE.parse(filename: str, config: lief._lief.PE.ParserConfig = <lief._lief.PE.ParserConfig object at 0x7f953be6d8f0>) lief._lief.PE.Binary | None
lief.PE.parse(raw: collections.abc.Sequence[int], config: lief._lief.PE.ParserConfig = <lief._lief.PE.ParserConfig object at 0x7f953be6d910>) lief._lief.PE.Binary | None
lief.PE.parse(obj: Union[io.IOBase | os.PathLike], config: lief._lief.PE.ParserConfig = <lief._lief.PE.ParserConfig object at 0x7f953be6d930>) lief._lief.PE.Binary | None

Overloaded function.

  1. parse(buffer: bytes, config: lief._lief.PE.ParserConfig = <lief._lief.PE.ParserConfig object at 0x7f953be6d8d0>) -> Optional[lief._lief.PE.Binary]

    Parse the PE binary from the given bytes and return a lief.PE.Binary object.

    The second argument is an optional configuration (ParserConfig) that can be used to define which part(s) of the PE should be parsed or skipped.

  2. parse(filename: str, config: lief._lief.PE.ParserConfig = <lief._lief.PE.ParserConfig object at 0x7f953be6d8f0>) -> Optional[lief._lief.PE.Binary]

Parse the PE binary from the given file path and return a Binary object

  1. parse(raw: collections.abc.Sequence[int], config: lief._lief.PE.ParserConfig = <lief._lief.PE.ParserConfig object at 0x7f953be6d910>) -> Optional[lief._lief.PE.Binary]

Parse the PE binary from the given list of bytes and return a lief.PE.Binary object

  1. parse(obj: Union[io.IOBase | os.PathLike], config: lief._lief.PE.ParserConfig = <lief._lief.PE.ParserConfig object at 0x7f953be6d930>) -> Optional[lief._lief.PE.Binary]

Parse the PE binary from the given parameter and return a lief.PE.Binary object

class lief.PE.ParserConfig(self)

Bases: object

This class is used to tweak the PE Parser (lief.PE.parse())

all = <lief._lief.PE.ParserConfig object>
default_conf = <lief._lief.PE.ParserConfig object>
property parse_arm64x_binary bool

Whether it should parse nested ARM64X binary

This option is set to off by default since it can introduce a certain overhead.

property parse_exceptions bool

Whether it should parse in-depth exceptions metadata.

This option is set to off by default since it can introduce a certain overhead.

property parse_exports bool

Parse PE Exports Directory

property parse_imports bool

Parse PE Import Directory

property parse_reloc bool

Parse PE relocations

property parse_rsrc bool

Parse PE resources tree

property parse_signature bool

Parse PE Authenticode signature

Binary

class lief.PE.Binary

Bases: Binary

Class which represents a PE binary which is the main interface to manage and modify a PE executable.

This object can be instantiated through lief.parse() or lief.PE.parse() while the constructor of this object can be used to craft a binary from scratch (see: 02 - Create a PE from scratch (Deprecated))

add_debug_info(self, entry: lief.PE.Debug) lief.PE.Debug

Add a new debug entry

add_import(self, import_name: str) lief.PE.Import

Add an imported library (i.e. DLL) to the binary

add_relocation(self, relocation: lief.PE.Relocation) lief.PE.Relocation

Add a Relocation to the binary

add_section(self, section: lief.PE.Section) lief.PE.Section

Add a Section to the binary.

authentihash(self, algorithm: lief.PE.ALGORITHMS) bytes

Compute the authentihash according to the ALGORITHMS given in the first parameter

property authentihash_md5 bytes

Authentihash MD5 value

property authentihash_sha1 bytes

Authentihash SHA1 value

property authentihash_sha256 bytes

Authentihash SHA-256 value

property authentihash_sha512 bytes

Authentihash SHA-512 value

property cert_dir lief.PE.DataDirectory

Return the data directory associated with the certificate table (authenticode).

clear_debug(self) bool

Remove all debug info from the binary

property codeview_pdb lief.PE.CodeViewPDB

Return the CodeViewPDB if present

property coff_string_table lief.PE.Binary.it_strings_table

Iterator over the strings located in the COFF string table

compute_checksum(self) int

Re-compute the value of checksum. If both values do not match, it could mean that the binary has been modified after the compilation.

This value is computed by LIEF for the current binary object.

property data_directories lief.PE.Binary.it_data_directories

Return an iterator over the DataDirectory

data_directory(self, type: lief.PE.DataDirectory.TYPES) lief.PE.DataDirectory

Return the DataDirectory object from the given TYPES type

property debug lief.PE.Binary.it_debug

Return the Debug

property debug_dir lief.PE.DataDirectory

Return the data directory associated with the debug table

property delay_dir lief.PE.DataDirectory

Return the data directory associated with delayed imports

property delay_imports lief.PE.Binary.it_delay_imports

Return an iterator over the DelayImport

property dos_header lief.PE.DosHeader

Return the DosHeader

property dos_stub memoryview

DOS stub content as a list of bytes

property exception_functions list[lief.Function]

Function found in the Exception directory

property exceptions lief.PE.Binary.it_exceptions

Iterator over the exception (_RUNTIME_FUNCTION) functions.

Warning

This property requires that the option lief.PE.ParserConfig.parse_exceptions was turned on (default is False) when parsing the binary.

property exceptions_dir lief.PE.DataDirectory

Return the data directory associated with the exceptions

property export_dir lief.PE.DataDirectory

Return the data directory associated with the export table

fill_address(self, address: int, size: int, value: int, addr_type: lief.Binary.VA_TYPES) None

Fill the content at the provided with a fixed value

find_coff_string(self, offset: int) lief.PE.COFFString

Try to find the COFF string at the given offset in the COFF string table.

Warning

This offset must include the first 4 bytes holding the size of the table. Hence, the first string starts a the offset 4.

find_exception_at(self, rva: int) lief.PE.ExceptionInfo

Try to find the exception info at the given RVA.

Warning

This property requires that the option lief.PE.ParserConfig.parse_exceptions was turned on (default is False) when parsing the binary.

property functions list[lief.Function]

All Function found in the binary

get_delay_import(self, import_name: str) lief.PE.DelayImport

Return the DelayImport from the given name or None if not not found

get_export(self) lief.PE.Export

Return the Export object

get_import(self, import_name: str) lief.PE.Import

Return the Import from the given name or None if it can’t be found

get_section(self, section_name: str) lief.PE.Section

Return the Section object from the given name or None if not not found

property has_configuration bool

True if the current binary has LoadConfiguration

property has_debug bool

True if the current binary has a Debug object

has_delay_import(self, import_name: str) bool

True if the binary imports the given library name

property has_delay_imports bool

True if the current binary has delay imports (DelayImport)

property has_exceptions bool

True if the current binary uses Exceptions

property has_exports bool

True if the current binary has a Export object

has_import(self, import_name: str) bool

True if the binary imports the given library name

property has_imports bool

True if the current binary has imports (Import)

property has_relocations bool

True if the current binary uses Relocation

property has_resources bool

True if the current binary has a Resources object

property has_rich_header bool

True if the current binary has a RichHeader object

property has_signatures bool

True if the binary is signed with the PE authenticode (Signature)

property has_tls bool

True if the current binary has a TLS object

property header lief.PE.Header

Return the Header

property iat_dir lief.PE.DataDirectory

Return the data directory associated with the IAT

property import_dir lief.PE.DataDirectory

Return the data directory associated with the import table

property imports lief.PE.Binary.it_imports

Return an iterator over the Import libraries

property is_arm64ec bool

True if this binary is compiled in ARM64EC mode (emulation compatible)

property is_arm64x bool

True if this binary is compiled in ARM64X mode (contains both ARM64 and ARM64EC

property is_reproducible_build bool

True if the binary was compiled with a reproducible build directive (Debug)

class it_const_signatures

Bases: object

Iterator over lief._lief.PE.Signature

class it_data_directories

Bases: object

Iterator over lief._lief.PE.DataDirectory

class it_debug

Bases: object

Iterator over lief._lief.PE.Debug

class it_delay_imports

Bases: object

Iterator over lief._lief.PE.DelayImport

class it_exceptions

Bases: object

Iterator over lief._lief.PE.ExceptionInfo

class it_imports

Bases: object

Iterator over lief._lief.PE.Import

class it_relocations

Bases: object

Iterator over lief._lief.PE.Relocation

class it_section

Bases: object

Iterator over lief._lief.PE.Section

class it_strings_table

Bases: object

Iterator over lief._lief.PE.COFFString

class it_symbols

Bases: object

Iterator over lief._lief.PE.Symbol

property load_config_dir lief.PE.DataDirectory

Return the data directory associated with the load config

property load_configuration lief.PE.LoadConfiguration

Return the LoadConfiguration object or None if not present

property nested_pe_binary lief.PE.Binary

If the current binary contains dynamic relocations (e.g. lief.PE.DynamicFixupARM64X), this function returns the relocated view of the current PE.

This can be used to get the alternative PE binary, targeting a different architecture.

Warning

This property requires that the option lief.PE.ParserConfig.parse_arm64x_binary was turned on (default is False) when parsing the binary.

property optional_header lief.PE.OptionalHeader

Header that follows the header. It is named optional from the COFF specifications but it is mandatory in a PE file.

property overlay memoryview

Return the overlay content as a list of bytes

property overlay_offset int

Return the original overlay offset

property relocation_dir lief.PE.DataDirectory

Return the data directory associated with the relocation table

property relocations lief.PE.DynamicFixupGeneric.it_relocations

Return an iterator over the Relocation

remove(self, section: lief.PE.Section, clear: bool) None

Remove the Section given in first parameter

remove_all_imports(self) None

Remove all imported libraries

remove_all_relocations(self) None
remove_debug(self, entry: lief.PE.Debug) bool

Remove a specific debug entry

remove_import(self, name: str) bool

Remove the imported library with the given name

remove_tls(self) None

Remove the TLS from the binary

property resources lief.PE.ResourceNode

Return the ResourceNode tree or None if not not present

property resources_manager lief.PE.ResourcesManager | lief.lief_errors

Return the ResourcesManager to manage resources

property rich_header lief.PE.RichHeader

RichHeader object (if present)

property rsrc_dir lief.PE.DataDirectory

Return the data directory associated with the resources tree

rva_to_offset(self, rva_address: int) int

Convert a relative virtual address to an offset

The conversion is performed by looking for the section that encompasses the provided RVA.

section_from_offset(self, offset: int) lief.PE.Section

Return the Section which encompasses the provided offset. It returns None if a section can’t be found.

section_from_rva(self, rva: int) lief.PE.Section

Return the Section which encompasses the provided relative virtual address. If a section can’t be found, it returns None.

property sections lief.PE.Binary.it_section

Return binary’s an iterator over the PE’s Section

set_export(self, arg: lief.PE.Export) lief.PE.Export

Add or replace the export table

set_resources(self, new_tree: lief.PE.ResourceNode) lief.PE.ResourceNode

Change or set the current resource tree with the new one provided in parameter.

property signatures lief.PE.Binary.it_const_signatures

Return an iterator over the Signature objects

property sizeof_headers int

Size of all the PE headers

property symbols lief.PE.Binary.it_symbols

Return binary’s Symbol

property tls lief.PE.TLS

TLS object (if present)

property tls_dir lief.PE.DataDirectory

Return the data directory associated with TLS

va_to_offset(self, va_address: int) int

Convert an absolute virtual address into an offset

See: rva_to_offset()

verify_signature(*args) lief.PE.Signature.VERIFICATION_FLAGS

Overloaded function.

  1. verify_signature(self, checks: lief._lief.PE.Signature.VERIFICATION_CHECKS = VERIFICATION_CHECKS.DEFAULT) -> lief._lief.PE.Signature.VERIFICATION_FLAGS

    Verify the binary against the embedded signature(s) (if any)

    First off, it checks that the embedded signatures are correct (c.f. lief.PE.Signature.check()) and then it checks that the authentihash matches lief.PE.ContentInfo.digest

    One can tweak the verification process with the lief.PE.Signature.VERIFICATION_CHECKS flags

  2. verify_signature(self, signature: lief._lief.PE.Signature, checks: lief._lief.PE.Signature.VERIFICATION_CHECKS = VERIFICATION_CHECKS.DEFAULT) -> lief._lief.PE.Signature.VERIFICATION_FLAGS

    Verify the binary with the Signature object provided in the first parameter It can be used to verify a detached signature:

    detached = lief.PE.Signature.parse("sig.pkcs7")
    binary.verify_signature(detached)
    
property virtual_size int

Return the binary’s virtual size.

This value should match sizeof_image

write(*args) lief.PE.Builder | None

Overloaded function.

  1. write(self, output_path: str) -> Optional[lief._lief.PE.Builder]

Build the binary and write the result in the given output file

  1. write(self, output_path: str, config: lief._lief.PE.Builder.config_t) -> Optional[lief._lief.PE.Builder]

Build the binary with the given config and write the result in the given output file

write_to_bytes(self) bytes

Dos Header

class lief.PE.DosHeader

Bases: Object

Class which represents the DosHeader, the first structure presents at the beginning of a PE file.

Most of the attributes of this structures are not relevant, except addressof_new_exeheader

property addressof_new_exeheader int
property addressof_relocation_table int
property checksum int
copy(self) lief.PE.DosHeader

Duplicate the current instance of this object

create(arg: lief.PE.PE_TYPE) lief.PE.DosHeader = <nanobind.nb_func object>
property file_size_in_pages int
property header_size_in_paragraphs int
property initial_ip int
property initial_relative_cs int
property initial_relative_ss int
property initial_sp int
property magic int
property maximum_extra_paragraphs int
property minimum_extra_paragraphs int
property numberof_relocation int
property oem_id int
property oem_info int
property overlay_number int
property used_bytes_in_last_page int


Optional Header

class lief.PE.OptionalHeader

Bases: Object

Class which represents the PE OptionalHeader structure.

class DLL_CHARACTERISTICS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntFlag

APPCONTAINER = 4096
DYNAMIC_BASE = 64
FORCE_INTEGRITY = 128
GUARD_CF = 16384
HIGH_ENTROPY_VA = 32
NO_BIND = 2048
NO_ISOLATION = 512
NO_SEH = 1024
NX_COMPAT = 256
TERMINAL_SERVER_AWARE = 32768
WDM_DRIVER = 8192
from_value(arg: int) lief.PE.OptionalHeader.DLL_CHARACTERISTICS = <nanobind.nb_func object>
class SUBSYSTEM(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

EFI_APPLICATION = 10
EFI_BOOT_SERVICE_DRIVER = 11
EFI_ROM = 13
EFI_RUNTIME_DRIVER = 12
NATIVE = 1
NATIVE_WINDOWS = 8
OS2_CUI = 5
POSIX_CUI = 7
UNKNOWN = 0
WINDOWS_BOOT_APPLICATION = 16
WINDOWS_CE_GUI = 9
WINDOWS_CUI = 3
WINDOWS_GUI = 2
XBOX = 14
from_value(arg: int) lief.PE.OptionalHeader.SUBSYSTEM = <nanobind.nb_func object>
add(self, characteristic: lief.PE.OptionalHeader.DLL_CHARACTERISTICS) None

Add the given DLL_CHARACTERISTICS

property addressof_entrypoint int

The address of the entry point relative to the image base when the executable file is loaded into memory. For program images, this is the starting address. For device drivers, this is the address of the initialization function.

An entry point is optional for DLLs. When no entry point is present, this field must be zero.

property baseof_code int

Address relative to the imagebase where the binary’s code starts

property baseof_data int

Address relative to the imagebase where the binary’s data starts.

Warning

This value is not present for PE64 files

property checksum int

The image file checksum. The algorithm for computing the checksum is incorporated into IMAGHELP.DLL. The following are checked for validation at load time all drivers, any DLL loaded at boot time, and any DLL that is loaded into a critical Windows process.

copy(self) lief.PE.OptionalHeader

Duplicate the current instance of this object

create(type: lief.PE.PE_TYPE) lief.PE.OptionalHeader = <nanobind.nb_func object>
property dll_characteristics int

Some characteristics (DLL_CHARACTERISTICS) of the underlying binary like the support of the PIE.

The prefix dll comes from the official PE specifications but these characteristics are also used for executables

property dll_characteristics_lists list[lief.PE.OptionalHeader.DLL_CHARACTERISTICS]

dll_characteristics as a list of DLL_CHARACTERISTICS

property file_alignment int

The alignment factor (in bytes) that is used to align the raw data of sections in the image file. The value should be a power of 2 between 512 and 64K, inclusive. The default value is 512. If the section_alignment is less than the architecture’s page size, then file_alignment must match section_alignment.

has(self, characteristics: lief.PE.OptionalHeader.DLL_CHARACTERISTICS) bool

True if the given DLL_CHARACTERISTICS is in the dll_characteristics

property imagebase int

The preferred base address when mapping the binary in memory

property loader_flags int

According to the PE specifications, this value is reserved and should be 0.

property magic lief.PE.PE_TYPE

Magic value (PE_TYPE) that identifies a PE32 from a PE64

property major_image_version int

The major version number of the image.

property major_linker_version int

The linker major version number

property major_operating_system_version int

The major version number of the required operating system.

property major_subsystem_version int

The major version number of the subsystem.

property minor_image_version int

The minor version number of the image.

property minor_linker_version int

The linker minor version number

property minor_operating_system_version int

The minor version number of the required operating system.

property minor_subsystem_version int

The minor version number of the subsystem

property numberof_rva_and_size int

The number of DataDirectory that follow this header

remove(self, characteristic: lief.PE.OptionalHeader.DLL_CHARACTERISTICS) None

Remove the given DLL_CHARACTERISTICS

property section_alignment int

The alignment (in bytes) of sections when they are loaded into memory. It must be greater than or equal to file_alignment and the default is the page size for the architecture.

property sizeof_code int

The size of the code .text section or the sum of all the sections that contain code (ie. Section with the flag CNT_CODE)

property sizeof_headers int

The combined size of an MS-DOS stub, PE header, and section headers rounded up to a multiple of file_alignment.

property sizeof_heap_commit int

The size of the local heap space to commit.

property sizeof_heap_reserve int

The size of the local heap space to reserve.

Only sizeof_heap_commit is available one page at a time until the reserve size is reached.

property sizeof_image int

The size (in bytes) of the image, including all headers, as the image is loaded in memory. It must be a multiple of section_alignment and should match virtual_size.

property sizeof_initialized_data int

The size of the initialized data which are usually located in the .data section. If the initialized data are split across multiple sections, it is the sum of the sections.

The sections associated with the initialized data are usually identified with the flag CNT_INITIALIZED_DATA

property sizeof_stack_commit int

The size of the stack to commit.

property sizeof_stack_reserve int

The size of the stack to reserve.

Only sizeof_stack_commit is committed, the rest is made available one page at a time until the reserve size is reached.

property sizeof_uninitialized_data int

The size of the uninitialized data which are usually located in the .bss section. If the uninitialized data are split across multiple sections, it is the sum of the sections.

The sections associated with the uninitialized data are usually identified with the flag CNT_UNINITIALIZED_DATA

property subsystem lief.PE.OptionalHeader.SUBSYSTEM

Target subsystem (SUBSYSTEM) like Driver, XBox, Windows GUI, ..

property win32_version_value int

Reserved, must be zero.


Data Directory

class lief.PE.DataDirectory(self)

Bases: Object

Class that represents a PE data directory entry

class TYPES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

ARCHITECTURE = 7
BASE_RELOCATION_TABLE = 5
BOUND_IMPORT = 11
CERTIFICATE_TABLE = 4
CLR_RUNTIME_HEADER = 14
DEBUG_DIR = 6
DELAY_IMPORT_DESCRIPTOR = 13
EXCEPTION_TABLE = 3
EXPORT_TABLE = 0
GLOBAL_PTR = 8
IAT = 12
IMPORT_TABLE = 1
LOAD_CONFIG_TABLE = 10
RESERVED = 15
RESOURCE_TABLE = 2
TLS_TABLE = 9
UNKNOWN = 16
from_value(arg: int) lief.PE.DataDirectory.TYPES = <nanobind.nb_func object>
property content memoryview

Raw content (bytes) referenced by this data directory

copy(self) lief.PE.DataDirectory

Duplicate the current instance of this object

property has_section bool

True if the current data directory is tied to a Section

property rva int

Relative virtual address of the content associated with the current data directory

property section lief.PE.Section

Section associated with the current data directory or None if not linked

property size int

Size in bytes of the content associated with the current data directory

property type lief.PE.DataDirectory.TYPES

Type (TYPES) of the current data directory


Section

Inheritance diagram of lief._lief.PE.Section
class lief.PE.Section(self)
class lief.PE.Section(self, name: str, content: collections.abc.Sequence[int])
class lief.PE.Section(self, name: str)

Bases: Section

Class which represents a PE section.

It extends the base class lief.Section

class CHARACTERISTICS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

ALIGN_1024BYTES = 11534336
ALIGN_128BYTES = 8388608
ALIGN_16BYTES = 5242880
ALIGN_1BYTES = 1048576
ALIGN_2048BYTES = 12582912
ALIGN_256BYTES = 9437184
ALIGN_2BYTES = 2097152
ALIGN_32BYTES = 6291456
ALIGN_4096BYTES = 13631488
ALIGN_4BYTES = 3145728
ALIGN_512BYTES = 10485760
ALIGN_64BYTES = 7340032
ALIGN_8192BYTES = 14680064
ALIGN_8BYTES = 4194304
CNT_CODE = 32
CNT_INITIALIZED_DATA = 64
CNT_UNINITIALIZED_DATA = 128
GPREL = 32768
LNK_COMDAT = 4096
LNK_INFO = 512
LNK_NRELOC_OVFL = 16777216
LNK_OTHER = 256
LNK_REMOVE = 2048
MEM_16BIT = 131072
MEM_DISCARDABLE = 33554432
MEM_EXECUTE = 536870912
MEM_LOCKED = 262144
MEM_NOT_CACHED = 67108864
MEM_NOT_PAGED = 134217728
MEM_PRELOAD = 524288
MEM_PURGEABLE = 65536
MEM_READ = 1073741824
MEM_SHARED = 268435456
MEM_WRITE = 2147483648
TYPE_NO_PAD = 8
from_value(arg: int) lief.PE.Section.CHARACTERISTICS = <nanobind.nb_func object>
property characteristics int

The CHARACTERISTICS that describe the characteristics of the section

property characteristics_lists list[lief.PE.Section.CHARACTERISTICS]

characteristics as a list

property coff_string lief.PE.COFFString

Return the COFF string associated with the section’s name (or None)

This coff string is usually present for long section names whose length does not fit in the 8 bytes allocated by the PE format.

copy(self) lief.PE.Section

Duplicate the current instance of this object

has_characteristic(self, characteristic: lief.PE.Section.CHARACTERISTICS) bool

True if the section has the given CHARACTERISTICS

property is_discardable bool

True if the section can be discarded as needed.

This is typically the case for debug-related sections.

property numberof_line_numbers int

The number of line-number entries for the section. This value should be zero for an image because COFF debugging information is deprecated.

See: pointerto_line_numbers

property numberof_relocations int

The number of relocation entries for the section.

See: pointerto_relocation

property padding bytes

Section padding content as bytes

property pointerto_line_numbers int

The file pointer to the beginning of line-number entries for the section. This is set to zero if there are no COFF line numbers. This value should be zero for an image because COFF debugging information is deprecated and modern debug information relies on the PDB files.

property pointerto_raw_data int

The offset of the section data in the PE file. Alias of offset

property pointerto_relocation int

The file pointer to the beginning of the COFF relocation entries for the section. This is set to zero for executable images or if there are no relocations.

For modern PE binaries, this value is usually set to 0 as the relocations are managed by Relocation.

property sizeof_raw_data int

Alias of size (size of the data in the section)

property virtual_size int

The total size of the section when loaded into memory.

If this value is greater than sizeof_raw_data, the section is zero-padded.


Import

class lief.PE.Import(self)
class lief.PE.Import(self, library_name: str)

Bases: Object

Class that represents a PE import

Overloaded function.

  1. __init__(self) -> None

Default constructor

  1. __init__(self, library_name: str) -> None

Constructor from a library name

add_entry(*args) lief.PE.ImportEntry

Add an ImportEntry (function) to the current import

property directory lief.PE.DataDirectory

Return the DataDirectory associated with this import.

It should be the one at index lief.PE.DataDirectory.TYPES.IMPORT_TABLE. It can return None if the Import directory can’t be resolved.

property entries lief.PE.Import.it_entries

Iterator over the ImportEntry (functions)

property forwarder_chain int

The index of the first forwarder reference

get_entry(self, function_name: str) lief.PE.ImportEntry

Return the ImportEntry with the given name or None if not found

get_function_rva_from_iat(self, function_name: str) int | lief.lief_errors

Return the relative virtual address of the given function within the Import Address Table

property iat_directory lief.PE.DataDirectory

Return the DataDirectory associated with the IAT table.

It should be the one at index lief.PE.DataDirectory.TYPES.IAT. It can return None if the IAT directory can’t be resolved.

property import_address_table_rva int

The RVA of the import address table (IAT). The content of this table is identical to the content of the Import Lookup Table (ILT) until the image is bound.

Warning

This address could change when re-building the binary

property import_lookup_table_rva int

The RVA of the import lookup table. This table contains the name or the ordinal for all the imports.

class it_entries

Bases: object

Iterator over lief._lief.PE.ImportEntry

property name str | bytes

Library name (e.g. kernel32.dll)

property name_rva int

The original name rva

remove_entry(*args) bool

Overloaded function.

  1. remove_entry(self, name: str) -> bool

    Remove the import entry with the given name.

    Return true if the deletion succeed, false otherwise

  2. remove_entry(self, ord: int) -> bool

    Remove the import entry with the given ordinal number

    Return True if the deletion succeed, false otherwise

property timedatestamp int

The stamp that is set to zero until the image is bound.

After the image is bound, this field is set to the time/data stamp of the DLL


Import Entry

Inheritance diagram of lief._lief.PE.ImportEntry
class lief.PE.ImportEntry(self)
class lief.PE.ImportEntry(self, import_name: str)
class lief.PE.ImportEntry(self, data: int, type: lief._lief.PE.PE_TYPE)

Bases: Symbol

Class that represents an entry (i.e. an import) in the import table (Import).

It extends the lief.Symbol generic class that provides the lief.Symbol.name and lief.Symbol.value

Overloaded function.

  1. __init__(self) -> None

  2. __init__(self, import_name: str) -> None

Constructor from a name

  1. __init__(self, data: int, type: lief._lief.PE.PE_TYPE) -> None

copy(self) lief.PE.ImportEntry

Duplicate the current instance of this object

property data int

Raw value

property demangled_name str

Demangled representation of the symbol or an empty string if it can’t be demangled.

property hint int

Index into the lief.PE.Export.entries that is used to speed-up the symbol resolution

property iat_address int

Original address of the entry in the Import Address Table

property iat_value int

Value of the current entry in the Import Address Table. It should match the lookup table value.

property ilt_value int

Original value in the import lookup table.

This value should match the iat_value

property is_ordinal bool

True if it is an import by ordinal

property name str | bytes

Import name if not ordinal

property ordinal int

Ordinal value (if any). See: is_ordinal


Delay Import

class lief.PE.DelayImport(self, library_name: str)

Bases: Object

Class that represents a PE delay import

Constructor from a library name

property attribute int

Reserved and should be zero according to the PE specifications

property biat int

RVA of the bound delay-load import address table or 0 if the table does not exist.

copy(self) lief.PE.DelayImport

Duplicate the current instance of this object

property entries lief.PE.DelayImport.it_entries

Iterator over the DelayImportEntry (functions)

property handle int

The RVA of the module handle (in the .data section) It is used for storage by the routine that is supplied to manage delay-loading.

property iat int

RVA of the delay-load import address table.

class it_entries

Bases: object

Iterator over lief._lief.PE.DelayImportEntry

property name str | bytes

Library name (e.g. kernel32.dll)

property names_table int

RVA of the delay-load import names table. The content of this table has the layout as the Import lookup table

property timestamp int

The timestamp of the DLL to which this image has been bound.

property uiat int

RVA of the unload delay-load import address table or 0 if the table does not exist.

According to the PE specifications, this table is an exact copy of the delay import address table that can be used to to restore the original IAT the case of unloading.


Delay Import Entry

Inheritance diagram of lief._lief.PE.DelayImportEntry
class lief.PE.DelayImportEntry(self)

Bases: Symbol

Class that represents an entry (i.e. a delay import) in the delay import table (DelayImport).

It extends the lief.Symbol generic class that provides the lief.Symbol.name and lief.Symbol.value

The meaning of lief.Symbol.value for this PE object is the address (as an RVA) in the IAT where the resolution should take place

copy(self) lief.PE.DelayImportEntry

Duplicate the current instance of this object

property data int

Raw value

property demangled_name str

Demangled representation of the symbol or an empty string if it can’t be demangled.

property hint int

Index into the lief.PE.Export.entries that is used to speed-up the symbol resolution

property iat_value int

Value of the current entry in the delay-loaded import address table. See: iat

property is_ordinal bool

True if it is an import by ordinal

property name str | bytes

Delay import name if not ordinal

property ordinal int

Ordinal value (if any). See: is_ordinal


TLS

class lief.PE.TLS(self)

Bases: Object

Class which represents the PE Thread Local Storage. This PE structure is also used to implement binary/library constructors.

Default constructor

add_callback(self, addr: int) lief.PE.TLS

Add a new TLS callback

property addressof_callbacks int

Pointer to an array of TLS callback functions.

The array is null-terminated, so if there is no callback, this field points to 4 bytes set to zero.

See: callbacks

property addressof_index int

The location to receive the TLS index assigned by the loader. This location should be located in a writable section like .data.

property addressof_raw_data tuple[int, int]

Tuple (start address, end address) of the TLS template. The template is a block of data that is used to initialize TLS data. The system copies all of this data each time a thread is created, so it must not be corrupted.

Note

These addresses are not RVA. It is addresses for which there should be a base relocation in the .reloc section.

property callbacks list[int]

List of the callbacks associated with the current TLS.

These functions are called before any other functions.

property characteristics int

The four bits [23:20] describe alignment info. Possible values are those defined as IMAGE_SCN_ALIGN_*, which are also used to describe alignment of section in object files. The other 28 bits are reserved for future use.

copy(self) lief.PE.TLS

Duplicate the current instance of this object

property data_template memoryview

The initial content used to initialize TLS data.

property directory lief.PE.DataDirectory

DataDirectory associated with the TLS object (or None if not linked)

property has_data_directory bool

True if there is a DataDirectory associated with the TLS object

property has_section bool

True if there is a Section associated with the TLS object

property section lief.PE.Section

Section associated with the TLS object (or None if not linked)

property sizeof_zero_fill int

Size in bytes of the zeros to be padded after the data specified by data_template.


Symbol

Inheritance diagram of lief._lief.PE.Symbol
class lief.PE.Symbol

Bases: Symbol

Class that represents a PE-COFF symbol.

Usually PE debug information (including symbols) are wrapped in a PDB file referenced by the lief.PE.CodeViewPDB object.

The PE format allows to define (by COFF inheritance) a symbol table that is different from the regular PDB symbols. This table contains COFF(16) symbols which can reference auxiliary symbols.

Warning

The lief.Symbol.value should be interpreted in perspective of the storage_class

Reference: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#coff-symbol-table

class BASE_TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

BYTE = 12
CHAR = 2
DOUBLE = 7
DWORD = 15
ENUM = 10
FLOAT = 6
INT = 4
LONG = 5
MOE = 11
NULL = 0
SHORT = 3
STRUCT = 8
UINT = 14
UNION = 9
VOID = 1
WORD = 13
from_value(arg: int) lief.PE.Symbol.BASE_TYPE = <nanobind.nb_func object>
class COMPLEX_TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

ARRAY = 3
FUNCTION = 2
NULL = 0
POINTER = 1
from_value(arg: int) lief.PE.Symbol.COMPLEX_TYPE = <nanobind.nb_func object>
class STORAGE_CLASS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Reference: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#storage-class

ARGUMENT = 9
AUTOMATIC = 1
BIT_FIELD = 18
BLOCK = 100
CLR_TOKEN = 107
END_OF_FUNCTION = -1
END_OF_STRUCT = 102
ENUM_TAG = 15
EXTERNAL = 2
EXTERNAL_DEF = 5
FILE = 103
FUNCTION = 101
LABEL = 6
MEMBER_OF_ENUM = 16
MEMBER_OF_STRUCT = 8
MEMBER_OF_UNION = 11
NONE = 0
REGISTER = 4
REGISTER_PARAM = 17
SECTION = 104
STATIC = 3
STRUCT_TAG = 10
TYPE_DEFINITION = 13
UNDEFINED_LABEL = 7
UNDEFINED_STATIC = 14
UNION_TAG = 12
WEAK_EXTERNAL = 105
from_value(arg: int) lief.PE.Symbol.STORAGE_CLASS = <nanobind.nb_func object>
property auxiliary_symbols lief.PE.Symbol.it_auxiliary_symbols_t

Auxiliary symbols associated with this symbol.

property base_type lief.PE.Symbol.BASE_TYPE

The simple (base) data type

property coff_name lief.PE.COFFString

COFF string used to represents the (long) symbol name

property complex_type lief.PE.Symbol.COMPLEX_TYPE

The complex type (if any)

property is_external bool
property is_file_record bool
property is_function_line_info bool
property is_undefined bool
property is_weak_external bool
class it_auxiliary_symbols_t

Bases: object

Iterator over lief._lief.PE.AuxiliarySymbol

property section_idx int

The signed integer that identifies the section, using a one-based index into the section table. Some values have special meaning:

  • 0: The symbol record is not yet assigned a section. A value of zero

    indicates that a reference to an external symbol is defined elsewhere. A value of non-zero is a common symbol with a size that is specified by the value.

  • -1: The symbol has an absolute (non-relocatable) value and is not an

    address.

  • -2: The symbol provides general type or debugging information but does

    not correspond to a section. Microsoft tools use this setting along with .file records

property storage_class lief.PE.Symbol.STORAGE_CLASS

Storage class of the symbol which indicates what kind of definition a symbol represents.

property type int

The symbol type. The first byte represents the base type (see: base_type) while the upper byte represents the complex type, if any (see: complex_type).


AuxiliarySymbol

Inheritance diagram of lief._lief.PE.AuxiliarySymbol, lief._lief.PE.AuxiliaryFunctionDefinition, lief._lief.PE.AuxiliaryWeakExternal, lief._lief.PE.AuxiliaryCLRToken, lief._lief.PE.AuxiliaryFile, lief._lief.PE.AuxiliarybfAndefSymbol, lief._lief.PE.AuxiliarySectionDefinition
class lief.PE.AuxiliarySymbol

Bases: object

Class that represents an auxiliary symbol.

An auxiliary symbol has the same size as a regular lief.PE.Symbol (18 bytes) but its content depends on the the parent symbol.

class TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Type discriminator for the subclasses

BF_AND_EF = 3
CLR_TOKEN = 1
FILE = 5
FUNC_DEF = 2
SEC_DEF = 6
UNKNOWN = 0
WEAK_EXTERNAL = 4
from_value(arg: int) lief.PE.AuxiliarySymbol.TYPE = <nanobind.nb_func object>
copy(self) lief.PE.AuxiliarySymbol | None

Duplicate the current instance of this object

property payload memoryview

For unknown type only, return the raw representation of this symbol

property type lief.PE.AuxiliarySymbol.TYPE

AuxiliaryCLRToken

Inheritance diagram of lief._lief.PE.AuxiliaryCLRToken
class lief.PE.AuxiliarySymbol

Bases: object

Class that represents an auxiliary symbol.

An auxiliary symbol has the same size as a regular lief.PE.Symbol (18 bytes) but its content depends on the the parent symbol.

class TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Type discriminator for the subclasses

BF_AND_EF = 3
CLR_TOKEN = 1
FILE = 5
FUNC_DEF = 2
SEC_DEF = 6
UNKNOWN = 0
WEAK_EXTERNAL = 4
from_value(arg: int) lief.PE.AuxiliarySymbol.TYPE = <nanobind.nb_func object>
copy(self) lief.PE.AuxiliarySymbol | None

Duplicate the current instance of this object

property payload memoryview

For unknown type only, return the raw representation of this symbol

property type lief.PE.AuxiliarySymbol.TYPE

AuxiliaryFunctionDefinition

Inheritance diagram of lief._lief.PE.AuxiliaryFunctionDefinition
class lief.PE.AuxiliaryFunctionDefinition

Bases: AuxiliarySymbol

This auxiliary symbol marks the beginning of a function definition.

Reference: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#auxiliary-format-1-function-definitions

property padding int

Padding value (should be 0)

property ptr_to_line_number int

The file offset of the first COFF line-number entry for the function, or zero if none exists (deprecated)

property ptr_to_next_func int

The symbol-table index of the record for the next function. If the function is the last in the symbol table, this field is set to zero

property tag_index int

The symbol-table index of the corresponding .bf (begin function) symbol record.

property total_size int

The size of the executable code for the function itself.

If the function is in its own section, the SizeOfRawData in the section header is greater or equal to this field, depending on alignment consideration


AuxiliaryWeakExternal

Inheritance diagram of lief._lief.PE.AuxiliaryWeakExternal
class lief.PE.AuxiliaryWeakExternal

Bases: AuxiliarySymbol

“Weak externals” are a mechanism for object files that allows flexibility at link time. A module can contain an unresolved external symbol (sym1), but it can also include an auxiliary record that indicates that if sym1 is not present at link time, another external symbol (sym2) is used to resolve references instead.

If a definition of sym1 is linked, then an external reference to the symbol is resolved normally. If a definition of sym1 is not linked, then all references to the weak external for sym1 refer to sym2 instead. The external symbol, sym2, must always be linked; typically, it is defined in the module that contains the weak reference to sym1.

Reference: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#auxiliary-format-3-weak-externals

class CHARACTERISTICS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

ANTI_DEPENDENCY = 4
SEARCH_ALIAS = 3
SEARCH_LIBRARY = 2
SEARCH_NOLIBRARY = 1
property characteristics lief.PE.AuxiliaryWeakExternal.CHARACTERISTICS
property padding memoryview
property sym_idx int

The symbol-table index of sym2, the symbol to be linked if sym1 is not found.


AuxiliarybfAndefSymbol

Inheritance diagram of lief._lief.PE.AuxiliarybfAndefSymbol
class lief.PE.AuxiliarybfAndefSymbol

Bases: AuxiliarySymbol


AuxiliarySectionDefinition

Inheritance diagram of lief._lief.PE.AuxiliarySectionDefinition
class lief.PE.AuxiliarySectionDefinition

Bases: AuxiliarySymbol

This auxiliary symbol exposes information about the associated section.

It duplicates some information that are provided in the section header

property checksum int

The checksum for communal data. It is applicable if the IMAGE_SCN_LNK_COMDAT flag is set in the section header.

property length int

The size of section data. The same as SizeOfRawData in the section header.

property nb_line_numbers int

The number of line-number entries for the section.

property nb_relocs int

The number of relocation entries for the section.

property section_idx int

One-based index into the section table for the associated section. This is used when the COMDAT selection setting is 5.

property selection int

The COMDAT selection number. This is applicable if the section is a COMDAT section.


AuxiliaryFile

Inheritance diagram of lief._lief.PE.AuxiliaryFile
class lief.PE.AuxiliaryFile

Bases: AuxiliarySymbol

This auxiliary symbol represents a filename (auxiliary format 4)

The lief.Symbol.name itself should start with .file, and this auxiliary record gives the name of a source-code file.

Reference: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#auxiliary-format-4-files

property filename str

The associated filename


Relocation

class lief.PE.Relocation(self)

Bases: Object

Class which represents the Base Relocation Block Usually, we find this structure in the .reloc section

add_entry(self, new_entry: lief.PE.RelocationEntry) lief.PE.RelocationEntry

Add a new RelocationEntry

property block_size int

The total number of bytes in the base relocation block. block_size = sizeof(BaseRelocationBlock) + nb_of_relocs * sizeof(uint16_t = RelocationEntry)

copy(self) lief.PE.Relocation

Duplicate the current instance of this object

property entries lief.PE.Relocation.it_entries

Iterator over the RelocationEntry

class it_entries

Bases: object

Iterator over lief._lief.PE.RelocationEntry

property virtual_address int

The RVA for which the offset of the relocation entries (RelocationEntry) is added


Relocation Entry

Inheritance diagram of lief._lief.PE.RelocationEntry
class lief.PE.RelocationEntry(self)
class lief.PE.RelocationEntry(self, arg0: int, arg1: lief._lief.PE.RelocationEntry.BASE_TYPES, /)

Bases: Relocation

Class which represents an entry of the PE relocation table.

It extends the lief.Relocation object to provide an uniform API across the file formats.

class BASE_TYPES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

ABS = 0
ARM_MOV32 = 517
DIR64 = 10
HIGH = 1
HIGH3ADJ = 11
HIGHADJ = 4
HIGHLOW = 3
LOW = 2
MIPS_JMPADDR = 261
MIPS_JMPADDR16 = 9
RISCV_HI20 = 1029
RISCV_LOW12I = 4103
RISCV_LOW12S = 8200
SECTION = 6
THUMB_MOV32 = 2055
UNKNOWN = -1
from_value(arg: int) lief.PE.RelocationEntry.BASE_TYPES = <nanobind.nb_func object>
property data int

Raw data of the relocation:

  • The high 4 bits store the relocation type

  • The low 12 bits store the relocation offset (position)

property position int

Offset - relative to virtual_address - where the relocation occurs

property type lief.PE.RelocationEntry.BASE_TYPES

Type of the relocation


Export

class lief.PE.Export(self)
class lief.PE.Export(self, name: str, entries: collections.abc.Sequence[lief._lief.PE.ExportEntry])

Bases: Object

Class which represents a PE Export

Overloaded function.

  1. __init__(self) -> None

Default constructor

  1. __init__(self, name: str, entries: collections.abc.Sequence[lief._lief.PE.ExportEntry]) -> None

Constructor from DLL name and its exports

add_entry(*args) lief.PE.ExportEntry

Add the given export and return the newly created and added entry

copy(self) lief.PE.Export

Duplicate the current instance of this object

property entries lief.PE.Export.it_entries

Iterator over the ExportEntry

property export_addr_table_cnt int

Number of entries in the export address table

property export_addr_table_rva int

RVA of the export address table

property export_flags int

According to the PE specifications this value is reserved and should be set to 0

find_entry(*args) lief.PE.ExportEntry

Overloaded function.

  1. find_entry(self, name: str) -> lief._lief.PE.ExportEntry

Find the export with the given name

  1. find_entry(self, ordinal: int) -> lief._lief.PE.ExportEntry

Find the export entry with the given ordinal number

find_entry_at(self, rva_addr: int) lief.PE.ExportEntry

Find the export entry at the provided RVA

class it_entries

Bases: object

Iterator over lief._lief.PE.ExportEntry

property major_version int

The major version number (can be user-defined)

property minor_version int

The minor version number (can be user-defined)

property name str | bytes

The name of the library exported (e.g. KERNEL32.dll)

property name_rva int

Address of the ASCII DLL’s name (RVA)

property names_addr_table_cnt int

Number of exports by name

property names_addr_table_rva int

RVA to the list of exported names

property ord_addr_table_rva int

RVA to the list of exported ordinals

property ordinal_base int

The starting number for the exports. Usually this value is set to 1

remove_entry(*args) bool

Overloaded function.

  1. remove_entry(self, entry: lief._lief.PE.ExportEntry) -> bool

Remove the given export entry

  1. remove_entry(self, name: str) -> bool

Remove the export entry with the given name

  1. remove_entry(self, rva: int) -> bool

Remove the export entry with the given RVA

property timestamp int

The time and date that the export data was created


Export Entry

Inheritance diagram of lief._lief.PE.ExportEntry
class lief.PE.ExportEntry(self)
class lief.PE.ExportEntry(self, name: str, addr: int)

Bases: Symbol

Class which represents a PE Export entry (cf. lief.PE.Export)

Overloaded function.

  1. __init__(self) -> None

Default constructor

  1. __init__(self, name: str, addr: int) -> None

Constructor with export name and address

property address int
property demangled_name str

Demangled representation of the symbol or an empty string if it can’t be demangled.

property forward_information lief.PE.ExportEntry.forward_information_t
class forward_information_t

Bases: object

property function str
property library str
property function_rva int
property is_extern bool
property is_forwarded bool
property name str | bytes
property ordinal int

Signature

class lief.PE.Signature

Bases: Object

class VERIFICATION_CHECKS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

Flags to tweak the verification process of the signature See lief.PE.Signature.check() and lief.PE.Binary.verify_signature()

DEFAULT = 1
HASH_ONLY = 2
LIFETIME_SIGNING = 4
SKIP_CERT_TIME = 8
from_value(arg: int) lief.PE.Signature.VERIFICATION_CHECKS = <nanobind.nb_func object>
class VERIFICATION_FLAGS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

BAD_DIGEST = 128
BAD_SIGNATURE = 256
CERT_EXPIRED = 1024
CERT_FUTURE = 2048
CERT_NOT_FOUND = 8
CORRUPTED_AUTH_DATA = 32
CORRUPTED_CONTENT_INFO = 16
INCONSISTENT_DIGEST_ALGORITHM = 4
INVALID_SIGNER = 1
MISSING_PKCS9_MESSAGE_DIGEST = 64
NO_SIGNATURE = 512
OK = 0
UNSUPPORTED_ALGORITHM = 2
from_value(arg: int) lief.PE.Signature.VERIFICATION_FLAGS = <nanobind.nb_func object>
property certificates lief.PE.Signature.it_const_crt

Return an iterator over x509 certificates

check(self, checks: lief.PE.Signature.VERIFICATION_CHECKS) lief.PE.Signature.VERIFICATION_FLAGS

Check the integrity of the signature and return a lief.PE.Signature.VERIFICATION_FLAGS

By default, it performs the following verifications:

  1. It must contain only one signer info (signers)

  2. lief.PE.Signature.digest_algorithm must match:

  3. The x509 certificate specified by lief.PE.SignerInfo.serial_number and lief.PE.SignerInfo.issuer must exist within lief.PE.Signature.certificates

  4. Given the x509 certificate, compare lief.PE.SignerInfo.encrypted_digest against either:

  5. If they are Authenticated attributes, check that a PKCS9_MESSAGE_DIGEST (lief.PE.PKCS9MessageDigest) attribute exists and that its value matches hash of ContentInfo

  6. Check the validity of the PKCS #9 counter signature if present

  7. If the signature doesn’t embed a signing-time in the counter signature, check the certificate validity. (See lief.PE.Signature.VERIFICATION_CHECKS.LIFETIME_SIGNING and lief.pe.Signature.VERIFICATION_CHECKS.SKIP_CERT_TIME)

See: lief.PE.Signature.VERIFICATION_CHECKS to tweak the behavior

property content_info lief.PE.ContentInfo

Return the ContentInfo

property digest_algorithm lief.PE.ALGORITHMS

Return the algorithm (ALGORITHMS) used to sign the content of ContentInfo

find_crt(self, serialno: collections.abc.Sequence[int]) lief.PE.x509

Find the x509 certificate according to its serial number

find_crt_issuer(*args) lief.PE.x509

Overloaded function.

  1. find_crt_issuer(self, issuer: str) -> lief._lief.PE.x509

Find the x509 certificate according to its issuer

  1. find_crt_issuer(self, issuer: str, serialno: collections.abc.Sequence[int]) -> lief._lief.PE.x509

Find the x509 certificate according to its issuer AND its serial number

find_crt_subject(*args) lief.PE.x509

Overloaded function.

  1. find_crt_subject(self, subject: str) -> lief._lief.PE.x509

Find the x509 certificate according to its subject

  1. find_crt_subject(self, subject: str, serialno: collections.abc.Sequence[int]) -> lief._lief.PE.x509

Find the x509 certificate according to its subject AND its serial number

class it_const_crt

Bases: object

Iterator over lief._lief.PE.x509

class it_const_signers_t

Bases: object

Iterator over lief._lief.PE.SignerInfo

parse(*args) lief.PE.Signature | None = <nanobind.nb_func object>
property raw_der memoryview

Return the raw original signature as a byte object

property signers lief.PE.Signature.it_const_signers_t

Return an iterator over the signers (SignerInfo)

property version int

Version of the signature. It should be 1


Signature Attribute

Inheritance diagram of lief._lief.PE.GenericType, lief._lief.PE.MsSpcNestedSignature, lief._lief.PE.SpcSpOpusInfo, lief._lief.PE.MsSpcStatementType, lief._lief.PE.MsManifestBinaryID, lief._lief.PE.PKCS9AtSequenceNumber, lief._lief.PE.SigningCertificateV2, lief._lief.PE.SpcRelaxedPeMarkerCheck, lief._lief.PE.PKCS9CounterSignature, lief._lief.PE.Attribute, lief._lief.PE.MsCounterSign, lief._lief.PE.PKCS9MessageDigest, lief._lief.PE.ContentType, lief._lief.PE.PKCS9SigningTime
class lief.PE.Attribute

Bases: Object

Interface over PKCS #7 attribute

class TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

CONTENT_TYPE = 1
GENERIC_TYPE = 2
MS_COUNTER_SIGN = 6
MS_PLATFORM_MANIFEST_BINARY_ID = 9
MS_SPC_NESTED_SIGN = 7
MS_SPC_STATEMENT_TYPE = 8
PKCS9_AT_SEQUENCE_NUMBER = 10
PKCS9_COUNTER_SIGNATURE = 11
PKCS9_MESSAGE_DIGEST = 12
PKCS9_SIGNING_TIME = 13
SIGNING_CERTIFICATE_V2 = 3
SPC_RELAXED_PE_MARKER_CHECK = 5
SPC_SP_OPUS_INFO = 4
UNKNOWN = 0
from_value(arg: int) lief.PE.Attribute.TYPE = <nanobind.nb_func object>
property type lief.PE.Attribute.TYPE

Concrete type of the attribute


Signature ContentType

Inheritance diagram of lief._lief.PE.ContentType
class lief.PE.ContentType

Bases: Attribute

Interface over the structure described by the OID 1.2.840.113549.1.9.3 (PKCS #9) The internal structure is described in the: RFC #2985: PKCS #9 - Selected Object Classes and Attribute Types Version 2.0

ContentType ::= OBJECT IDENTIFIER
property oid str

OID as described in RFC #2985 (string object)


Signature GenericType

Inheritance diagram of lief._lief.PE.GenericType
class lief.PE.GenericType

Bases: Attribute

Interface over an attribute for which the internal structure is not supported by LIEF

property oid str

OID of the original attribute

property raw_content memoryview

Original DER blob of the attribute


Signature MsSpcNestedSignature

Inheritance diagram of lief._lief.PE.MsSpcNestedSignature
class lief.PE.MsSpcNestedSignature

Bases: Attribute

Interface over the structure described by the OID 1.3.6.1.4.1.311.2.4.1

The internal structure is not documented but we can infer the following structure:

MsSpcNestedSignature ::= SET OF SignedData

With SignedData, the structure described in PKCS #7 RFC (See: lief.PE.Signature)

property signature lief.PE.Signature

Underlying Signature object


Signature MsSpcStatementType

Inheritance diagram of lief._lief.PE.MsSpcStatementType
class lief.PE.MsSpcStatementType

Bases: Attribute

Interface over the structure described by the OID 1.3.6.1.4.1.311.2.1.11

The internal structure is described in the official document: Windows Authenticode Portable Executable Signature Format

SpcStatementType ::= SEQUENCE of OBJECT IDENTIFIER
property oid str

According to the documentation:

The SpcStatementType MUST contain one Object Identifier with either
the value ``1.3.6.1.4.1.311.2.1.21 (SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID)`` or
``1.3.6.1.4.1.311.2.1.22 (SPC_COMMERCIAL_SP_KEY_PURPOSE_OBJID)``.

Signature PKCS9AtSequenceNumber

Inheritance diagram of lief._lief.PE.PKCS9AtSequenceNumber
class lief.PE.PKCS9AtSequenceNumber

Bases: Attribute

Interface over the structure described by the OID 1.2.840.113549.1.9.25.4 (PKCS #9)

The internal structure is described in the RFC #2985: PKCS #9 - Selected Object Classes and Attribute Types Version 2.0

sequenceNumber ATTRIBUTE ::= {
  WITH SYNTAX SequenceNumber
  EQUALITY MATCHING RULE integerMat
  SINGLE VALUE TRUE
  ID pkcs-9-at-sequenceNumber
}

SequenceNumber ::= INTEGER (1..MAX)
property number int

Number as described in the RFC


Signature PKCS9CounterSignature

Inheritance diagram of lief._lief.PE.PKCS9CounterSignature
class lief.PE.PKCS9CounterSignature

Bases: Attribute

Interface over the structure described by the OID 1.2.840.113549.1.9.6 (PKCS #9)

The internal structure is described in the RFC #2985: PKCS #9 - Selected Object Classes and Attribute Types Version 2.0

counterSignature ATTRIBUTE ::= {
  WITH SYNTAX SignerInfo
  ID pkcs-9-at-counterSignature
}
property signer lief.PE.SignerInfo

Return the SignerInfo as described in the RFC #2985


Signature PKCS9MessageDigest

Inheritance diagram of lief._lief.PE.PKCS9MessageDigest
class lief.PE.PKCS9MessageDigest

Bases: Attribute

Interface over the structure described by the OID 1.2.840.113549.1.9.4 (PKCS #9)

The internal structure is described in the RFC #2985: PKCS #9 - Selected Object Classes and Attribute Types Version 2.0

messageDigest ATTRIBUTE ::= {
  WITH SYNTAX MessageDigest
  EQUALITY MATCHING RULE octet
  SINGLE VALUE TRUE
  ID pkcs-9-at-messageDigest
}

MessageDigest ::= OCTET STRING
property digest bytes

Message digeset as a blob of bytes as described in the RFC


Signature PKCS9SigningTime

Inheritance diagram of lief._lief.PE.PKCS9SigningTime
class lief.PE.PKCS9SigningTime

Bases: Attribute

Interface over the structure described by the OID 1.2.840.113549.1.9.5 (PKCS #9)

The internal structure is described in the RFC #2985: PKCS #9 - Selected Object Classes and Attribute Types Version 2.0

signingTime ATTRIBUTE ::= {
        WITH SYNTAX SigningTime
        EQUALITY MATCHING RULE signingTimeMatch
        SINGLE VALUE TRUE
        ID pkcs-9-at-signingTime
}

SigningTime ::= Time -- imported from ISO/IEC 9594-8
property time list[int]

Time as a list [year, month, day, hour, min, sec]


Signature SpcSpOpusInfo

Inheritance diagram of lief._lief.PE.SpcSpOpusInfo
class lief.PE.SpcSpOpusInfo

Bases: Attribute

Interface over the structure described by the OID 1.3.6.1.4.1.311.2.1.12 The internal structure is described in the official document: Windows Authenticode Portable Executable Signature Format

SpcSpOpusInfo ::= SEQUENCE {
    programName  [0] EXPLICIT SpcString OPTIONAL,
    moreInfo     [1] EXPLICIT SpcLink OPTIONAL
}
property more_info str | bytes

Other information such as an URL

property program_name str | bytes

Program description provided by the publisher


Signature SpcIndirectData

Inheritance diagram of lief._lief.PE.SpcIndirectData
class lief.PE.SpcIndirectData

Bases: Content

property digest memoryview
property digest_algorithm lief.PE.ALGORITHMS

Digest used to hash the file. This should match digest_algorithm

property file str
property url str

GenericContent

Inheritance diagram of lief._lief.PE.GenericContent
class lief.PE.GenericContent

Bases: Content


RsaInfo

class lief.PE.RsaInfo

Bases: object

Object representing a RSA key

property D bytes

RSA private exponent (in bytes)

property E bytes

RSA public exponent (in bytes)

property N bytes

RSA public modulus (in bytes)

property P bytes

First prime factor (in bytes)

property Q bytes

Second prime factor (in bytes)

property has_private_key bool

True if it embeds a private key

property has_public_key bool

True if it embeds a public key

property key_size int

Size of the public modulus in bits


x509

class lief.PE.x509

Bases: Object

Interface over a x509 certificate

class KEY_TYPES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Public key scheme used by the x509 certificate

ECDSA = 4
ECKEY = 2
ECKEY_DH = 3
NONE = 0
RSA = 1
RSASSA_PSS = 6
RSA_ALT = 5
from_value(arg: int) lief.PE.x509.KEY_TYPES = <nanobind.nb_func object>
class KEY_USAGE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Key usage as defined in RFC #5280 - section-4.2.1.3

CRL_SIGN = 6
DATA_ENCIPHERMENT = 3
DECIPHER_ONLY = 8
DIGITAL_SIGNATURE = 0
ENCIPHER_ONLY = 7
KEY_AGREEMENT = 4
KEY_CERT_SIGN = 5
KEY_ENCIPHERMENT = 2
NON_REPUDIATION = 1
from_value(arg: int) lief.PE.x509.KEY_USAGE = <nanobind.nb_func object>
class VERIFICATION_FLAGS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

Verification flags associated with verify

BADCERT_BAD_KEY = 65536
BADCERT_BAD_MD = 16384
BADCERT_BAD_PK = 32768
BADCERT_CN_MISMATCH = 4
BADCERT_EXPIRED = 1
BADCERT_EXT_KEY_USAGE = 4096
BADCERT_FUTURE = 512
BADCERT_KEY_USAGE = 2048
BADCERT_MISSING = 64
BADCERT_NOT_TRUSTED = 8
BADCERT_NS_CERT_TYPE = 8192
BADCERT_OTHERNATURE = 256
BADCERT_REVOKED = 2
BADCERT_SKIP_VERIFY = 128
BADCRL_BAD_KEY = 524288
BADCRL_BAD_MD = 131072
BADCRL_BAD_PK = 262144
BADCRL_EXPIRED = 32
BADCRL_FUTURE = 1024
BADCRL_NOT_TRUSTED = 16
OK = 0
from_value(arg: int) lief.PE.x509.VERIFICATION_FLAGS = <nanobind.nb_func object>
property certificate_policies list[str]

Policy information terms as list of OID (see RFC #5280)

property ext_key_usage list[str]

Indicates one or more purposes for which the certified public key may be used (list of OID)

property is_ca bool
is_trusted_by(self, ca_list: collections.abc.Sequence[lief.PE.x509]) lief.PE.x509.VERIFICATION_FLAGS

Verify this certificate against a list of root CA (list of x509 objects) It returns a set of flags defined by VERIFICATION_FLAGS

Example:
signer = binary.signatures[0].signers[0]
microsoft_ca_bundle = lief.PE.x509.parse("bundle.pem")
print(signer.cert.is_trusted_by(microsoft_ca_bundle))
property issuer str | bytes

Issuer of the certificate

property key_type lief.PE.x509.KEY_TYPES

Return the underlying public-key scheme (KEY_TYPES)

property key_usage list[lief.PE.x509.KEY_USAGE]

Purpose of the key contained in the certificate (see KEY_USAGE)

parse(*args) list[lief.PE.x509] = <nanobind.nb_func object>
property raw bytes

The raw bytes associated with this x509 cert (DER encoded)

property rsa_info lief.PE.RsaInfo | None

If the underlying public-key scheme is RSA, return the RsaInfo associated with this certificate. Otherwise, return None

property serial_number bytes

Unique id for certificate issued by a specific CA.

property signature bytes

The signature of the certificate

property signature_algorithm str

Signature algorithm (OID)

property subject str | bytes

Subject of the certificate

property valid_from list[int]

Start time of certificate validity

property valid_to list[int]

End time of certificate validity

verify(self, ca: lief.PE.x509) lief.PE.x509.VERIFICATION_FLAGS

Verify that this certificate has been used to trust the given x509 certificate

It returns a set of flags defined by VERIFICATION_FLAGS

Example:
ca     = lief.PE.x509.parse("ca.crt")[0]
signer = lief.PE.x509.parse("signer.crt")[0]
print(ca.verify(signer))  # lief.PE.x509.VERIFICATION_FLAGS.OK
property version int

X.509 version. (1=v1, 2=v2, 3=v3)


ContentInfo

Inheritance diagram of lief._lief.PE.PKCS9TSTInfo, lief._lief.PE.SpcIndirectData, lief._lief.PE.GenericContent
class lief.PE.ContentInfo

Bases: Object

ContentInfo as described in the RFC 2315

ContentInfo ::= SEQUENCE {
  contentType ContentType,
  content     [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
}

ContentType ::= OBJECT IDENTIFIER

In the case of PE signature, ContentType must be set to SPC_INDIRECT_DATA_OBJID OID: 1.3.6.1.4.1.311.2.1.4 and content is defined by the structure: SpcIndirectDataContent

SpcIndirectDataContent ::= SEQUENCE {
 data          SpcAttributeTypeAndOptionalValue,
 messageDigest DigestInfo
}

SpcAttributeTypeAndOptionalValue ::= SEQUENCE {
 type  ObjectID,
 value [0] EXPLICIT ANY OPTIONAL
}

For PE signature, SpcAttributeTypeAndOptionalValue.type is set to SPC_PE_IMAGE_DATAOBJ (OID: 1.3.6.1.4.1.311.2.1.15) and the value is defined by SpcPeImageData

DigestInfo ::= SEQUENCE {
 digestAlgorithm  AlgorithmIdentifier,
 digest           OCTETSTRING
}

AlgorithmIdentifier ::= SEQUENCE {
 algorithm  ObjectID,
 parameters [0] EXPLICIT ANY OPTIONAL
}
class Content

Bases: Object

property content_type str

OID of the content type. This value should match SPC_INDIRECT_DATA_OBJID

copy(self) lief.PE.ContentInfo.Content | None

Duplicate the current instance of this object

property content_type str

An alias for content_type

copy(self) lief.PE.ContentInfo

Duplicate the current instance of this object

property digest bytes

Return the digest (authentihash) if the underlying content type is SPC_INDIRECT_DATA_OBJID. Return empty bytes otherwise.

property digest_algorithm lief.PE.ALGORITHMS

Return the hash algorithm used to generate the digest

property value lief.PE.ContentInfo.Content

SignerInfo

class lief.PE.SignerInfo

Bases: Object

SignerInfo as described in the RFC 2315 #Section 9.2

SignerInfo ::= SEQUENCE {
 version                   Version,
 issuerAndSerialNumber     IssuerAndSerialNumber,
 digestAlgorithm           DigestAlgorithmIdentifier,
 authenticatedAttributes   [0] IMPLICIT Attributes OPTIONAL,
 digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
 encryptedDigest           EncryptedDigest,
 unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
}

EncryptedDigest ::= OCTET STRING
property authenticated_attributes lief.PE.SignerInfo.it_const_attributes_t

Return an iterator over the authenticated attributes (Attribute)

property cert lief.PE.x509

x509 certificate used by this signer. If it can’t be found, it returns None

property digest_algorithm lief.PE.ALGORITHMS

Algorithm (ALGORITHMS) used to hash the file. This value should match ContentInfo.digest_algorithm and Signature.digest_algorithm

property encrypted_digest bytes

Return the signature created by the signing certificate’s private key

property encryption_algorithm lief.PE.ALGORITHMS

Return algorithm (ALGORITHMS) used to encrypt the digest

get_attribute(self, type: lief.PE.Attribute.TYPE) lief.PE.Attribute

Return the authenticated or un-authenticated attribute matching the given lief.PE.SIG_ATTRIBUTE_TYPES It returns the first entry that matches the given type. If it can’t be found, it returns None

get_auth_attribute(self, type: lief.PE.Attribute.TYPE) lief.PE.Attribute

Return the authenticated attribute matching the given lief.PE.SIG_ATTRIBUTE_TYPES It returns the first entry that matches the given type. If it can’t be found, it returns None

get_unauth_attribute(self, type: lief.PE.Attribute.TYPE) lief.PE.Attribute

Return the un-authenticated attribute matching the given lief.PE.SIG_ATTRIBUTE_TYPES It returns the first entry that matches the given type. If it can’t be found, it returns a nullptr

property issuer str | bytes

The X509 issuer used to sign the signed-data (see: lief.PE.x509.issuer)

class it_const_attributes_t

Bases: object

Iterator over lief._lief.PE.Attribute

property serial_number bytes

The X509 serial number used to sign the signed-data (see: lief.PE.x509.serial_number)

property unauthenticated_attributes lief.PE.SignerInfo.it_const_attributes_t

Return an iterator over the unauthenticated attributes (Attribute)

property version int

Should be 1


MsCounterSign

class lief.PE.MsCounterSign

Bases: Attribute

This class exposes the ms-counter-signature.

property certificates lief.PE.MsCounterSign.it_const_crt

Return an iterator over x509 certificates

property content_info lief.PE.ContentInfo
property digest_algorithm lief.PE.ALGORITHMS
class it_const_crt

Bases: object

Iterator over lief._lief.PE.x509

class it_const_signers_t

Bases: object

Iterator over lief._lief.PE.SignerInfo

property signers lief.PE.MsCounterSign.it_const_signers_t

Return an iterator over the signers (SignerInfo)

property version int

PKCS9TSTInfo

class lief.PE.PKCS9TSTInfo

Bases: Content

Interface over the structure described by the OID 1.2.840.113549.1.9.16.1.4 (PKCS #9)

The internal structure is described in the RFC #3161

TSTInfo ::= SEQUENCE  {
 version        INTEGER  { v1(1) },
 policy         TSAPolicyId,
 messageImprint MessageImprint,
 serialNumber   INTEGER,
 genTime        GeneralizedTime,
 accuracy       Accuracy                OPTIONAL,
 ordering       BOOLEAN                 DEFAULT FALSE,
 nonce          INTEGER                 OPTIONAL,
 tsa            [0] GeneralName         OPTIONAL,
 extensions     [1] IMPLICIT Extensions OPTIONAL
}

TSAPolicyId    ::= OBJECT IDENTIFIER
MessageImprint ::= SEQUENCE {
  hashAlgorithm  AlgorithmIdentifier,
  hashedMessage  OCTET STRING
}

Accuracy ::= SEQUENCE {
  seconds        INTEGER           OPTIONAL,
  millis     [0] INTEGER  (1..999) OPTIONAL,
  micros     [1] INTEGER  (1..999) OPTIONAL
}

MsManifestBinaryID

class lief.PE.MsManifestBinaryID

Bases: Attribute

Interface over the structure described by the OID 1.3.6.1.4.1.311.10.3.28 (szOID_PLATFORM_MANIFEST_BINARY_ID)

The internal structure is not documented but we can infer the following structure:

szOID_PLATFORM_MANIFEST_BINARY_ID ::= SET OF BinaryID

BinaryID ::= UTF8STRING
property manifest_id str

The manifest id


SpcRelaxedPeMarkerCheck

class lief.PE.SpcRelaxedPeMarkerCheck

Bases: Attribute

property value int

SigningCertificateV2

class lief.PE.SigningCertificateV2

Bases: Attribute

SigningCertificateV2 ::= SEQUENCE {
  certs    SEQUENCE OF ESSCertIDv2,
  policies SEQUENCE OF PolicyInformation OPTIONAL
}

ESSCertIDv2 ::= SEQUENCE {
  hashAlgorithm AlgorithmIdentifier DEFAULT {algorithm id-sha256},
  certHash      OCTET STRING,
  issuerSerial  IssuerSerial OPTIONAL
}

IssuerSerial ::= SEQUENCE {
  issuer       GeneralNames,
  serialNumber CertificateSerialNumber
}

PolicyInformation ::= SEQUENCE {
  policyIdentifier   OBJECT IDENTIFIER,
  policyQualifiers   SEQUENCE SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL
}

Builder

class lief.PE.Builder(self, binary: lief._lief.PE.Binary, config: lief._lief.PE.Builder.config_t)

Bases: object

build(self) lief.ok_t | lief.lief_errors

Perform the build process

bytes(self) bytes
class config_t(self)

Bases: object

This structure is used to configure the build operation.

The default value of these attributes is set to False if the operation modifies the binary layout even though nothing changed. For instance, building the import table always requires relocating the table to another place. Thus, the default value is false and must be explicitly set to true.

property debug bool

Whether the builder should regenerate debug entries

property debug_section str

Section that holds the debug entries

property dos_stub bool

Whether the builder should write back dos stub (including the rich header)

property export_section str

Section that holds the export table

property exports bool

Whether the builder should reconstruct the export table This option should be turned on if you modify exports.

Please check LIEF website for more details

property force_relocating bool
property idata_section str

Section that holds the relocated import table (IAT/ILT)

property imports bool

Whether the builder should reconstruct the imports table. This option should be turned on if you modify imports.

Please check LIEF website for more details

property load_configuration bool

Whether the builder should regenerate the load configuration

property overlay bool

Whether the builder should write back any overlay data

property reloc_section str

Section that holds the relocated relocations

property relocations bool

Whether the builder should regenerate relocations

property resolved_iat_cbk collections.abc.Callable[[lief.PE.Binary, lief.PE.Import, lief.PE.ImportEntry, int], None]
property resources bool

Whether the builder should regenerate the resources tree

property rsrc_section str

If the resources tree needs to be relocated, this attribute defines the name of the new section that contains the relocated tree.

property tls bool

Whether the builder should regenerate the TLS info

property tls_section str

Section that holds the relocated TLS info

property rsrc_data memoryview
write(self, output: str) None

Write the build result into the output file


Resource Node

Inheritance diagram of lief._lief.PE.ResourceData, lief._lief.PE.ResourceDirectory, lief._lief.PE.ResourceNode
class lief.PE.ResourceNode

Bases: Object

Class which represents a Node in the resource tree.

It is extended by lief.PE.ResourceData and lief.PE.ResourceNode

add_child(self, node: lief.PE.ResourceNode) lief.PE.ResourceNode

Add a new child to the current node

property childs lief.PE.ResourceNode.it_childs

Node’s children

copy(self) lief.PE.ResourceNode | None

Duplicate the current instance of this object

delete_child(*args) None

Overloaded function.

  1. delete_child(self, node: lief._lief.PE.ResourceNode) -> None

Delete the given ResourceNode from the current children

  1. delete_child(self, id: int) -> None

    Delete the ResourceNode with the given id from the current children

property depth int

Current depth of the node in the resource tree

property has_name bool

True if the current node uses a name

property id int

Integer that identifies the Type, Name, or Language ID entry.

property is_data bool

True if the current node is a ResourceData

property is_directory bool

True if the current node is a ResourceDirectory

class it_childs

Bases: object

Iterator over lief._lief.PE.ResourceNode

property name str

Resource’s name

parse(bytes: bytes, rva: int) lief.PE.ResourceNode | None = <nanobind.nb_func object>

Resource Directory

Inheritance diagram of lief._lief.PE.ResourceDirectory
class lief.PE.ResourceDirectory(self)
class lief.PE.ResourceDirectory(self, arg: int, /)

Bases: ResourceNode

Overloaded function.

  1. __init__(self) -> None

Default constructor

  1. __init__(self, arg: int, /) -> None

Constructor from an ID

property characteristics int

Resource characteristics. This field is reserved for future use. It is currently set to zero.

property major_version int

The major version number, set by the user.

property minor_version int

The minor version number, set by the user.

property numberof_id_entries int

The number of directory entries immediately following the Name entries that use numeric IDs for Type, Name, or Language entries.

property numberof_name_entries int

The number of directory entries immediately following the table that use strings to identify Type, Name, or Language entries (depending on the level of the table

property time_date_stamp int

The time that the resource data was created by the resource compiler.


Resource Data

Inheritance diagram of lief._lief.PE.ResourceData
class lief.PE.ResourceData(self)
class lief.PE.ResourceData(self, content: collections.abc.Sequence[int], code_page: int = 0)

Bases: ResourceNode

Class which represents a Data Node in the PE resources tree

Overloaded function.

  1. __init__(self) -> None

Default constructor

  1. __init__(self, content: collections.abc.Sequence[int], code_page: int = 0) -> None

property code_page int

Return the code page that is used to decode code point values within the resource data. Typically, the code page is the Unicode code page.

property content memoryview

Resource content

property offset int

Offset of the content within the resource

Warning

This value can change when re-building the resource table

property reserved int

Reserved value. Should be 0


Resources Manager

class lief.PE.ResourcesManager(self, node: lief._lief.PE.ResourceNode)

Bases: Object

The Resource Manager provides an enhanced API to manipulate the resource tree

class TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

ACCELERATOR = 9
ANICURSOR = 21
ANIICON = 22
BITMAP = 2
CURSOR = 1
DIALOG = 5
DLGINCLUDE = 17
FONT = 8
FONTDIR = 7
GROUP_CURSOR = 12
GROUP_ICON = 14
HTML = 23
ICON = 3
MANIFEST = 24
MENU = 4
MESSAGETABLE = 11
PLUGPLAY = 19
RCDATA = 10
STRING = 6
VERSION = 16
VXD = 20
from_value(arg: int) lief.PE.ResourcesManager.TYPE = <nanobind.nb_func object>
property accelerator lief.PE.ResourcesManager.it_const_accelerators

Return list of ResourceAccelerator present in the resource

add_icon(self, icon: lief.PE.ResourceIcon) None

Add an icon to the resources

change_icon(self, old_one: lief.PE.ResourceIcon, new_one: lief.PE.ResourceIcon) None

Switch the given icons

property dialogs lief.PE.ResourcesManager.it_const_dialogs

Return the list of the ResourceDialog present in the resource

get_node_type(self, type: lief.PE.ResourcesManager.TYPE) lief.PE.ResourceNode

Return ResourceNode with the given TYPE or None if not found.

property has_accelerator bool

True if resources contain ResourceAccelerator

property has_dialogs bool

true if the resources contain ResourceDialog

property has_html bool

True if resources contain HTML resource

property has_icons bool

true if the resources contain ResourceIcon

property has_manifest bool

True if the resources contain a Manifest element

property has_string_table bool

True if resources contain ResourceStringTable

has_type(self, type: lief.PE.ResourcesManager.TYPE) bool

True if the resource has the given TYPE

property has_version bool

true if the resources contain a ResourceVersion

property html list[str]

HTML resource as the list of string

property icons lief.PE.ResourcesManager.it_const_icons

Return the list of the ResourceIcon present in the resource

class it_const_accelerators

Bases: object

Iterator over lief._lief.PE.ResourceAccelerator

class it_const_dialogs

Bases: object

Iterator over lief._lief.PE.ResourceDialog

class it_const_icons

Bases: object

Iterator over lief._lief.PE.ResourceIcon

property manifest str | bytes

Manifest as a string

print(self, max_depth: int) str

Print the current resource tree

class string_entry_t

Bases: object

property id int
property string str
property string_table list[lief.PE.ResourcesManager.string_entry_t]

Return the list of the strings embedded in the string table (RT_STRING)

property types list[lief.PE.ResourcesManager.TYPE]

Return list of TYPE present in the resources

property version list[lief.PE.ResourceVersion]

Return a list of verison info (VS_VERSIONINFO).


Resource Icon

class lief.PE.ResourceIcon

Bases: Object

property bit_count int

Bits per pixel

property color_count int

Number of colors in image (0 if >=8bpp)

from_serialization(arg: bytes) lief.PE.ResourceIcon | lief.lief_errors = <nanobind.nb_func object>
property height int

Height in pixels of the image

property id int

Id associated with the icon

property lang int

Language associated with the icon

property pixels memoryview
property planes int

Color Planes

property reserved int

Reserved (must be 0)

save(self, filepath: str) None

Save the icon to the given filepath

serialize(self) bytes

Serialize the current icon into bytes

property sublang int

Sublanguage associated with the icon

property width int

Width in pixels of the image


Resource Dialog

Inheritance diagram of lief._lief.PE.ResourceDialog, lief._lief.PE.ResourceDialogExtended, lief._lief.PE.ResourceDialogRegular
class lief.PE.ResourceDialog

Bases: Object

This class is the base class for either a regular (legacy) Dialog or an extended Dialog. These different kinds of Dialogs are documented by MS at the following addresses:

class CONTROL_STYLES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

From: https://learn.microsoft.com/en-us/windows/win32/controls/common-control-styles

ADJUSTABLE = 32
BOTTOM = 3
LEFT = 129
NODIVIDER = 64
NOMOVEX = 130
NOMOVEY = 2
NOPARENTALIGN = 8
NORESIZE = 4
RIGHT = 131
TOP = 1
VERT = 128
from_value(arg: int) lief.PE.ResourceDialog.CONTROL_STYLES = <nanobind.nb_func object>
class DIALOG_STYLES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

From: https://learn.microsoft.com/en-us/windows/win32/dlgbox/dialog-box-styles

ABSALIGN = 1
CENTER = 2048
CENTERMOUSE = 4096
CONTEXTHELP = 8192
CONTROL = 1024
FIXEDSYS = 8
LOCALEDIT = 32
MODALFRAME = 128
NOFAILCREATE = 16
NOIDLEMSG = 256
S3DLOOK = 4
SETFONT = 64
SETFOREGROUND = 512
SHELLFONT = 72
SYSMODAL = 2
from_value(arg: int) lief.PE.ResourceDialog.DIALOG_STYLES = <nanobind.nb_func object>
class Item

Bases: object

property clazz int | str | None

Window class of the control. This can be either: a string that specifies the name of a registered window class or an ordinal value of a predefined system class.

property control_styles list[lief.PE.ResourceDialog.CONTROL_STYLES]

List of CONTROL_STYLES used by this item

property creation_data memoryview

Creation data that is passed to the control’s window procedure

property cx int

The width, in dialog box units, of the control.

property cy int

The height, in dialog box units, of the control.

property extended_style int

The extended styles for a window. This member is not used to create controls in dialog boxes, but applications that use dialog box templates can use it to create other types of windows.

It can take a combination of WINDOW_EXTENDED_STYLES

has(*args) bool

Overloaded function.

  1. has(self, style: lief._lief.PE.ResourceDialog.WINDOW_STYLES) -> bool

Check if this item has the given WINDOW_STYLES

  1. has(self, style: lief._lief.PE.ResourceDialog.CONTROL_STYLES) -> bool

Check if this item has the given CONTROL_STYLES

property id int

The control identifier.

property style int

The style of the control. This can be a combination of WINDOW_STYLES or CONTROL_STYLES.

property title int | str | None

Title of the item which can be either: a string that specifies the initial text or an ordinal value of a resource, such as an icon, in an executable file

property window_styles list[lief.PE.ResourceDialog.WINDOW_STYLES]

List of WINDOW_STYLES used by this item

property x int

The x-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is always relative to the upper-left corner of the dialog box’s client area.

property y int

The y-coordinate, in dialog box units, of the upper-left corner of the control. This coordinate is always relative to the upper-left corner of the dialog box’s client area.

class TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Enum for discriminating the kind of the Dialog (regular vs extended)

EXTENDED = 2
REGULAR = 1
UNKNOWN = 0
class WINDOW_EXTENDED_STYLES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

From: https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles

ACCEPTFILES = 16
APPWINDOW = 262144
CLIENTEDGE = 512
CONTEXTHELP = 1024
CONTROLPARENT = 65536
DLGMODALFRAME = 1
LEFT = 0
LEFTSCROLLBAR = 16384
MDICHILD = 64
NOPARENTNOTIFY = 4
RIGHT = 4096
RTLREADING = 8192
STATICEDGE = 131072
TOOLWINDOW = 128
TOPMOST = 8
TRANSPARENT_STY = 32
WINDOWEDGE = 256
from_value(arg: int) lief.PE.ResourceDialog.WINDOW_EXTENDED_STYLES = <nanobind.nb_func object>
class WINDOW_STYLES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

From: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles

BORDER = 8388608
CAPTION = 12582912
CHILD = 1073741824
CLIPCHILDREN = 33554432
CLIPSIBLINGS = 67108864
DISABLED = 134217728
DLGFRAME = 4194304
GROUP = 131072
HSCROLL = 1048576
MAXIMIZE = 16777216
MINIMIZE = 536870912
OVERLAPPED = 0
POPUP = 2147483648
SYSMENU = 524288
TABSTOP = 65536
THICKFRAME = 262144
VISIBLE = 268435456
VSCROLL = 2097152
from_value(arg: int) lief.PE.ResourceDialog.WINDOW_STYLES = <nanobind.nb_func object>
copy(self) lief.PE.ResourceDialog | None

Duplicate the current instance of this object

property cx int

The width, in dialog box units, of the dialog box.

property cy int

The height, in dialog box units, of the dialog box

property extended_style int

The extended styles for a window. This member is not used to create dialog boxes, but applications that use dialog box templates can use it to create other types of windows. For a list of values, see WINDOW_EXTENDED_STYLES

has(*args) bool

Overloaded function.

  1. has(self, arg: lief._lief.PE.ResourceDialog.DIALOG_STYLES, /) -> bool

Check if the dialog used to given dialog style

  1. has(self, arg: lief._lief.PE.ResourceDialog.WINDOW_STYLES, /) -> bool

Check if the dialog used to given window style

  1. has(self, arg: lief._lief.PE.ResourceDialog.WINDOW_EXTENDED_STYLES, /) -> bool

Check if the dialog used to given extended window style

property menu int | str | None

ordinal or name value of a menu resource

property style int

The style of the dialog box. This member can be a combination of window style values (such as CAPTION and SYSMENU) and dialog box style values (such as CENTER).

property styles_list list[lief.PE.ResourceDialog.DIALOG_STYLES]

List of DIALOG_STYLES used by this dialog

property title str

title of the dialog box

property type lief.PE.ResourceDialog.TYPE
property window_class int | str | None

ordinal of a predefined system window class or name of a registered window class

property windows_ext_styles_list list[lief.PE.ResourceDialog.WINDOW_EXTENDED_STYLES]

List of WINDOW_EXTENDED_STYLES used by this dialog

property windows_styles_list list[lief.PE.ResourceDialog.WINDOW_STYLES]

List of WINDOW_STYLES used by this dialog

property x int

The x-coordinate, in dialog box units, of the upper-left corner of the dialog box.

property y int

The y-coordinate, in dialog box units, of the upper-left corner of the dialog box.


Resource Dialog – Regular

Inheritance diagram of lief._lief.PE.ResourceDialogRegular
class lief.PE.ResourceDialogRegular(self)

Bases: ResourceDialog

Implementation for a regular/legacy dialog box.

See: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-dlgtemplate

class Item(self)

Bases: Item

This class represents a DLGTEMPLATE item (DLGITEMTEMPLATE) See: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-dlgitemtemplate

add_item(self, item: lief.PE.ResourceDialogRegular.Item) None

Add a new control item to the dialog

property font lief.PE.ResourceDialogRegular.font_t

Additional font information

class font_t

Bases: object

This structure represents additional font information that might be embedded at the end of the DLGTEMPLATE stream

property name str
property point_size int
class it_items

Bases: object

Iterator over lief._lief.PE.Item

property items lief.PE.ResourceDialogRegular.it_items

Iterator over the different control items

property nb_items int

Number of control items


Resource Dialog – Extended

Inheritance diagram of lief._lief.PE.ResourceDialogExtended
class lief.PE.ResourceDialogExtended(self)

Bases: ResourceDialog

Implementation for the new extended dialogbox format.

See: https://learn.microsoft.com/en-us/windows/win32/dlgbox/dlgtemplateex

class Item(self)

Bases: Item

This class represents a DLGTEMPLATEEX item (DLGITEMTEMPLATEEX).

See: https://learn.microsoft.com/en-us/windows/win32/dlgbox/dlgitemtemplateex

property help_id int

The help context identifier for the control. When the system sends a WM_HELP message, it passes the helpID value in the dwContextId member of the HELPINFO structure.

add_item(self, item: lief.PE.ResourceDialogExtended.Item) None

Add a new control item to the dialog

property font lief.PE.ResourceDialogExtended.font_t

Additional font information

class font_t

Bases: object

Font information for the font to use for the text in the dialog box and its controls

property charset int

The character set to be used

property italic bool

Indicates whether the font is italic

property point_size int

The point size of the font

property typeface str

The name of the typeface for the font.

property weight int

The weight of the font

property help_id int

The help context identifier for the dialog box window. When the system sends a WM_HELP message, it passes the helpID value in the dwContextId member of the HELPINFO structure.

class it_items

Bases: object

Iterator over lief._lief.PE.Item

property items lief.PE.ResourceDialogExtended.it_items

Iterator over the different control items

property signature int

Indicates whether a template is an extended dialog box template. If signature is 0xFFFF, this is an extended dialog box template. In this case, the dlgVer member specifies the template version number.

property version int

The version number of the extended dialog box template. This member must be set to 1.


Resource Version

class lief.PE.ResourceVersion

Bases: Object

Class that represents the data associated with the RT_VERSION entry

See: VS_VERSIONINFO – https://docs.microsoft.com/en-us/windows/win32/menurc/vs-versioninfo

property file_info lief.PE.ResourceVersion.fixed_file_info_t

Return the fixed file info (VS_FIXEDFILEINFO)

class fixed_file_info_t

Bases: object

This structure represents the VS_FIXEDFILEINFO structure defined in verrsrc.h.

class FILE_FLAGS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

DEBUG = 1
INFO_INFERRED = 16
PATCHED = 4
PRERELEASE = 2
PRIVATEBUILD = 8
SPECIALBUILD = 32
class FILE_TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

APP = 1
DLL = 2
DRV = 3
FONT = 4
STATIC_LIB = 7
UNKNOWN = 0
VXD = 5
class FILE_TYPE_DETAILS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

DRV_COMM = 8589934602
DRV_DISPLAY = 8589934596
DRV_INPUTMETHOD = 8589934603
DRV_INSTALLABLE = 8589934600
DRV_KEYBOARD = 8589934594
DRV_LANGUAGE = 8589934595
DRV_MOUSE = 8589934597
DRV_NETWORK = 8589934598
DRV_PRINTER = 8589934593
DRV_SOUND = 8589934601
DRV_SYSTEM = 8589934599
DRV_VERSIONED_PRINTER = 12
FONT_RASTER = 17179869185
FONT_TRUETYPE = 17179869187
FONT_VECTOR = 17179869186
UNKNOWN = 0
class VERSION_OS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

DOS_WINDOWS16 = 65537
DOS_WINDOWS32 = 65540
NT = 262144
NT_WINDOWS32 = 262148
OS216 = 131072
OS216_PM16 = 131074
OS232 = 196608
OS232_PM32 = 196611
PM16 = 2
PM32 = 3
UNKNOWN = 0
WINCE = 327680
WINDOWS16 = 1
WINDOWS32 = 4
property file_date_ls int

The least significant 32 bits of the file’s 64-bit binary creation date and time stamp.

property file_date_ms int

The most significant 32 bits of the file’s 64-bit binary creation date and time stamp.

property file_flags int

Contains a bitmask that specifies the Boolean attributes of the file. This member can include one or more of the values specified in FILE_FLAGS.

property file_flags_mask int

Contains a bitmask that specifies the valid bits in file_flags. A bit is valid only if it was defined when the file was created.

property file_os int

The operating system for which this file was designed. This member can be one of the values specified in VERSION_OS.

property file_subtype int

The function of the file. The possible values depend on the value of file_type.

property file_type int

The general type of file. This member can be one of the values specified in FILE_TYPE. All other values are reserved.

property file_type_details lief.PE.ResourceVersion.fixed_file_info_t.FILE_TYPE_DETAILS
property file_version_ls int

The least significant 32 bits of the file’s binary version number. This member is used with file_version_ms to form a 64-bit value used for numeric comparisons.

property file_version_ms int

The most significant 32 bits of the file’s binary version number. This member is used with file_version_ls to form a 64-bit value used for numeric comparisons.

property flags list[lief.PE.ResourceVersion.fixed_file_info_t.FILE_FLAGS]

List of flags

has(self, flag: lief.PE.ResourceVersion.fixed_file_info_t.FILE_FLAGS) bool

Check if the given flag is present

property product_version_ls int

The least significant 32 bits of the binary version number of the product with which this file was distributed. This member is used with product_version_ms to form a 64-bit value used for numeric comparisons.

property product_version_ms int

The most significant 32 bits of the binary version number of the product with which this file was distributed. This member is used with product_version_ls to form a 64-bit value used for numeric comparisons.

property signature int

Contains the value 0xFEEF04BD. This is used with the szKey member of the VS_VERSIONINFO structure when searching a file for the VS_FIXEDFILEINFO structure.

property struct_version int

The binary version number of this structure. The high-order word of this member contains the major version number, and the low-order word contains the minor version number.

property key str

The Unicode string L”VS_VERSION_INFO”

property string_file_info lief.PE.ResourceStringFileInfo

Return the StringFileInfo element

property type int

The type of data in the version resource: * 1 if it contains text data * 0 if it contains binary data

property var_file_info lief.PE.ResourceVarFileInfo

Return the VarFileInfo element


Resource Var File Info

class lief.PE.ResourceVarFileInfo

Bases: Object

Representation of the VarFileInfo structure

This structure represents the organization of data in a file-version resource. It contains version information not dependent on a particular language and code page combination.

See: https://learn.microsoft.com/en-us/windows/win32/menurc/varfileinfo

class it_vars

Bases: object

Iterator over lief._lief.PE.ResourceVar

property key str

Signature of the structure. Must be the unicode string “VarFileInfo”

property type int

The type of data in the version resource: * 1 if it contains text data * 0 if it contains binary data

property vars lief.PE.ResourceVarFileInfo.it_vars

Iterator over the embedded variables associated to the structure


Resource Var File Info

class lief.PE.ResourceVarFileInfo

Bases: Object

Representation of the VarFileInfo structure

This structure represents the organization of data in a file-version resource. It contains version information not dependent on a particular language and code page combination.

See: https://learn.microsoft.com/en-us/windows/win32/menurc/varfileinfo

class it_vars

Bases: object

Iterator over lief._lief.PE.ResourceVar

property key str

Signature of the structure. Must be the unicode string “VarFileInfo”

property type int

The type of data in the version resource: * 1 if it contains text data * 0 if it contains binary data

property vars lief.PE.ResourceVarFileInfo.it_vars

Iterator over the embedded variables associated to the structure


Resource Var

class lief.PE.ResourceVar

Bases: object

This class represents an element of the ResourceVarFileInfo structure It typically contains a list of language and code page identifier pairs that the version of the application or DLL supports.

See: https://learn.microsoft.com/en-us/windows/win32/menurc/var-str

property key str

Signature of the structure. Must be the unicode string “Translation”

property type int

The type of data in the version resource: * 1 if it contains text data * 0 if it contains binary data

property values list[int]

Return the translation values.

The low-order word of each uint32_t must contain a Microsoft language identifier, and the high-order word must contain the IBM code page number. Either high-order or low-order word can be zero, indicating that the file is language or code page independent


Resource String Table

class lief.PE.ResourceStringTable

Bases: Object

This class represents the StringTable structure. This structure can be seen as a dictionary of key, values with key and values defined a utf-16 string.

property entries lief.PE.ResourceStringTable.it_entries

Iterator over the different entry_t in this table

class entry_t

Bases: object

An entry in this table which is composed of an UTF-16 key and an UTF-16 value.

property key str
property value str
get(self, key: str) str | None
class it_entries

Bases: object

Iterator over lief._lief.PE.entry_t

property key str

An 8-digit hexadecimal number stored as a Unicode string. The four most significant digits represent the language identifier. The four least significant digits represent the code page for which the data is formatted. Each Microsoft Standard Language identifier contains two parts: the low-order 10 bits specify the major language, and the high-order 6 bits specify the sublanguage.

property type int

The type of data in the version resource: * 1 if it contains text data * 0 if it contains binary data


Resource Accelerator

class lief.PE.ResourceAccelerator

Bases: Object

class FLAGS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

From: https://docs.microsoft.com/en-us/windows/win32/menurc/acceltableentry

ALT = 16
CONTROL = 8
END = 128
NOINVERT = 2
SHIFT = 4
VIRTKEY = 1
from_value(arg: int) lief.PE.ResourceAccelerator.FLAGS = <nanobind.nb_func object>
add(self, arg: lief.PE.ResourceAccelerator.FLAGS) lief.PE.ResourceAccelerator

Append the given flag

property ansi int

An ANSI character value or a virtual-key code that identifies the accelerator key.

property ansi_str str
property flags int

Describe the keyboard accelerator characteristics.

has(self, arg: lief.PE.ResourceAccelerator.FLAGS) bool

Whether the entry has the given flag

property id int

An identifier for the keyboard accelerator.

property padding int

The number of bytes inserted to ensure that the structure is aligned on a DWORD boundary.

remove(self, arg: lief.PE.ResourceAccelerator.FLAGS) lief.PE.ResourceAccelerator

Remove the given flag


Rich Header

class lief.PE.RichHeader(self)

Bases: Object

Class which represents the not-so-documented rich header

This structure is usually located at the end of the dos_stub and contains information about the build environment.

It is generated by the Microsoft linker link.exe and there are no options to disable or remove this information.

add_entry(*args) None

Overloaded function.

  1. add_entry(self, entry: lief._lief.PE.RichEntry) -> None

Add a new RichEntry

  1. add_entry(self, id: int, build_id: int, count: int) -> None

Add a new RichEntry given its id, build_id, count

copy(self) lief.PE.RichHeader

Duplicate the current instance of this object

property entries lief.PE.RichHeader.it_entries

Return an iterator over the RichEntry within the header

hash(*args) list[int]

Overloaded function.

  1. hash(self, algo: lief._lief.PE.ALGORITHMS) -> list[int]

    Compute the hash of the decoded rich header structure with the given hash ALGORITHMS

  2. hash(self, algo: lief._lief.PE.ALGORITHMS, xor_key: int) -> list[int]

    Compute the hash of the rich header structure encoded with the provided key and the given hash ALGORITHMS

class it_entries

Bases: object

Iterator over lief._lief.PE.RichEntry

property key int

Key used to encode the header (xor operation)

raw(*args) list[int]

Overloaded function.

  1. raw(self) -> list[int]

    The raw structure of the Rich header without xor-encoding.

    This function is equivalent as calling the other raw function with a xor_key set to 0

  2. raw(self, xor_key: int) -> list[int]

    Given this rich header, this function re-computes the raw bytes of the structure with the provided xor-key.

    You can access the decoded data’s structure with the xor_key set to 0


Rich Entry

class lief.PE.RichEntry(self)
class lief.PE.RichEntry(self, id: int, build_id: int, count: int)

Bases: Object

Class which represents an entry associated to the RichHeader

Overloaded function.

  1. __init__(self) -> None

  2. __init__(self, id: int, build_id: int, count: int) -> None

Contructor from id, build_id and count

property build_id int

Builder number of the tool (if any)

copy(self) lief.PE.RichEntry

Duplicate the current instance of this object

property count int

Occurrence count

property id int

Type of the entry


Debug

Inheritance diagram of lief._lief.PE.CodeView, lief._lief.PE.Pogo, lief._lief.PE.CodeViewPDB, lief._lief.PE.ExDllCharacteristics, lief._lief.PE.Repro, lief._lief.PE.Debug, lief._lief.PE.FPO, lief._lief.PE.PDBChecksum, lief._lief.PE.VCFeature
class lief.PE.Debug(self)

Bases: Object

This class represents a generic entry in the debug data directory. For known types, this class is extended to provide a dedicated API (see: CodeCodeView)

class TYPES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

The entry types

BORLAND = 9
CLSID = 11
CODEVIEW = 2
COFF = 1
EXCEPTION = 5
EX_DLLCHARACTERISTICS = 20
FIXUP = 6
FPO = 3
ILTCG = 14
MISC = 4
MPX = 15
OMAP_FROM_SRC = 8
OMAP_TO_SRC = 7
PDBCHECKSUM = 19
POGO = 13
REPRO = 16
RESERVED10 = 10
UNKNOWN = 0
VC_FEATURE = 12
from_value(arg: int) lief.PE.Debug.TYPES = <nanobind.nb_func object>
property addressof_rawdata int

Address of the debug data relative to the image base

property characteristics int

Reserved should be 0

copy(self) lief.PE.Debug | None

Duplicate the current instance of this object

property major_version int

The major version number of the debug data format.

property minor_version int

The minor version number of the debug data format.

property payload memoryview

Debug data associated with this entry

property pointerto_rawdata int

File offset of the debug data

property section lief.PE.Section

The section where debug data is located

property sizeof_data int

Size of the debug data

property timestamp int

The time and date when the debug data was created.

property type lief.PE.Debug.TYPES

The format (TYPES) of the debugging information


Code View

Inheritance diagram of lief._lief.PE.CodeView, lief._lief.PE.CodeViewPDB
class lief.PE.CodeView(self)
class lief.PE.CodeView(self, arg: lief._lief.PE.CodeView.SIGNATURES, /)

Bases: Debug

class SIGNATURES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

CV_41 = 959464014
CV_50 = 825311822
PDB_20 = 808534606
PDB_70 = 1396986706
UNKNOWN = 0
from_value(arg: int) lief.PE.CodeView.SIGNATURES = <nanobind.nb_func object>
property cv_signature lief.PE.CodeView.SIGNATURES

Type of the code view (SIGNATURES)


Code View PDB

Inheritance diagram of lief._lief.PE.CodeViewPDB
class lief.PE.CodeViewPDB(self)
class lief.PE.CodeViewPDB(self, filename: str)

Bases: CodeView

CodeView PDB specialization

Overloaded function.

  1. __init__(self) -> None

Default constructor

  1. __init__(self, filename: str) -> None

Filename-based constructor

property age int

Age value to verify. The age does not necessarily correspond to any known time value, it is used to determine if a .pdb file is out of sync with a corresponding .exe file.

property filename str | bytes

The path to the .pdb file

property guid str

The GUID signature to verify against the .pdb file signature.

This attribute might be used to lookup remote PDB file on a symbol server

property parent lief.PE.CodeView

Return a reference to the parent lief.PE.CodeView

property signature list[int]

The 32-bit signature to verify against the .pdb file signature.


Code Integrity

class lief.PE.CodeIntegrity(self)

Bases: Object

property catalog int

0xFFFF means not available

property catalog_offset int
property flags int

Flags to indicate if CI information is available, etc.

property reserved int

Additional bitmask to be defined later


Pogo

Inheritance diagram of lief._lief.PE.Pogo
class lief.PE.Pogo(self)

Bases: Debug

class SIGNATURES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

LCTG = 1280590663
PGI = 1346849024
UNKNOWN = 268435455
ZERO = 0
from_value(arg: int) lief.PE.Pogo.SIGNATURES = <nanobind.nb_func object>
property entries lief.PE.Pogo.it_entries
class it_entries

Bases: object

Iterator over lief._lief.PE.PogoEntry

property signature lief.PE.Pogo.SIGNATURES

Type of the pogo (SIGNATURES)


Pogo Entry

class lief.PE.PogoEntry(self)

Bases: Object

copy(self) lief.PE.PogoEntry

Duplicate the current instance of this object

property name str | bytes
property size int
property start_rva int

Repro

Inheritance diagram of lief._lief.PE.Repro
class lief.PE.Repro

Bases: Debug

This class represents a reproducible build entry from the debug directory. (IMAGE_DEBUG_TYPE_REPRO). This entry is usually generated with the undocumented /Brepro linker flag.

See: https://nikhilism.com/post/2020/windows-deterministic-builds/

property hash memoryview

The hash associated with the reproducible build


PDBChecksum

Inheritance diagram of lief._lief.PE.PDBChecksum
class lief.PE.PDBChecksum(self, algo: lief._lief.PE.PDBChecksum.HASH_ALGO, hash: collections.abc.Sequence[int])

Bases: Debug

This class represents the PDB Checksum debug entry which is essentially an array of bytes representing the checksum of the PDB content.

class HASH_ALGO(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

SHA256 = 1
UNKNOWN = 0
property algorithm lief.PE.PDBChecksum.HASH_ALGO

Algorithm used for hashing the PDB content

property hash memoryview

Hash of the PDB content


VCFeature

Inheritance diagram of lief._lief.PE.VCFeature
class lief.PE.VCFeature

Bases: Debug

This class represents the IMAGE_DEBUG_TYPE_VC_FEATURE debug entry

property c_cpp int

Count for C/C++

property gs int

Count for /GS (number of guard stack)

property guards int

Count for /guardN

property pre_vcpp int

Count for Pre-VC++ 11.00

property sdl int

Whether /sdl was enabled for this binary.

sdl stands for Security Development Lifecycle and provides enhanced security features like changing security-relevant warnings into errors or enforcing guard stack.


ExDllCharacteristics

Inheritance diagram of lief._lief.PE.ExDllCharacteristics
class lief.PE.ExDllCharacteristics

Bases: Debug

This class represents the IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS debug entry

class CHARACTERISTICS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

Extended DLL Characteristics

CET_COMPAT = 1
CET_COMPAT_STRICT_MODE = 2
CET_DYNAMIC_APIS_ALLOW_IN_PROC = 8
CET_RESERVED_1 = 16
CET_RESERVED_2 = 32
CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODE = 4
FORWARD_CFI_COMPAT = 64
HOTPATCH_COMPATIBLE = 128
from_value(arg: int) lief.PE.ExDllCharacteristics.CHARACTERISTICS = <nanobind.nb_func object>
property ex_characteristics lief.PE.ExDllCharacteristics.CHARACTERISTICS

The extended characteristics

property ex_characteristics_list list[lief.PE.ExDllCharacteristics.CHARACTERISTICS]

Characteristics as a vector

has(self, characteristic: lief.PE.ExDllCharacteristics.CHARACTERISTICS) bool

Check if the given CHARACTERISTICS is used


Frame Pointer Omission (FPO)

Inheritance diagram of lief._lief.PE.FPO
class lief.PE.FPO

Bases: Debug

This class represents the IMAGE_DEBUG_TYPE_FPO debug entry

class FRAME_TYPE(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

FPO = 0
NON_FPO = 3
TRAP = 1
TSS = 2
from_value(arg: int) lief.PE.FPO.FRAME_TYPE = <nanobind.nb_func object>
property entries lief.PE.FPO.it_entries

Iterator over the different FPO entries

class entry_t

Bases: object

Represents the stack frame layout for a x86 function when frame pointer omission (FPO) optimization is used.

property nb_locals int

The number of local variables.

property nb_saved_regs int

Number of registers saved.

property parameters_size int

The size of the parameters.

property proc_size int

The number of bytes in the function.

property prolog_size int

The number of bytes in the function prolog code.

property reserved int

reserved for future use

property rva int

The function RVA

property type lief.PE.FPO.FRAME_TYPE

Variable that indicates the frame type.

property use_bp bool

Whether the EBP register has been allocated.

property use_seh bool

Whether the function uses structured exception handling.

class it_entries

Bases: object

Iterator over lief._lief.PE.entry_t


COFF String

class lief.PE.COFFString

Bases: object

This class represents a string located in the COFF string table.

Some of these strings can be used for section’s name where its lenght is greater than 8 bytes. See: coff_string.

Reference: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#coff-string-table

property offset int

The offset of this string the in the COFF string table. This offset includes the first 4-bytes that holds the table size

property string str

The actual string


Exception Info

Inheritance diagram of lief._lief.PE.RuntimeFunctionX64, lief._lief.PE.unwind_aarch64.UnpackedFunction, lief._lief.PE.ExceptionInfo, lief._lief.PE.unwind_aarch64.PackedFunction, lief._lief.PE.RuntimeFunctionAArch64
class lief.PE.ExceptionInfo

Bases: object

This class is the base class for any exception or runtime function entry

class ARCH(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Arch discriminator for the subclasses

ARM64 = 1
UNKNOWN = 0
X86_64 = 2
property arch lief.PE.ExceptionInfo.ARCH

Target architecture of this exception

copy(self) lief.PE.ExceptionInfo | None

Duplicate the current instance of this object

property rva_start int

Function start address


RuntimeFunctionX64

Inheritance diagram of lief._lief.PE.RuntimeFunctionX64
class lief.PE.RuntimeFunctionX64

Bases: ExceptionInfo

This class represents an entry in the exception table (.pdata section) for the x86-64 architecture.

Reference: https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64

class UNWIND_FLAGS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Flag

CHAIN_INFO = 4
EXCEPTION_HANDLER = 1
TERMINATE_HANDLER = 2
from_value(arg: int) lief.PE.RuntimeFunctionX64.UNWIND_FLAGS = <nanobind.nb_func object>
class UNWIND_OPCODES(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

ALLOC_LARGE = 1
ALLOC_SMALL = 2
EPILOG = 6
PUSH_MACHFRAME = 10
PUSH_NONVOL = 0
SAVE_NONVOL = 4
SAVE_NONVOL_FAR = 5
SAVE_XMM128 = 8
SAVE_XMM128_FAR = 9
SET_FPREG = 3
SPARE = 7
from_value(arg: int) lief.PE.RuntimeFunctionX64.UNWIND_OPCODES = <nanobind.nb_func object>
class UNWIND_REG(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

R10 = 10
R11 = 11
R12 = 12
R13 = 13
R14 = 14
R15 = 15
R8 = 8
R9 = 9
RAX = 0
RBP = 5
RBX = 3
RCX = 1
RDI = 7
RDX = 2
RSI = 6
RSP = 4
from_value(arg: int) lief.PE.RuntimeFunctionX64.UNWIND_REG = <nanobind.nb_func object>
property rva_end int

Function end address

property size int

Size of the function (in bytes)

property unwind_info lief.PE.RuntimeFunctionX64.unwind_info_t

Detailed unwind information

class unwind_info_t

Bases: object

property chained lief.PE.RuntimeFunctionX64

If lief.PE.UNWIND_FLAGS.CHAIN_INFO is set, this attributes references the chained runtime function.

property count_opcodes int

The number of slots in the unwind codes array. Some unwind codes, for example, lief.PE.RuntimeFunctionX64.UNWIND_OPCODES.SAVE_NONVOL, require more than one slot in the array.

property flags int

See: lief.PE.RuntimeFunctionX64.UNWIND_FLAGS

property frame_reg int

If nonzero, then the function uses a frame pointer (FP), and this field is the number of the nonvolatile register used as the frame pointer, using the same encoding for the operation info field of UNWIND_OPCODES node

property frame_reg_offset int

If the frame register field is nonzero, this field is the scaled offset from RSP that is applied to the FP register when it’s established

property handler int | None

An image-relative pointer to either the function’s language-specific exception or termination handler. This value is set if one of these flags is set: lief.PE.RuntimeFunctionX64.UNWIND_FLAGS.EXCEPTION_HANDLER, lief.PE.UNWIND_FLAGS.TERMINATE_HANDLER.

has(self, arg: lief.PE.RuntimeFunctionX64.UNWIND_FLAGS) bool

Check if the given flag is used

property opcodes list[lief.PE.unwind_x64.Code | None]

Enhanced representation of the unwind code

property raw_opcodes list[int]

An array of items that explains the effect of the prolog on the nonvolatile registers and RSP

property sizeof_prologue int

Length of the function prolog in bytes.

property version int

Version number of the unwind data, currently 1 or 2.

property unwind_rva int

Unwind info address


unwind_x64 - Code

Inheritance diagram of lief._lief.PE.unwind_x64.SaveXMM128, lief._lief.PE.unwind_x64.Code, lief._lief.PE.unwind_x64.Epilog, lief._lief.PE.unwind_x64.PushMachFrame, lief._lief.PE.unwind_x64.SetFPReg, lief._lief.PE.unwind_x64.PushNonVol, lief._lief.PE.unwind_x64.Alloc, lief._lief.PE.unwind_x64.SaveNonVolatile, lief._lief.PE.unwind_x64.Spare
class lief.PE.unwind_x64.Code

Bases: object

Base class for all unwind operations

property opcode lief.PE.RuntimeFunctionX64.UNWIND_OPCODES

The original opcode

property position int

Offset in the prolog


unwind_x64 - Alloc

Inheritance diagram of lief._lief.PE.unwind_x64.Alloc
class lief.PE.unwind_x64.Alloc

Bases: Code

This class represents a stack-allocation operation (lief.PE.RuntimeFunctionX64.UNWIND_OPCODES.ALLOC_SMALL, lief.PE.RuntimeFunctionX64.UNWIND_OPCODES.ALLOC_LARGE)

property size int

The size allocated


unwind_x64 - PushNonVol

Inheritance diagram of lief._lief.PE.unwind_x64.PushNonVol
class lief.PE.unwind_x64.PushNonVol