<s> from MobileDevice import * <EOL> from amdevice import * <EOL> from wirservice import * <EOL> import uuid <EOL> import json <EOL> class WebKitInspector ( WIRService ) : <EOL> def __init__ ( self , amdevice ) : <EOL> WIRService . __init__ ( self , amdevice , [ AMSVC_WEBINSPECTOR ] ) <EOL> def uniqueid ( self ) : <EOL> retval = str ( uuid . uuid1 ( ) ) <EOL> if isinstance ( retval , str ) : <EOL> retval = retval . decode ( u'<STR_LIT:utf-8>' ) <EOL> return retval <EOL> def reportIdentifier ( self , connection_uuid ) : <EOL> self . _sendmsg ( <EOL> u'<STR_LIT>' , <EOL> { <EOL> u'<STR_LIT>' : connection_uuid , <EOL> } <EOL> ) <EOL> retval = self . _recvmsg ( ) <EOL> retval = self . _recvmsg ( ) <EOL> return retval [ <NUM_LIT:1> ] <EOL> def getConnectedApplications ( self , connection_uuid ) : <EOL> self . _sendmsg ( <EOL> u'<STR_LIT>' , <EOL> { <EOL> u'<STR_LIT>' : connection_uuid <EOL> } <EOL> ) <EOL> retval = self . _recvmsg ( ) <EOL> return retval [ <NUM_LIT:1> ] <EOL> def forwardGetListing ( self , connection_uuid , appid ) : <EOL> self . _sendmsg ( <EOL> u'<STR_LIT>' , <EOL> { <EOL> u'<STR_LIT>' : connection_uuid , <EOL> u'<STR_LIT>' : appid <EOL> } <EOL> ) <EOL> retval = self . _recvmsg ( ) <EOL> while retval [ <NUM_LIT:0> ] != u'<STR_LIT>' : <EOL> retval = self . _recvmsg ( ) <EOL> return retval [ <NUM_LIT:1> ] <EOL> def forwardIndicateWebView ( self , connection_uuid , appid , pageid , enable ) : <EOL> self . sendmsg ( <EOL> u'<STR_LIT>' , <EOL> { <EOL> u'<STR_LIT>' : connection_uuid , <EOL> u'<STR_LIT>' : appid , <EOL> u'<STR_LIT>' : pageid , <EOL> u'<STR_LIT>' : enable <EOL> } <EOL> ) <EOL> print self . _recvmsg ( ) <EOL> def forwardSocketSetup ( self , connection_uuid , appid , pageid , sender_uuid ) : <EOL> self . _sendmsg ( <EOL> u'<STR_LIT>' , <EOL> { <EOL> u'<STR_LIT>' : connection_uuid , <EOL> u'<STR_LIT>' : appid , <EOL> u'<STR_LIT>' : pageid , <EOL> u'<STR_LIT>' : sender_uuid <EOL> } <EOL> ) <EOL> self . _recvmsg ( ) <EOL> def forwardSocketData ( self , connection_uuid , appid , pageid , sender_uuid , jsonmsg ) : <EOL> self . _sendmsg ( <EOL> u'<STR_LIT>' , <EOL> { <EOL> u'<STR_LIT>' : connection_uuid , <EOL> u'<STR_LIT>' : appid , <EOL> u'<STR_LIT>' : pageid , <EOL> u'<STR_LIT>' : sender_uuid , <EOL> u'<STR_LIT>' : jsonmsg . encode ( u'<STR_LIT:utf-8>' ) <EOL> } <EOL> ) <EOL> return self . _recvmsg ( ) [ <NUM_LIT:1> ] <EOL> def forwardDidClose ( self , connection_uuid , appid , pageid , sender_uuid ) : <EOL> self . sendmsg ( <EOL> u'<STR_LIT>' , <EOL> { <EOL> u'<STR_LIT>' : connection_uuid , <EOL> u'<STR_LIT>' : appid , <EOL> u'<STR_LIT>' : pageid , <EOL> u'<STR_LIT>' : sender_uuid <EOL> } <EOL> ) <EOL> print self . _recvmsg ( ) <EOL> def navigate ( self , url ) : <EOL> conn = self . uniqueid ( ) <EOL> app = u'<STR_LIT>' <EOL> self . reportIdentifier ( conn ) <EOL> self . getConnectedApplications ( conn ) <EOL> listing = self . forwardGetListing ( conn , app ) <EOL> pages = listing [ u'<STR_LIT>' ] <EOL> ident = int ( pages . values ( ) [ <NUM_LIT:0> ] [ u'<STR_LIT>' ] ) <EOL> session = self . uniqueid ( ) <EOL> self . forwardSocketSetup ( conn , app , ident , session ) <EOL> data = { <EOL> u'<STR_LIT:id>' : ident , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : { <EOL> u'<STR_LIT:url>' : ( <EOL> url <EOL> ) <EOL> } <EOL> } <EOL> print self . forwardSocketData ( conn , app , ident , session , json . dumps ( data ) ) <EOL> def register_argparse_webinspector ( cmdargs ) : <EOL> import argparse <EOL> import sys <EOL> import mimetypes <EOL> import base64 <EOL> def cmd_load ( args , dev ) : <EOL> mimetype = mimetypes . guess_type ( args . path ) <EOL> f = open ( args . path , u'<STR_LIT:rb>' ) <EOL> content = f . read ( ) <EOL> f . close ( ) <EOL> wi = WebKitInspector ( dev ) <EOL> wi . navigate ( u'<STR_LIT>' + mimetype [ <NUM_LIT:0> ] + u'<STR_LIT>' + base64 . b64encode ( content ) ) <EOL> wi . disconnect ( ) <EOL> def cmd_navigate ( args , dev ) : <EOL> wi = WebKitInspector ( dev ) <EOL> wi . navigate ( args . url . decode ( u'<STR_LIT:utf-8>' ) ) <EOL> wi . disconnect ( ) <EOL> webparser = cmdargs . add_parser ( <EOL> u'<STR_LIT>' , <EOL> help = u'<STR_LIT>' <EOL> ) <EOL> webcmd = webparser . add_subparsers ( ) <EOL> loadcmd = webcmd . add_parser ( <EOL> u'<STR_LIT>' , <EOL> help = u'<STR_LIT>' <EOL> ) <EOL> loadcmd . add_argument ( <EOL> u'<STR_LIT:path>' , <EOL> help = u'<STR_LIT>' <EOL> ) <EOL> loadcmd . set_defaults ( func = cmd_load ) <EOL> navigatecmd = webcmd . add_parser ( <EOL> u'<STR_LIT>' , <EOL> help = u'<STR_LIT>' <EOL> ) <EOL> navigatecmd . add_argument ( <EOL> u'<STR_LIT:url>' , <EOL> help = u'<STR_LIT>' <EOL> ) <EOL> navigatecmd . set_defaults ( func = cmd_navigate ) </s>
