Pkg.DotNETDecompiler
— API for decompiling .NET assemblies¶
Overview¶
The Pkg.DotNETDecompiler
module contains the API for decompiling .NET assemblies.
Decompiling a Class¶
The following code example demonstrates how to decompile a class in a .NET assembly:
from Pkg.DotNETDecompiler import *
def main():
dec = DotNETDecompiler()
dec.init("path/to/assembly")
# we specify the name of the class to decompile or alternatively we could specify a class or method token
text, _ = dec.decompile("WindowsFormsApplication1.Form1")
if text != None:
print(text)
Module API¶
Pkg.DotNETDecompiler module API.
Classes:
.NET decompiler class.
- class DotNETDecompiler¶
.NET decompiler class.
Methods:
addSearchPath
(search_path)Adds a search path for referenced assemblies.
decompile
(name_or_token[, language_version, …])Decompiles a class or method in a .NET assembly.
init
(file_name[, search_paths, …])Initializes the decompiler.
Sets whether decompilation should fail on a missing assembly reference.
setIndentSize
(size)Sets the indentation size for decompiled code.
- addSearchPath(search_path: str) → None¶
Adds a search path for referenced assemblies.
- Parameters
search_path (str) – The search path to add.
- decompile(name_or_token: Union[str, int], language_version: Optional[str] = None, wait_object: Optional[Pro.Core.NTIWait] = None) → Tuple[Optional[str], Optional[Pro.Core.NTTextTags]]¶
Decompiles a class or method in a .NET assembly.
- Parameters
name_or_token (Union[str, int]) – The name or token of the class or method to decompile.
language_version (Optional[str]) – The version of the language that should be used to decompile.
wait_object (Optional[NTIWait]) – An optional wait object.
- Returns
Returns a tuple containing the decompiled text and text tags if successful; otherwise returns a tuple whose first value is
None
.- Return type
Tuple[Optional[str], Optional[NTTextTags]]
See also
Pro.Core.NTTextTags
.
- init(file_name: str, search_paths: Optional[List[str]] = None, fail_on_missing_reference: bool = True)¶
Initializes the decompiler.
- Parameters
file_name (str) – The name of the .NET assembly to decompile.
search_paths (Optional[List[str]]) – An optional list of search paths used to resolved referenced assemblies.
fail_on_missing_reference (bool) – If
True
, fails the decompilation when a referenced assembly is not resolved.See also
decompile()
.
- setFailOnMissingReference(fail_on_missing_reference: bool) → None¶
Sets whether decompilation should fail on a missing assembly reference.
- Parameters
fail_on_missing_reference (bool) – If
True
, fails the decompilation when a referenced assembly is not resolved.
- setIndentSize(size: int) → None¶
Sets the indentation size for decompiled code.
- Parameters
size (int) – The indent size.