Skip to content

Commit

Permalink
client: xpc: add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Dec 6, 2023
1 parent 5de7a1b commit 9825b11
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import toml


# -- Project information -----------------------------------------------------

project = 'rpc-project'
Expand Down
1 change: 1 addition & 0 deletions src/rpcclient/rpcclient/darwin/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

kCFAllocatorDefault = 0
MACH_PORT_NULL = 0
XPC_ARRAY_APPEND = 0xffffffffffffffff


class AVAudioSessionRouteSharingPolicy(IntEnum):
Expand Down
21 changes: 17 additions & 4 deletions src/rpcclient/rpcclient/darwin/xpc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datetime import datetime
from functools import lru_cache
from typing import List, Mapping
from uuid import UUID

from rpcclient.darwin.common import CfSerializable
from rpcclient.darwin.consts import XPC_ARRAY_APPEND
from rpcclient.darwin.symbol import DarwinSymbol
from rpcclient.exceptions import MissingLibraryError, RpcXpcSerializationError
from rpcclient.structs.consts import RTLD_NOW
Expand All @@ -14,6 +16,14 @@ def type(self) -> int:
return self._client.symbols.xpc_get_type(self)


class XPCArray(XPCObject):
def set_data(self, buf: bytes, index: int = XPC_ARRAY_APPEND) -> None:
"""
See https://developer.apple.com/documentation/xpc/1505937-xpc_array_set_data?language=objc
"""
self._client.symbols.xpc_array_set_data(self, index, buf, len(buf))


class XPCDictionary(XPCObject):
def set_string(self, key: str, value: str) -> None:
self._client.symbols.xpc_dictionary_set_string(self, key, value)
Expand All @@ -33,17 +43,17 @@ def set_data(self, key: str, value: bytes) -> None:
def set_fd(self, key: str, value: int) -> None:
self._client.symbols.xpc_dictionary_set_fd(self, key, value)

def set_uuid(self, key: str, value: str) -> None:
self._client.symbols.xpc_dictionary_set_uuid(self, key, value)
def set_uuid(self, key: str, value: UUID) -> None:
self._client.symbols.xpc_dictionary_set_uuid(self, key, value.bytes)

def set_dictionary(self, key: str, value: int) -> None:
self._client.symbols.xpc_dictionary_set_dictionary(self, key, value)

def set_object(self, obj: XPCObject) -> None:
self._client.symbols.xpc_dictionary_set_object(self, obj)

def set_value(self, obj: XPCObject) -> None:
self._client.symbols.xpc_dictionary_set_value(self, obj)
def set_value(self, key: str, obj: XPCObject) -> None:
self._client.symbols.xpc_dictionary_set_value(self, key, obj)

def get_string(self, key: str) -> str:
return self._client.symbols.xpc_dictionary_get_string(self, key).peek_str()
Expand Down Expand Up @@ -89,6 +99,9 @@ def __init__(self, client):
def create_xpc_dictionary(self) -> XPCDictionary:
return XPCDictionary.create(self._client.symbols.xpc_dictionary_create(0, 0, 0), self._client)

def create_xpc_array(self) -> XPCArray:
return XPCArray.create(self._client.symbols.xpc_array_create_empty(), self._client)

def send_xpc_dictionary(self, service_name: str, message: XPCDictionary) -> XPCDictionary:
"""
Send a native XPC dictionary to a XPC service synchronously and return result.
Expand Down

0 comments on commit 9825b11

Please sign in to comment.