Skip to content

Commit

Permalink
Refactor OSs hierarchy.
Browse files Browse the repository at this point in the history
  • Loading branch information
matan1008 committed Feb 13, 2022
1 parent e05d406 commit a3bcfaa
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/rpcclient/rpcclient/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import click
import coloredlogs

from rpcclient.client.client_factory import create_client
from rpcclient.client_factory import create_client
from rpcclient.protocol import DEFAULT_PORT

coloredlogs.install(level=logging.DEBUG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from rpcclient.network import Network
from rpcclient.processes import Processes
from rpcclient.protocol import protocol_message_t, cmd_type_t, exec_chunk_t, exec_chunk_type_t, UNAME_VERSION_LEN
from rpcclient.structs.darwin import pid_t, exitcode_t
from rpcclient.darwin.structs import pid_t, exitcode_t
from rpcclient.symbol import Symbol
from rpcclient.symbols_jar import SymbolsJar

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from socket import socket

from rpcclient.client.client import Client
from rpcclient.client.darwin_client import DarwinClient
from rpcclient.client.linux_client import LinuxClient
from rpcclient.client import Client
from rpcclient.darwin.client import DarwinClient
from rpcclient.linux.client import LinuxClient
from rpcclient.exceptions import FailedToConnectError
from rpcclient.protocol import UNAME_VERSION_LEN, DEFAULT_PORT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

from cached_property import cached_property

from rpcclient.client.client import Client
from rpcclient.darwin.darwin_fs import DarwinFs
from rpcclient.darwin.darwin_media import DarwinMedia
from rpcclient.darwin.darwin_network import DarwinNetwork
from rpcclient.darwin.darwin_processes import DarwinProcesses
from rpcclient.client import Client
from rpcclient.darwin.fs import DarwinFs
from rpcclient.darwin.media import DarwinMedia
from rpcclient.darwin.network import DarwinNetwork
from rpcclient.darwin.processes import DarwinProcesses
from rpcclient.darwin.preferences import Preferences
from rpcclient.exceptions import RpcClientException
from rpcclient.structs.darwin import utsname
from rpcclient.structs.darwin_consts import kCFNumberSInt64Type, kCFNumberDoubleType
from rpcclient.symbol import DarwinSymbol
from rpcclient.darwin.structs import utsname
from rpcclient.darwin.consts import kCFNumberSInt64Type, kCFNumberDoubleType
from rpcclient.darwin.symbol import DarwinSymbol


class DarwinClient(Client):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rpcclient.common import path_to_str
from rpcclient.exceptions import BadReturnValueError
from rpcclient.fs import Fs, DirEntry, ScandirIterator
from rpcclient.structs.darwin import dirent32, dirent64, stat64, statfs64
from rpcclient.darwin.structs import dirent32, dirent64, stat64, statfs64


def do_stat(client, stat_name, filename: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from rpcclient.common import path_to_str
from rpcclient.exceptions import RpcClientException, BadReturnValueError
from rpcclient.symbol import DarwinSymbol
from rpcclient.darwin.symbol import DarwinSymbol


class Recorder:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rpcclient.common import path_to_str
from rpcclient.exceptions import BadReturnValueError
from rpcclient.processes import Processes
from rpcclient.structs.darwin import pid_t, MAXPATHLEN, PROC_PIDLISTFDS, proc_fdinfo, PROX_FDTYPE_VNODE, \
from rpcclient.darwin.structs import pid_t, MAXPATHLEN, PROC_PIDLISTFDS, proc_fdinfo, PROX_FDTYPE_VNODE, \
vnode_fdinfowithpath, PROC_PIDFDVNODEPATHINFO, proc_taskallinfo, PROC_PIDTASKALLINFO, PROX_FDTYPE_SOCKET, \
PROC_PIDFDSOCKETINFO, socket_fdinfo, so_kind_t, so_family_t, PROX_FDTYPE_PIPE, PROC_PIDFDPIPEINFO, pipe_info

Expand Down
File renamed without changes.
67 changes: 67 additions & 0 deletions src/rpcclient/rpcclient/darwin/symbol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import struct
import time

from rpcclient.darwin.consts import kCFNumberSInt64Type, kCFNumberDoubleType
from rpcclient.exceptions import CfSerializationError, UnrecognizedSelector
from rpcclient.symbol import Symbol


class DarwinSymbol(Symbol):
def objc_call(self, selector, *params):
""" call an objc method on a given object """
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):
"""
Get output from CFCopyDescription()
:return: CFCopyDescription()'s output as a string
"""
if self == 0:
return None
return self._client.symbols.CFCopyDescription(self).py

@property
def py(self):
if self == 0:
return None

t = self._client._cf_types[self._client.symbols.CFGetTypeID(self)]
if t == 'str':
return self._client.symbols.CFStringGetCStringPtr(self, 0).peek_str()
if t == 'bool':
return bool(self._client.symbols.CFBooleanGetValue(self, 0))
if t == 'number':
with self._client.safe_malloc(200) as buf:
if self._client.symbols.CFNumberIsFloatType(self):
if not self._client.symbols.CFNumberGetValue(self, kCFNumberDoubleType, buf):
raise CfSerializationError(f'failed to deserialize float: {self}')
return struct.unpack('<d', buf.peek(8))[0]
if not self._client.symbols.CFNumberGetValue(self, kCFNumberSInt64Type, buf):
raise CfSerializationError(f'failed to deserialize int: {self}')
return int(buf[0])
if t == 'date':
return time.strptime(self.cfdesc, '%Y-%m-%d %H:%M:%S %z')
if t == 'data':
count = self._client.symbols.CFDataGetLength(self)
return self._client.symbols.CFDataGetBytePtr(self).peek(count)
if t == 'array':
result = []
count = self._client.symbols.CFArrayGetCount(self)
for i in range(count):
result.append(self._client.symbols.CFArrayGetValueAtIndex(self, i).py)
return result
if t == 'dict':
result = {}
count = self._client.symbols.CFArrayGetCount(self)
with self._client.safe_malloc(8 * count) as keys:
with self._client.safe_malloc(8 * count) as values:
self._client.symbols.CFDictionaryGetKeysAndValues(self, keys, values)
for i in range(count):
result[keys[i].py] = values[i].py
return result
raise NotImplementedError(f'type: {t}')
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from cached_property import cached_property

from rpcclient.client.client import Client
from rpcclient.linux_fs import LinuxFs
from rpcclient.structs.linux import utsname
from rpcclient.client import Client
from rpcclient.linux.fs import LinuxFs
from rpcclient.linux.structs import utsname


class LinuxClient(Client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from rpcclient.exceptions import BadReturnValueError
from rpcclient.fs import Fs
from rpcclient.structs.linux import dirent
from rpcclient.linux.structs import dirent


class LinuxFs(Fs):
Expand Down
File renamed without changes.
65 changes: 0 additions & 65 deletions src/rpcclient/rpcclient/symbol.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import ctypes
import os
import struct
import time
from contextlib import contextmanager

from construct import FormatField

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'}
RETVAL_BIT_COUNT = 64

Expand Down Expand Up @@ -194,64 +190,3 @@ def __str__(self):

def __call__(self, *args, **kwargs):
return self._client.call(self, args)


class DarwinSymbol(Symbol):
def objc_call(self, selector, *params):
""" call an objc method on a given object """
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):
"""
Get output from CFCopyDescription()
:return: CFCopyDescription()'s output as a string
"""
if self == 0:
return None
return self._client.symbols.CFCopyDescription(self).py

@property
def py(self):
if self == 0:
return None

t = self._client._cf_types[self._client.symbols.CFGetTypeID(self)]
if t == 'str':
return self._client.symbols.CFStringGetCStringPtr(self, 0).peek_str()
if t == 'bool':
return bool(self._client.symbols.CFBooleanGetValue(self, 0))
if t == 'number':
with self._client.safe_malloc(200) as buf:
if self._client.symbols.CFNumberIsFloatType(self):
if not self._client.symbols.CFNumberGetValue(self, kCFNumberDoubleType, buf):
raise CfSerializationError(f'failed to deserialize float: {self}')
return struct.unpack('<d', buf.peek(8))[0]
if not self._client.symbols.CFNumberGetValue(self, kCFNumberSInt64Type, buf):
raise CfSerializationError(f'failed to deserialize int: {self}')
return int(buf[0])
if t == 'date':
return time.strptime(self.cfdesc, '%Y-%m-%d %H:%M:%S %z')
if t == 'data':
count = self._client.symbols.CFDataGetLength(self)
return self._client.symbols.CFDataGetBytePtr(self).peek(count)
if t == 'array':
result = []
count = self._client.symbols.CFArrayGetCount(self)
for i in range(count):
result.append(self._client.symbols.CFArrayGetValueAtIndex(self, i).py)
return result
if t == 'dict':
result = {}
count = self._client.symbols.CFArrayGetCount(self)
with self._client.safe_malloc(8 * count) as keys:
with self._client.safe_malloc(8 * count) as values:
self._client.symbols.CFDictionaryGetKeysAndValues(self, keys, values)
for i in range(count):
result[keys[i].py] = values[i].py
return result
raise NotImplementedError(f'type: {t}')
2 changes: 1 addition & 1 deletion src/rpcclient/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from rpcclient.client.client_factory import create_client
from rpcclient.client_factory import create_client


@pytest.fixture
Expand Down

0 comments on commit a3bcfaa

Please sign in to comment.