Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: use protobuf_bridge #368

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/rpcclient/rpcclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@
from rpcclient.lief import Lief
from rpcclient.network import Network
from rpcclient.processes import Processes
from rpcclient.protobuf_bridge import Argument, CmdCall, CmdDlclose, CmdDlopen, CmdDlsym, CmdDummyBlock, CmdExec, \
CmdListDir, CmdPeek, CmdPoke, Response
from rpcclient.protosocket import ProtoSocket
from rpcclient.structs.consts import EAGAIN, ECONNREFUSED, EEXIST, EISDIR, ENOENT, ENOTDIR, ENOTEMPTY, EPERM, EPIPE, \
RTLD_NEXT
from rpcclient.symbol import Symbol
from rpcclient.symbols_jar import SymbolsJar
from rpcclient.sysctl import Sysctl

# make sure imports from the *_pb2 modules don't depend on the locally installed protobuf version
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
from rpcclient.protos.rpc_pb2 import Argument, CmdCall, CmdDlclose, CmdDlopen, CmdDlsym, CmdDummyBlock, CmdExec, \
CmdListDir, CmdPeek, CmdPoke, Response # noqa E402

tty_support = False
try:
import termios
Expand Down
6 changes: 1 addition & 5 deletions src/rpcclient/rpcclient/darwin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import builtins
import json
import logging
import os
import plistlib
import typing
from collections import namedtuple
Expand Down Expand Up @@ -36,14 +35,11 @@
from rpcclient.darwin.time import Time
from rpcclient.darwin.xpc import Xpc
from rpcclient.exceptions import CfSerializationError, GettingObjectiveCClassError, MissingLibraryError
from rpcclient.protobuf_bridge import CmdGetClassList, CmdShowClass, CmdShowObject
from rpcclient.structs.consts import RTLD_GLOBAL, RTLD_NOW
from rpcclient.symbol import Symbol
from rpcclient.symbols_jar import SymbolsJar

# make sure imports from the *_pb2 modules don't depend on the locally installed protobuf version
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
from rpcclient.protos.rpc_pb2 import CmdGetClassList, CmdShowClass, CmdShowObject # noqa: E402

IsaMagic = namedtuple('IsaMagic', 'mask value')
ISA_MAGICS = [
# ARM64
Expand Down
6 changes: 1 addition & 5 deletions src/rpcclient/rpcclient/darwin/processes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dataclasses
import errno
import logging
import os
import posixpath
import re
import struct
Expand Down Expand Up @@ -31,14 +30,11 @@
from rpcclient.exceptions import ArgumentError, BadReturnValueError, MissingLibraryError, ProcessSymbolAbsentError, \
RpcClientException, SymbolAbsentError, UnrecognizedSelectorError
from rpcclient.processes import Processes
from rpcclient.protobuf_bridge import ARCH_ARM64
from rpcclient.structs.consts import RTLD_NOW, SEEK_SET, SIGKILL, SIGTERM
from rpcclient.symbol import ADDRESS_SIZE_TO_STRUCT_FORMAT, Symbol
from rpcclient.sysctl import CTL, KERN

# make sure imports from the *_pb2 modules don't depend on the locally installed protobuf version
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
from rpcclient.protos.rpc_pb2 import ARCH_ARM64 # noqa: E402

_CF_STRING_ARRAY_PREFIX_LEN = len(' "')
_CF_STRING_ARRAY_SUFFIX_LEN = len('",')
_BACKTRACE_FRAME_REGEX = re.compile(r'\[\s*(\d+)\] (0x[0-9a-f]+)\s+\{(.+?) \+ (.+?)\} (.*)')
Expand Down
15 changes: 15 additions & 0 deletions src/rpcclient/rpcclient/protobuf_bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
This module makes sure imports from the *_pb2 modules don't depend on the locally installed protobuf version
"""
import os

os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
os.environ['TEMORARILY_DISABLE_PROTOBUF_VERSION_CHECK'] = 'true'

from rpcclient.protos.rpc_pb2 import ARCH_ARM64, Argument, CmdCall, CmdClose, CmdDlclose, CmdDlopen, CmdDlsym, \
CmdDummyBlock, CmdExec, CmdGetClassList, CmdListDir, CmdPeek, CmdPoke, CmdShowClass, CmdShowObject, Command, \
Handshake, Response # noqa: E402

__all__ = ['Argument', 'CmdCall', 'CmdClose', 'CmdDlclose', 'CmdDlopen', 'CmdDlsym', 'CmdDummyBlock', 'CmdExec',
'CmdGetClassList', 'CmdListDir', 'CmdPeek', 'CmdPoke', 'CmdShowClass', 'CmdShowObject', 'Command',
'Handshake', 'Response', 'ARCH_ARM64']
6 changes: 1 addition & 5 deletions src/rpcclient/rpcclient/protosocket.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
import socket
import struct
import threading

from rpcclient.exceptions import InvalidServerVersionMagicError, ServerDiedError, ServerResponseError

# make sure imports from the *_pb2 modules don't depend on the locally installed protobuf version
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
from rpcclient.protos.rpc_pb2 import CmdClose, Command, Handshake, Response # noqa: E402
from rpcclient.protobuf_bridge import CmdClose, Command, Handshake, Response

# field[0] is MAGIC - skip
COMMAND_MAPPING = {field.message_type.name: field.name for field in Command.DESCRIPTOR.fields[1:]}
Expand Down
5 changes: 1 addition & 4 deletions src/rpcclient/rpcclient/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
from capstone import CS_ARCH_ARM64, CS_ARCH_X86, CS_MODE_64, CS_MODE_LITTLE_ENDIAN, Cs, CsInsn
from construct import Container

from rpcclient.protobuf_bridge import ARCH_ARM64
from rpcclient.structs.generic import Dl_info

# make sure imports from the *_pb2 modules don't depend on the locally installed protobuf version
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
from rpcclient.protos.rpc_pb2 import ARCH_ARM64 # noqa: E402

ADDRESS_SIZE_TO_STRUCT_FORMAT = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'}
RETVAL_BIT_COUNT = 64

Expand Down
6 changes: 1 addition & 5 deletions src/rpcclient/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from contextlib import closing
from uuid import uuid4

Expand All @@ -8,10 +7,7 @@
from rpcclient.darwin.client import DarwinClient
from rpcclient.exceptions import BadReturnValueError
from rpcclient.ios.client import IosClient

# make sure imports from the *_pb2 modules don't depend on the locally installed protobuf version
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
from rpcclient.protos.rpc_pb2 import ARCH_ARM64 # noqa: E402
from rpcclient.protobuf_bridge import ARCH_ARM64


@pytest.fixture
Expand Down
Loading