openatx / adbutils

pure python adb library for google adb service.
MIT License
736 stars 173 forks source link

进到adb shell后要输账号密码,怎么实现 #40

Open xyd113 opened 3 years ago

wjt9 commented 3 years ago

怎么没人回答这个问题,我也遇到同样的问题,不知道怎么解

xyd113 commented 3 years ago

怎么没人回答这个问题,我也遇到同样的问题,不知道怎么解

我用pexpect实现了adb shell里面输账号密码 (以下代码我有加工过,你需要再调一下) shell = pexpect.spawn(f"adb shell") shell.expect('login:', 5) shell.sendline("your username") shell.expect('Password:', 5) shell.sendline("your password")

Yann-Song commented 3 years ago

修改init.py 在 class _AdbStreamConnection(object): 中增加一个发数据方法,如下: def send_onlydata(self, data: str): self.conn.send("{}".format(data).encode("utf-8")) 在class AdbClient(object): 中增加一个登录方法,

   def login_adb(self,serial : str,username : str,password : str):
            msg = ''
            c = self._connect()
            c.send_command("host:transport:" + serial)
            c.check_okay()
            c.send_command("shell:")
            c.check_okay()
            while True:
                ch = c.read_string(1)
                msg = msg + ch
                if msg.find('ogin:') > 0:
                    c.send_onlydata(username)
                    msg = ''
                    continue
                elif msg.find('assword:') > 0:
                    c.send_onlydata(password)
                    msg = ''
                    continue
                elif msg.find('ncorrect') > 0:
                    print("error password / user account ")
                    self.__login = False
                    break
                elif msg.find('#') > 0:
                    self.__login = True
                    break
            return c

我的实现如上,python 不是熟悉,能看懂就行了

codeskyblue commented 2 years ago

什么手机啊,怎么还有用户名密码啊