diff options
| author | Peter LaFosse <peter@vector35.com> | 2021-09-06 13:11:51 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2021-09-07 08:23:17 -0400 |
| commit | 2af056bca94120b953629d6c57adc486ad8ffc10 (patch) | |
| tree | 11de3ddbb71b86e2d11c35c71830e9212347c346 /python/types.py | |
| parent | 7c84dcfbdcb57df0b99257307ab95b18d9bc3821 (diff) | |
Create NameSpace.get_core_struct()
Diffstat (limited to 'python/types.py')
| -rw-r--r-- | python/types.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/python/types.py b/python/types.py index 4595876b..d52f2b71 100644 --- a/python/types.py +++ b/python/types.py @@ -46,6 +46,7 @@ MembersType = Union[List['StructureMember'], List[Tuple['Type', str]]] EnumMembersType = Union[List[Tuple[str,int]], List[str], List['EnumerationMember']] SomeType = Union['TypeBuilder', 'Type'] TypeContainer = Union['binaryview.BinaryView', 'typelibrary.TypeLibrary'] +NameSpaceType = Optional[Union[str, List[str], 'NameSpace']] # The following are needed to prevent the type checker from getting # confused as we have member functions in `Type` named the same thing _int = int @@ -198,6 +199,15 @@ class NameSpace(QualifiedName): result.append(name.name[i].decode("utf-8")) return NameSpace(result) + @staticmethod + def get_core_struct(name:Optional[Union[str, List[str], 'NameSpace']]) -> Optional[core.BNNameSpace]: + if name is None: + return None + if isinstance(name, NameSpace): + return name._to_core_struct() + else: + return NameSpace(name)._to_core_struct() + class Symbol: """ @@ -228,11 +238,8 @@ class Symbol: raw_name = full_name if binding is None: binding = SymbolBinding.NoBinding - if isinstance(namespace, str): - namespace = NameSpace(namespace) - if isinstance(namespace, NameSpace): - namespace = namespace._to_core_struct() - _handle = core.BNCreateSymbol(sym_type, short_name, full_name, raw_name, addr, binding, namespace, ordinal) + _namespace = NameSpace.get_core_struct(namespace) + _handle = core.BNCreateSymbol(sym_type, short_name, full_name, raw_name, addr, binding, _namespace, ordinal) assert _handle is not None self._handle = _handle |
