diff --git a/src/rpcclient/rpcclient/darwin/processes.py b/src/rpcclient/rpcclient/darwin/processes.py index f5e55c8..f2e4513 100644 --- a/src/rpcclient/rpcclient/darwin/processes.py +++ b/src/rpcclient/rpcclient/darwin/processes.py @@ -1,6 +1,7 @@ import dataclasses import errno import logging +import os import posixpath import re import struct @@ -30,11 +31,14 @@ from rpcclient.exceptions import ArgumentError, BadReturnValueError, MissingLibraryError, ProcessSymbolAbsentError, \ RpcClientException, SymbolAbsentError, UnrecognizedSelectorError from rpcclient.processes import Processes -from rpcclient.protos.rpc_pb2 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+\{(.+?) \+ (.+?)\} (.*)') diff --git a/src/rpcclient/rpcclient/protosocket.py b/src/rpcclient/rpcclient/protosocket.py index 938b4e4..dd20e24 100644 --- a/src/rpcclient/rpcclient/protosocket.py +++ b/src/rpcclient/rpcclient/protosocket.py @@ -1,9 +1,13 @@ +import os import socket import struct import threading from rpcclient.exceptions import InvalidServerVersionMagicError, ServerDiedError, ServerResponseError -from rpcclient.protos.rpc_pb2 import CmdClose, Command, Handshake, Response + +# 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 # field[0] is MAGIC - skip COMMAND_MAPPING = {field.message_type.name: field.name for field in Command.DESCRIPTOR.fields[1:]} diff --git a/src/rpcclient/tests/conftest.py b/src/rpcclient/tests/conftest.py index 264f303..9518355 100644 --- a/src/rpcclient/tests/conftest.py +++ b/src/rpcclient/tests/conftest.py @@ -1,3 +1,4 @@ +import os from contextlib import closing from uuid import uuid4 @@ -7,7 +8,10 @@ from rpcclient.darwin.client import DarwinClient from rpcclient.exceptions import BadReturnValueError from rpcclient.ios.client import IosClient -from rpcclient.protos.rpc_pb2 import ARCH_ARM64 + +# 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 @pytest.fixture