Skip to content

Commit 09dbd64

Browse files
authored
Merge pull request #437 from BenjyWiener/abstract-darwin-symbol
darwin: Add DarwinSymbol methods to ObjectiveCSymbol
2 parents 6f72889 + a0c04e1 commit 09dbd64

6 files changed

Lines changed: 31 additions & 22 deletions

File tree

src/rpcclient/rpcclient/clients/darwin/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from rpcclient.core.client import AsyncCoreClient, BaseCoreClient, CoreClient, RemoteCallArg
4040
from rpcclient.core.structs.consts import RTLD_GLOBAL, RTLD_NOW
4141
from rpcclient.core.subsystems.decorator import subsystem
42-
from rpcclient.core.symbol import BaseSymbol
4342
from rpcclient.core.symbols_jar import LazySymbol
4443
from rpcclient.exceptions import CfSerializationError, MissingLibraryError
4544
from rpcclient.protocol.rpc_bridge import AsyncRpcBridge, SyncRpcBridge
@@ -231,7 +230,7 @@ async def get_class_list(self) -> dict[str, objective_c_class.Class]:
231230
return result
232231

233232
@zyncio.zmethod
234-
async def decode_cf(self, symbol: BaseSymbol) -> CfSerializable:
233+
async def decode_cf(self, symbol: int) -> CfSerializable:
235234
if await self.symbols.CFGetTypeID.z(symbol) == self._CFNullTypeID:
236235
return None
237236

src/rpcclient/rpcclient/clients/darwin/objective_c/objective_c_symbol.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
from rpcclient.clients.darwin.objective_c import objc
1515
from rpcclient.clients.darwin.objective_c.objc import Method
1616
from rpcclient.clients.darwin.objective_c.objective_c_class import BoundObjectiveCMethod, Class
17-
from rpcclient.clients.darwin.symbol import BaseDarwinSymbol, DarwinSymbol
18-
from rpcclient.core._types import ClientBound
17+
from rpcclient.clients.darwin.symbol import AbstractDarwinSymbol, BaseDarwinSymbol, DarwinSymbol
1918
from rpcclient.core.client import RemoteCallArg
20-
from rpcclient.core.symbol import AbstractSymbol
2119
from rpcclient.core.symbols_jar import SymbolsJar
2220
from rpcclient.exceptions import RpcClientException
21+
from rpcclient.utils import readonly
2322

2423

2524
if TYPE_CHECKING:
@@ -40,7 +39,7 @@ class Ivar(Generic[DarwinSymbolT_co]):
4039
offset: int
4140

4241

43-
class ObjectiveCSymbol(AbstractSymbol, ClientBound["BaseDarwinClient[DarwinSymbolT_co]"], Generic[DarwinSymbolT_co]):
42+
class ObjectiveCSymbol(AbstractDarwinSymbol, Generic[DarwinSymbolT_co]):
4443
"""
4544
Wrapper object for an objective-c symbol.
4645
Allowing easier access to its properties, methods and ivars.
@@ -56,6 +55,9 @@ class ObjectiveCSymbol(AbstractSymbol, ClientBound["BaseDarwinClient[DarwinSymbo
5655
"properties",
5756
})
5857

58+
@readonly
59+
def _client(self) -> "BaseDarwinClient[DarwinSymbolT_co]": ...
60+
5961
def __init__(self, value: int, client: "BaseDarwinClient[DarwinSymbolT_co]") -> None:
6062
"""
6163
Create an ObjectiveCSymbol object.
@@ -64,7 +66,7 @@ def __init__(self, value: int, client: "BaseDarwinClient[DarwinSymbolT_co]") ->
6466
:return: ObjectiveCSymbol object.
6567
:rtype: ObjectiveCSymbol
6668
"""
67-
self._client = client
69+
__class__._client.set(self, client)
6870
self._sym: DarwinSymbolT_co = client.symbol(value)
6971
self.ivars: list[Ivar[DarwinSymbolT_co]] = []
7072
self.methods: list[Method[DarwinSymbolT_co]] = []
@@ -74,6 +76,9 @@ def __init__(self, value: int, client: "BaseDarwinClient[DarwinSymbolT_co]") ->
7476
if zyncio.is_sync(self):
7577
self.reload()
7678

79+
def __zync_delegate__(self) -> DarwinSymbolT_co:
80+
return self._sym
81+
7782
def _symbol_from_value(self, value: int) -> DarwinSymbolT_co:
7883
"""
7984
Returns the gives value as as a BaseDarwinSymbol.

