# TypeDef

The TypeDef table contains various information about defined types.

# Get defined type names

TypeDef.get_type_names(visibility: int) -> List[str]

Get a list of defined type names.

Parameters:

  • visibility The visibility of the defined types. Options:
    • Type.TypeDefVisibility.NOTPUBLIC
    • Type.TypeDefVisibility.PUBLIC
    • Type.TypeDefVisibility.NESTEDPUBLIC
    • Type.TypeDefVisibility.NESTEDPRIVATE
    • Type.TypeDefVisibility.NESTEDFAMILY
    • Type.TypeDefVisibility.NESTEDASSEMBLY
    • Type.TypeDefVisibility.NESTEDFAMANDASSEM
    • Type.TypeDefVisibility.NESTEDFAMORASSEM
    • Type.TypeDefVisibility.ANY (on by default)

Return value:

A list with defined type names

Example:

# Import class DotNetPE from module dotnetfile
from dotnetfile import DotNetPE

# Create an instance of DotNetPE with the file path as a parameter
dotnet_file = DotNetPE('/Users/<username>/my_dotnet_assembly.exe')

# Check if the "TypeDef" table exists
if dotnet_file.metadata_table_exists('TypeDef'):
    # Get list with all defined types names
    type_names = dotnet_file.TypeDef.get_type_names()

    # Print out the defined type names
    for type_name in type_names:
        print(f'{type_name}')

# Get defined type names with methods

TypeDef.get_type_names_with_methods() -> List[Struct.TypesMethods]

Get a list of defined type names with their corresponding methods.

Parameters:

-

Return value:

The result is a list of TypesMethods dataclass objects with the following values:

  • Type str Type name
  • Namespace str Namespace name
  • Methods Methods (dataclass) Method information:
    • Name str Method name
    • Signature Dict Additional method information:
      • hasthis bool Method has a "this" pointer
      • return str Return value
      • parameter Tuple[str] Parameter(s)
    • Flags int Method flags
  • Flags int Type flags

Example:

# Import class DotNetPE from module dotnetfile
from dotnetfile import DotNetPE

# Create an instance of DotNetPE with the file path as a parameter
dotnet_file = DotNetPE('/Users/<username>/my_dotnet_assembly.exe')

# Check if the "TypeDef" table exists
if dotnet_file.metadata_table_exists('TypeDef'):
    # Get type name with their corresponding methods
    types_with_methods = dotnet_file.TypeDef.get_type_names_with_methods()

    # Print out detailed type information
    for type_with_method in types_with_methods:
        print(f'Type: {type_with_method.Type}')
        print(f'Namespace: {type_with_method.Namespace}')
        print(f'Flags: {type_with_method.Flags}')
        print('Methods:')
        for method in type_with_method.Methods:
            print(f'\tName: {method.Name}')
            print(f'\tFlags: {method.Flags}')
            if method.Signature:
                print('\tSignature:')
                print(f'\t\tParameter: {method.Signature["parameter"]}')
                print(f'\t\tReturn value: {method.Signature["return"]}')
                print(f'\t\tHas this pointer: {method.Signature["hasthis"]}')
            print('\t---')
        print('---')