Skip to content

Commit

Permalink
Merge pull request #1315 from kvs-coder/disable-mem-limit
Browse files Browse the repository at this point in the history
dvt: Add memory limit waiver for pid
  • Loading branch information
doronz88 authored Dec 27, 2024
2 parents 139f4e4 + 5f1ded6 commit 3d13553
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pymobiledevice3/cli/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def proclist(service_provider: LockdownClient):

print_json(processes)

@dvt.command('memlimitoff', cls=Command)
@click.argument('pid', type=click.INT)
def memlimitoff(service_provider: LockdownServiceProvider, pid: int) -> None:
""" Disable process memory limit """
with DvtSecureSocketProxyService(lockdown=service_provider) as dvt:
ProcessControl(dvt).disable_memory_limit_for_pid(pid)

@dvt.command('applist', cls=Command)
def applist(service_provider: LockdownServiceProvider) -> None:
Expand Down
6 changes: 6 additions & 0 deletions pymobiledevice3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'AccessDeniedError', 'RSDRequiredError', 'SysdiagnoseTimeoutError', 'GetProhibitedError',
'FeatureNotSupportedError', 'OSNotSupportedError', 'DeprecationError', 'NotEnoughDiskSpaceError',
'CloudConfigurationAlreadyPresentError', 'QuicProtocolNotSupportedError', 'RemotePairingCompletedError',
'DisableMemoryLimitError',
]

from typing import Optional
Expand Down Expand Up @@ -405,3 +406,8 @@ class RemotePairingCompletedError(PyMobileDevice3Exception):
completed.
"""
pass


class DisableMemoryLimitError(PyMobileDevice3Exception):
""" Disabling memory limit fails. """
pass
10 changes: 10 additions & 0 deletions pymobiledevice3/services/dvt/instruments/process_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typing
from typing import Optional

from pymobiledevice3.exceptions import DisableMemoryLimitError
from pymobiledevice3.osu.os_utils import get_os_utils
from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService
from pymobiledevice3.services.remote_server import MessageAux
Expand Down Expand Up @@ -40,6 +41,15 @@ def signal(self, pid: int, sig: int):
self._channel.sendSignal_toPid_(MessageAux().append_obj(sig).append_obj(pid), expects_reply=True)
return self._channel.receive_plist()

def disable_memory_limit_for_pid(self, pid: int) -> None:
"""
Waive memory limit for a given pid
:param pid: process id.
"""
self._channel.requestDisableMemoryLimitsForPid_(MessageAux().append_int(pid), expects_reply=True)
if not self._channel.receive_plist():
raise DisableMemoryLimitError()

def kill(self, pid: int):
"""
Kill a process.
Expand Down
7 changes: 7 additions & 0 deletions tests/services/instruments/test_dvt_secure_socket_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def test_applist(dvt):
assert safari['Type'] == 'PluginKit'


def test_memlimitoff(dvt):
"""
Test disabling memory limit.
"""
ProcessControl(dvt).disable_memory_limit_for_pid(get_process_data(dvt, 'SpringBoard')['pid'])


def test_kill(dvt):
"""
Test killing a process.
Expand Down

0 comments on commit 3d13553

Please sign in to comment.