Skip to content

Commit

Permalink
Check if respondsToSelector before objc_call
Browse files Browse the repository at this point in the history
  • Loading branch information
BarVaserman committed Feb 12, 2022
1 parent dddb165 commit 13d0908
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/rpcclient/rpcclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ class InvalidArgumentError(RpcClientException):

class FailedToConnectError(RpcClientException):
pass


class UnrecognizedSelector(RpcClientException):
pass
8 changes: 6 additions & 2 deletions src/rpcclient/rpcclient/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from construct import FormatField

from rpcclient.exceptions import CfSerializationError
from rpcclient.exceptions import CfSerializationError, UnrecognizedSelector
from rpcclient.structs.darwin_consts import kCFNumberSInt64Type, kCFNumberDoubleType

ADDRESS_SIZE_TO_STRUCT_FORMAT = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'}
Expand Down Expand Up @@ -199,7 +199,11 @@ def __call__(self, *args, **kwargs):
class DarwinSymbol(Symbol):
def objc_call(self, selector, *params):
""" call an objc method on a given object """
return self._client.symbols.objc_msgSend(self, self._client.symbols.sel_getUid(selector), *params)
sel = self._client.symbols.sel_getUid(selector)
if not self._client.symbols.objc_msgSend(self, self._client.symbols.sel_getUid("respondsToSelector:"), sel):
raise UnrecognizedSelector(f"unrecognized selector '{selector}' sent to class")

return self._client.symbols.objc_msgSend(self, sel, *params)

@property
def cfdesc(self):
Expand Down

0 comments on commit 13d0908

Please sign in to comment.