Beispiel #1
0
 def get_injectable_tracepoints(self, iid):
     payload = Payload()
     payload.put_u32('iid', iid)
     response = self.request('INJT', payload)
     for i in xrange(response.get('tptc', 0)):
         postfix = '[%i]' % i
         yield Tracepoint(response.get('tpta' + postfix), response.get('tpth' + postfix))
Beispiel #2
0
 def ls(self, path):
     payload = Payload()
     payload.put_str('path', path)
     response = self.request('LDIR', payload)
     return set([response.get('entv[{:}]'.format(i)) 
                + ('/' if response.get('entd[{:}]'.format(i)) else '')
                for i in xrange(response.get('entc', 0))])
Beispiel #3
0
 def iter_injectable_symbols(self, iid, which):
     if which not in 'EIA':
         raise ValueError
     payload = Payload()
     payload.put_u32('iid', iid)
     response = self.request('INJ' + which, payload)
     for i in xrange(response.get('symc', 0)):
         postfix = '[%i]' % i
         yield Symbol(response.get('symad' + postfix), response.get('symnm' + postfix))
Beispiel #4
0
    def get_memory(self, pid):
        payload = Payload()
        payload.put_u32('pid', pid)
        response = self.request('MAPS', payload)

        def iter_segments():
            for i in xrange(response.get('segc', 0)):
                def get(what):
                    return response.get('seg{:}[{:}]'.format(what, i))
                yield get('lo'), get('hi'), get('type'), get('file'), get('off')
        return sorted(iter_segments())
Beispiel #5
0
    def request(self, type, payload=None):
        self.__check_connection()
        if payload is None:
            payload = Payload()
        header = Header(type,
                        next(self.seqgen),
                        len(payload.pack()))
        packet = Packet(header, payload)
        self.__send(packet)
        response = self.__recv()

        if response.type == 'FAIL':
            raise ADBIException(response.get('msg', 'Request failed.'))
        if response.type == 'USUP':
            raise ADBIException(response.get('msg', 'Not supported.'))
        if response.type == 'MALF':
            raise ADBIException('Protocol error: {:}'.format(response.get('msg', '?')))

        return response
Beispiel #6
0
 def dump(self, pid, address, size):
     payload = Payload()
     payload.put_u32('pid', pid)
     payload.put_u64('address', address)
     payload.put_u32('size', size)
     response = self.request('MEMD', payload)
     words = (response.get('word[%i]' % x) for x in xrange(response.get('size', 0)))
     def tobytes(word):
         a = (word >> 24) & 0xff
         b = (word >> 16) & 0xff
         c = (word >> 8) & 0xff
         d = (word) & 0xff
         return ''.join(chr(x) for x in (d, c, b, a))
     bytes = (tobytes(x) for x in words)
     return ''.join(bytes)
Beispiel #7
0
 def explain_address(self, pid, address):
     payload = Payload()
     payload.put_u32('pid', pid)
     payload.put_u64('address', address)
     return self.request('ADDR', payload)
Beispiel #8
0
 def __recv(self):
     header = Header.unpack_from(self.connection.recv(Header.size))
     payload = self.connection.recv(header.length)
     payload = Payload.unpack_from(payload)
     return Packet(header, payload)
Beispiel #9
0
 def kill(self, pid):
     payload = Payload()
     payload.put_u32('pid', pid)
     return self.request('KILL', payload)
Beispiel #10
0
 def injectable_unload(self, iid):
     payload = Payload()
     payload.put_u32('iid', iid)
     return self.request('INJU', payload)
Beispiel #11
0
 def injectable_load(self, path):
     payload = Payload()
     payload.put_str('path', path)
     return self.request('INJL', payload)
Beispiel #12
0
 def spawn(self, args):
     payload = Payload()
     payload.put_u32('argc', len(args))
     for i, v in enumerate(args):
         payload.put_str('argv[{:}]'.format(i), v)
     return self.request('SPWN', payload)
Beispiel #13
0
 def detach(self, pid):
     payload = Payload()
     payload.put_u32('pid', pid)
     return self.request('DETC', payload)
Beispiel #14
0
 def loglevel(self, loglevel):
     payload = Payload()
     payload.put_u32('loglevel', loglevel)
     return self.request('LLEV', payload)