From 8a0bebba2e186c57bfd2adb1da84ea789c6427bd Mon Sep 17 00:00:00 2001 From: DoronZ Date: Fri, 18 Feb 2022 23:29:16 +0200 Subject: [PATCH] bugfix: handle kCFNull --- src/rpcclient/rpcclient/darwin/client.py | 1 + src/rpcclient/rpcclient/darwin/symbol.py | 4 ++++ .../tests/test_core_foundation_types.py | 18 +++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/rpcclient/rpcclient/darwin/client.py b/src/rpcclient/rpcclient/darwin/client.py index 0ce1be83..4497dde2 100644 --- a/src/rpcclient/rpcclient/darwin/client.py +++ b/src/rpcclient/rpcclient/darwin/client.py @@ -41,6 +41,7 @@ def __init__(self, sock, sysname: str, hostname: str, port: int = None): raise MissingLibraryError('failed to load CoreFoundation') self._cf_types = { + self.symbols.CFNullGetTypeID(): 'null', self.symbols.CFDateGetTypeID(): 'date', self.symbols.CFDataGetTypeID(): 'data', self.symbols.CFStringGetTypeID(): 'str', diff --git a/src/rpcclient/rpcclient/darwin/symbol.py b/src/rpcclient/rpcclient/darwin/symbol.py index 15720d00..e865fafe 100644 --- a/src/rpcclient/rpcclient/darwin/symbol.py +++ b/src/rpcclient/rpcclient/darwin/symbol.py @@ -26,6 +26,9 @@ def cfdesc(self): return None return self._client.symbols.CFCopyDescription(self).py + def _decode_cfnull(self) -> None: + return None + def _decode_cfstr(self) -> str: ptr = self._client.symbols.CFStringGetCStringPtr(self, 0) if ptr: @@ -80,6 +83,7 @@ def py(self): t = self._client._cf_types[self._client.symbols.CFGetTypeID(self)] type_decoders = { + 'null': self._decode_cfnull, 'str': self._decode_cfstr, 'bool': self._decode_cfbool, 'number': self._decode_cfnumber, diff --git a/src/rpcclient/tests/test_core_foundation_types.py b/src/rpcclient/tests/test_core_foundation_types.py index 3dbc835f..3e184cbf 100644 --- a/src/rpcclient/tests/test_core_foundation_types.py +++ b/src/rpcclient/tests/test_core_foundation_types.py @@ -1,12 +1,16 @@ import pytest -@pytest.mark.parametrize('data', ['string', - b'bytes', - 123, - 0.1, - [0, 1, 'abc'], - {'key': 'value'}, - [{'key': 'value'}, [1, 2]]]) +@pytest.mark.parametrize('data', [ + None, + True, + False, + 'string', + b'bytes', + 123, + 0.1, + [0, 1, 'abc'], + {'key': 'value'}, + [{'key': 'value'}, [1, 2]]]) def test_serialization(client, data): assert client.cf(data).py == data