libimobiledevice/libimobiledevice — pull request #158 by upbit (2014-12-07 02:59:32+00:00)
Title: cython: Add debugserver.pxi to Python binding

Tested on Python 2.7:

~~~python
#!/usr/bin/env python

import sys
import time
import plist
from imobiledevice import *

# modify APP_PATH and APP_BIN before test
APP_PATH = "/var/mobile/Containers/Bundle/Application/CFF7043E-9955-423C-BB29-138B53A1E3DD/RankingLog.app/"
APP_BIN = APP_PATH + "RankingLog"

def debugserver_run_app():
ld = LockdownClient(iDevice())
debugserver = ld.get_service_client(DebugServerClient)

with DebugServerCommand("QSetLogging:bitmask=LOG_ALL|LOG_RNB_REMOTE|LOG_RNB_PACKETS") as cmd:
print "Setting logging bitmask: %s" % debugserver.send_command(cmd)
with DebugServerCommand("QSetMaxPacketSize:", 1, ["1024"]) as cmd:
print "Setting maximum packet size: %s" % debugserver.send_command(cmd)
with DebugServerCommand("QSetWorkingDir:", 1, [APP_PATH]) as cmd:
print "Setting working directory: %s" % debugserver.send_command(cmd)

response = debugserver.set_argv(1, [APP_BIN])
print "Setting argv: %s" % response

with DebugServerCommand("qLaunchSuccess") as cmd:
print "Checking if launch succeeded: %s" % debugserver.send_command(cmd)

with DebugServerCommand("Hc0") as cmd:
print "Setting thread: %s" % debugserver.send_command(cmd)

cmd_continue = DebugServerCommand("c")
loop_response = debugserver.send_command(cmd_continue)

# waiting Ctrl+C to exit
while True:
try:
if (loop_response == None):
break
result, loop_response = debugserver.handle_response(loop_response, reply=True)
if result:
sys.stdout.write(result)

time.sleep(100/1000.0)

except (KeyboardInterrupt, SystemExit):
print "Exiting..."
break

with DebugServerCommand("k") as cmd:
response = debugserver.send_command(cmd)
print "Killing process: %s" % debugserver.handle_response(response)

def main():
debugserver_run_app()

if __name__ == '__main__':
main()
~~~