Skip to content

Instantly share code, notes, and snippets.

@tp7309
Last active November 18, 2022 09:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tp7309/73d336e0ad431cde4ef2ca714c63b084 to your computer and use it in GitHub Desktop.
Save tp7309/73d336e0ad431cde4ef2ca714c63b084 to your computer and use it in GitHub Desktop.
fix adb unauthorized issue
chcp 65001
@echo fix adb unauthorized issue, can only fix one PC, run it in recovery mode
@echo 用于修复nexus6p不能连接adb的问题,在recovery模式下运行此脚本。
set currentDir=%~dp0
@echo add local fastboot to PATH variable
@set PATH=%currentDir%lib\platform-tools;%PATH%
adb devices 2>nul | findstr /r /c:"recovery" || @echo "error : device not in recovery mode" && pause && exit /B 1
@echo off
echo fix adb connection
REM maybe need recreate adbkey.pub
adb kill-server
adb start-server
set ADBKEY=%userprofile%\.android\adbkey.pub
if not exist %ADBKEY% (
echo can not find %ADBKEY% !
) else (
adb pull /data/misc/adb/adb_keys .
set /p content=<%ADBKEY%
set rawid=unknown@unknown
set rawid2= @unknown
set newid=%username%_%computername%@tp7309.com
call set result=%%content:%rawid%=%newid%%%
call set result=%%content:%rawid2%= %newid%%%
REM fuck echo variable must be in echo on mode!
@echo on
echo %result%
echo %result% | findstr /C:"@" > nul && (
REM normal
) || (
echo "invalid adb device public key, please try again!"
goto :exit0
)
echo %result% > %ADBKEY%
echo %result% >> adb_keys
@echo off
adb push adb_keys /data/misc/adb/adb_keys
del /f adb_keys
echo fix adb connnection done!
)
adb reboot
goto exit0
:exit0
pause
#!/bin/sh
echo fix adb unauthorized issue, can only fix one PC, run it in recovery mode
echo 用于修复nexus6p不能连接adb的问题,在recovery模式下运行此脚本
echo add local fastboot to PATH variable
export PATH="${currentDir}/lib/platform-tools;$PATH"
adb devices | grep "recovery" || (echo "error : device not in recovery mode" && exit)
echo maybe need recreate adbkey.pub
adb kill-server
adb start-server
ADBKEY=~/.android/adbkey.pub
if [ ! -f $ADBKEY ]; then
echo can not find $ADBKEY!
fi
adb pull /data/misc/adb/adb_keys .
if [ -f adb_keys ]; then
echo -e '\n' >> adb_keys
fi
rawid="unknown@unknown"
newid="$(id -u -n)_$(hostname)@tp7309.com"
cat $ADBKEY | sed "s/${rawid}/${newid}/g" > $ADBKEY
cat $ADBKEY | sed 's/$rawid/$newid/g' >> adb_keys
adb push adb_keys /data/misc/adb/adb_keys
rm -f adb_keys
echo fix adb connnection done!
adb reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment