Skip to content

Commit

Permalink
bugfix: handle kCFNull
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Feb 18, 2022
1 parent b19e2a3 commit 8a0bebb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/rpcclient/rpcclient/darwin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions src/rpcclient/rpcclient/darwin/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 11 additions & 7 deletions src/rpcclient/tests/test_core_foundation_types.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8a0bebb

Please sign in to comment.