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))
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))])
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))
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())
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
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)
def explain_address(self, pid, address): payload = Payload() payload.put_u32('pid', pid) payload.put_u64('address', address) return self.request('ADDR', payload)
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)
def kill(self, pid): payload = Payload() payload.put_u32('pid', pid) return self.request('KILL', payload)
def injectable_unload(self, iid): payload = Payload() payload.put_u32('iid', iid) return self.request('INJU', payload)
def injectable_load(self, path): payload = Payload() payload.put_str('path', path) return self.request('INJL', payload)
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)
def detach(self, pid): payload = Payload() payload.put_u32('pid', pid) return self.request('DETC', payload)
def loglevel(self, loglevel): payload = Payload() payload.put_u32('loglevel', loglevel) return self.request('LLEV', payload)