src/rpcclient/rpcclient/clients/darwin/subsystems/location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def _get_location_manager(self) -> DarwinSymbolT_co:
4343
@zyncio.zproperty
4444
async def _location_services_enabled(self) -> bool:
4545
"""opt-in status for location services"""
46-
return bool((await self._get_location_manager()).objc_call.z("locationServicesEnabled"))
46+
return bool(await (await self._get_location_manager()).objc_call.z("locationServicesEnabled"))
4747

4848
@_location_services_enabled.setter
4949
async def location_services_enabled(self, value: bool) -> None:

src/rpcclient/rpcclient/clients/darwin/subsystems/processes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ async def vmu_proc_info(self) -> DarwinSymbolT_co:
880880

881881
@zyncio.zproperty
882882
@cached_async_method
883-
async def vmu_region_identifier(self: "Process[DarwinSymbolT_co]") -> DarwinSymbolT_co:
883+
async def vmu_region_identifier(self) -> DarwinSymbolT_co:
884884
"""Return the VMUVMRegionIdentifier object for this task."""
885885

886886
VMUVMRegionIdentifier = await self._client.symbols.objc_getClass.z("VMUVMRegionIdentifier")

src/rpcclient/rpcclient/clients/darwin/symbol.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from rpcclient.clients.darwin.common import CfSerializable, CfSerializableAny, CfSerializableT
88
from rpcclient.core.client import RemoteCallArg
9-
from rpcclient.core.symbol import AsyncSymbol, BaseSymbol, Symbol
9+
from rpcclient.core.symbol import AbstractSymbol, AsyncSymbol, BaseSymbol, Symbol
1010
from rpcclient.exceptions import UnrecognizedSelectorError
1111
from rpcclient.utils import assert_cast, readonly
1212

@@ -17,12 +17,9 @@
1717
from rpcclient.clients.darwin.subsystems.processes import Region
1818

1919

20-
class BaseDarwinSymbol(BaseSymbol):
20+
class AbstractDarwinSymbol(AbstractSymbol):
2121
@readonly
22-
def _client(self) -> "BaseDarwinClient[Self]": ...
23-
24-
def __init__(self, value: int, client: "BaseDarwinClient[Self]") -> None:
25-
super().__init__(value, client)
22+
def _client(self) -> "BaseDarwinClient[BaseDarwinSymbol]": ...
2623

2724
async def _objc_call(self, selector: str, *params, **kwargs) -> Any:
2825
"""call an objc method on a given object"""
@@ -79,6 +76,19 @@ async def cfdesc(self) -> CfSerializable:
7976
"""
8077
return await self.get_cfdesc()
8178

79+
@property
80+
def osstatus(self) -> list[ErrorCode] | None:
81+
"""Get possible translation to given error code by querying osstatus"""
82+
return get_possible_error_codes(self)
83+
84+
85+
class BaseDarwinSymbol(BaseSymbol, AbstractDarwinSymbol):
86+
@readonly
87+
def _client(self) -> "BaseDarwinClient[Self]": ...
88+
89+
def __init__(self, value: int, client: "BaseDarwinClient[Self]") -> None:
90+
super().__init__(value, client)
91+
8292
@property
8393
def objc_symbol(self) -> "ObjectiveCSymbol[Self]":
8494
"""
@@ -87,11 +97,6 @@ def objc_symbol(self) -> "ObjectiveCSymbol[Self]":
8797
"""
8898
return self._client.objc_symbol(self)
8999

90-
@property
91-
def osstatus(self) -> list[ErrorCode] | None:
92-
"""Get possible translation to given error code by querying osstatus"""
93-
return get_possible_error_codes(self)
94-
95100
@property
96101
def stripped_value(self) -> Self:
97102
"""Remove PAC upper bits"""

src/rpcclient/rpcclient/core/subsystems/sysctl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ async def get_int_by_name(self, name: str) -> int:
162162
return struct.unpack("<I", await self.get_by_name.z(name))[0]
163163

164164
@zyncio.zmethod
165-
async def set_int_by_name(self, name: str, value: int):
165+
async def set_int_by_name(self, name: str, value: int) -> None:
166166
"""equivalent of: sysctl <name> -w value"""
167167
await self.set_by_name.z(name, struct.pack("<I", value))
168168

169169
@zyncio.zmethod
170-
async def set_str_by_name(self, name: str, value: str):
170+
async def set_str_by_name(self, name: str, value: str) -> None:
171171
"""equivalent of: sysctl <name> -w value"""
172172
await self.set_by_name.z(name, value.encode() + b"\x00")
173173

0 commit comments

Comments
 (0)