Skip to content

Commit

Permalink
Fix some type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
negasora committed Jun 21, 2024
1 parent 38e719b commit afba5a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions python/demangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
from . import types
from .architecture import Architecture
from .platform import Platform
from typing import Union
from typing import Iterable, List, Optional, Union

def get_qualified_name(names):
def get_qualified_name(names: Iterable[str]):
"""
``get_qualified_name`` gets a qualified name for the provided name list.
Expand All @@ -46,15 +46,15 @@ def get_qualified_name(names):
return "::".join(names)


def demangle_llvm(mangled_name: str, options=None):
def demangle_llvm(mangled_name: str, options: Optional[Union[bool, binaryview.BinaryView]] = None) -> Optional[List[str]]:
"""
``demangle_llvm`` demangles a mangled name to a Type object.
:param str mangled_name: a mangled (msvc/itanium/rust/dlang) name
:param options: (optional) Whether to simplify demangled names : None falls back to user settings, a BinaryView uses that BinaryView's settings, or a boolean to set it directly
:type options: Tuple[bool, BinaryView, None]
:type options: Optional[Union[bool, BinaryView]]
:return: returns demangled name or None on error
:rtype: str
:rtype: Optional[List[str]]
"""
outName = ctypes.POINTER(ctypes.c_char_p)()
outSize = ctypes.c_ulonglong()
Expand All @@ -79,16 +79,16 @@ def demangle_llvm(mangled_name: str, options=None):
return None


def demangle_ms(archOrPlatform:Union[Architecture, Platform], mangled_name:str, options=False):
def demangle_ms(archOrPlatform: Union[Architecture, Platform], mangled_name: str, options: Optional[Union[bool, binaryview.BinaryView]] = False):
"""
``demangle_ms`` demangles a mangled Microsoft Visual Studio C++ name to a Type object.
:param Union[Architecture, Platform] archOrPlatform: Architecture or Platform for the symbol. Required for pointer/integer sizes and calling conventions.
:param str mangled_name: a mangled Microsoft Visual Studio C++ name
:param options: (optional) Whether to simplify demangled names : None falls back to user settings, a BinaryView uses that BinaryView's settings, or a boolean to set it directly
:type options: Tuple[bool, BinaryView, None]
:type options: Optional[Union[bool, BinaryView]]
:return: returns tuple of (Type, demangled_name) or (None, mangled_name) on error
:rtype: Tuple
:rtype: Tuple[Optional[Type], Union[str, List[str]]]
:Example:
>>> demangle_ms(Platform["x86_64"], "?testf@Foobar@@SA?AW4foo@1@W421@@Z")
Expand Down Expand Up @@ -128,16 +128,16 @@ def demangle_ms(archOrPlatform:Union[Architecture, Platform], mangled_name:str,
return (None, mangled_name)


def demangle_gnu3(arch, mangled_name, options=None):
def demangle_gnu3(arch, mangled_name: str, options: Optional[Union[bool, binaryview.BinaryView]] = None):
"""
``demangle_gnu3`` demangles a mangled name to a Type object.
:param Architecture arch: Architecture for the symbol. Required for pointer and integer sizes.
:param str mangled_name: a mangled GNU3 name
:param options: (optional) Whether to simplify demangled names : None falls back to user settings, a BinaryView uses that BinaryView's settings, or a boolean to set it directly
:type options: Tuple[bool, BinaryView, None]
:type options: Optional[Union[bool, BinaryView]]
:return: returns tuple of (Type, demangled_name) or (None, mangled_name) on error
:rtype: Tuple
:rtype: Tuple[Optional[Type], Union[str, List[str]]]
"""
handle = ctypes.POINTER(core.BNType)()
outName = ctypes.POINTER(ctypes.c_char_p)()
Expand Down Expand Up @@ -165,7 +165,7 @@ def demangle_gnu3(arch, mangled_name, options=None):
return (None, mangled_name)


def simplify_name_to_string(input_name):
def simplify_name_to_string(input_name: Union[str, types.QualifiedName]):
"""
``simplify_name_to_string`` simplifies a templated C++ name with default arguments and returns a string
Expand All @@ -189,7 +189,7 @@ def simplify_name_to_string(input_name):
return result


def simplify_name_to_qualified_name(input_name, simplify=True):
def simplify_name_to_qualified_name(input_name: Union[str, types.QualifiedName], simplify: bool = True):
"""
``simplify_name_to_qualified_name`` simplifies a templated C++ name with default arguments and returns a qualified name. This can also tokenize a string to a qualified name with/without simplifying it
Expand Down
2 changes: 1 addition & 1 deletion python/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ def __init__(self, handle, platform: Optional['_platform.Platform'] = None, conf

@classmethod
def create(
cls, handle=core.BNTypeHandle, platform: Optional['_platform.Platform'] = None, confidence: int = core.max_confidence
cls, handle: core.BNTypeHandle, platform: Optional['_platform.Platform'] = None, confidence: int = core.max_confidence
) -> 'Type':
assert handle is not None, "Passed a handle which is None"
assert isinstance(handle, core.BNTypeHandle)
Expand Down

0 comments on commit afba5a7

Please sign in to comment.