Android ADB批处理脚本

时间:2021-01-02 23:06:55



以下信息全部为批处理,复制代码到记事本保存为.BAT后缀。例:apk信息查看.bat

1.APK信息查看

@ECHO OFF

ECHO [查看APK包信息]

ECHO -------------------------------

ECHO aapt dump badging %~nx1

aapt dump badging %1 > %~dp0%~n1.txt

ECHO [暂停3秒自动关闭...]

ping -n 3 127.0.0.1>nul
@ECHO ON


2.APK自动安装

@ECHO OFF

ECHO [安装APK]

ECHO -------------------------------

ECHO [等待插入手机...]

adb wait-for-device

ECHO [安装] %~nx1

adb install -r %1

ECHO [暂停5秒自动关闭...]

ping -n 5 127.0.0.1>nul

@ECHO ON

3.读取手机信息保存为文件

@ECHO OFF 
ECHO [读取手机信息]

ECHO -------------------------------

adb shell cat /system/build.prop>%~dp0\phone.info

FOR /F "tokens=1,2 delims==" %%a in (phone.info) do (

IF %%a == ro.build.version.release SET androidOS=%%b

IF %%a == ro.product.model SET model=%%b

IF %%a == ro.product.brand SET brand=%%b

)

del /a/f/q %~dp0\phone.info

ECHO.

ECHO.手机品牌: %brand%

ECHO.手机型号: %model%

ECHO.系统版本: Android %androidOS%



ECHO.-------------------------------

ECHO.手机品牌: %brand%>"%~dp0\Phone_%model%.txt"

ECHO.手机型号: %model%>>"%~dp0\Phone_%model%.txt"

ECHO.系统版本: Android %androidOS%>>"%~dp0\Phone_%model%.txt"

ECHO [暂停5秒自动关闭...]

ping -n 5 127.0.0.1>nul

@ECHO ON


4.手机截屏保存为根目录

@ECHO OFF

ECHO.[快速手机截屏]

ECHO.-------------------------------

ECHO.[Exce ] 手机截屏

adb shell screencap -p /sdcard/screen.png

ECHO.[Tips ] 拷贝截屏图片至电脑

adb pull /sdcard/screen.png "%~dp0\screen.png"

ren screen.png "%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.png"

adb shell rm /sdcard/screen.png

ECHO [暂停2秒自动关闭...]

ping -n 2 127.0.0.1>nul

@ECHO ON

5.快速截屏保存为跟目录

@ECHO OFF

ECHO.[快速手机截屏]

ECHO.-------------------------------

ECHO.[Exce ] 手机截屏

adb shell screencap -p /sdcard/screen.png

ECHO.[Tips ] 拷贝截屏图片至电脑

adb pull /sdcard/screen.png "%~dp0\screen.png"

ren screen.png "%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.png"

adb shell rm /sdcard/screen.png

ECHO [暂停2秒自动关闭...]

ping -n 2 127.0.0.1>nul

@ECHO ON

6.导出Logcat日志

@ECHO OFF

ECHO.[导出logcat日志]

ECHO.-------------------------------

adb logcat -d>"%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.log"

ECHO.[暂停5秒自动关闭...]

ping -n 5 127.0.0.1>nul

@ECHO ON

7.android测试内存监控

@ECHO OFF

COLOR 0A

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::

ECHO.:: ::

ECHO.:: 内存(RAM)监控显示V1.0 ::

ECHO.:: ::

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::

::::::: 用于监控APP占用内存 ::

::::::: ::

::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET packagename=tv.fuzegame.fuzelauncher



:: 获取得小时,格式为:24小时制,10点前补0

SET c_time_hour=%time:~0,2%

IF /i %c_time_hour% LSS 10 (

SET c_time_hour=0%time:~1,1%

)

SET logfilename="%~dp0%date:~0,4%%date:~5,2%%date:~8,2%%c_time_hour%%time:~3,2%%time:~6,2%_RAM.txt"

ECHO."内存信息监控" >%logfilename%

:Startscreencap

adb shell procrank >>%logfilename%

CLS

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::

ECHO.:: ::

ECHO.:: APP内存信息监控显示 ::

ECHO.:: ::

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::

ECHO. PID Vss Rss Pss Uss cmdline

FINDSTR /C:"%packagename%" %logfilename%

ping -n 2 127.0.0.1>nul

GOTO Startscreencap


7. Activity启动跳转时间监控

@ECHO OFF

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::

ECHO.:: ::

ECHO.:: Activity启动跳转时间监控 V1.0 ::

ECHO.:: ::

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::

::::::: ::

::::::: ::

::::::::::::::::::::::::::::::::::::::::::::::::::::::

ECHO.[ INFO ] 清空日志

adb logcat -c

ECHO.[ INFO ] 监控开始(Ctrl+C结束)

ECHO.[ INFO ] 保存请拷贝输出内容

adb logcat -s ActivityManager|Findstr /C:": Displayed"


8.查看RSA、APK、keystore签名信息

@ECHO OFF

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::

ECHO.:: ::

ECHO.:: 查看APK签名信息 ::

ECHO.:: ::

ECHO.:::::::::::::::::::::::::::::::::::::::::::::::::


::::::::::::::::::::::::::::::::::::::::::::::::::::::

Color 0A

ECHO.

ECHO.[ HELP ] 可查看RSA、APK、keystore签名信息

SET C_PATH=%~dp0

REM 方法:直接将APK或RSA文件到bat文件上

IF NOT "%1"=="" SET apkorFile=%1

IF "%~x1"==".RSA" GOTO RSAFile

IF "%~x1"==".rsa" GOTO RSAFile

IF "%~x1"==".apk" GOTO APKFile

IF "%~x1"==".APK" GOTO APKFile

IF "%~x1"==".keystore" GOTO KEYSTOREFile

IF "%~x1"==".KEYSTORE" GOTO KEYSTOREFile



Color 0D

ECHO.[ INFO ] 你是猴子派来的逗逼吧?

ECHO.[ HELP ] 请将RSA或得APK或者keystore拖至Bat文件上

GOTO BATend



:KEYSTOREFile

DEL "%C_PATH%%~nx1.txt" 2>nul

ECHO.[ INFO ] INPUT:%apkorFile%

ECHO.[ INFO ] OUT: %C_PATH%%~nx1.txt

ECHO.

keytool -list -v -keystore %apkorFile% > "%C_PATH%%~nx1.txt"

type "%C_PATH%%~nx1.txt"

GOTO BATend



:RSAFile

DEL "%C_PATH%%~n1.RSA.txt" 2>nul

ECHO.[ INFO ] INPUT:%apkorFile%

ECHO.[ INFO ] OUT: %C_PATH%%~n1.RSA.txt

ECHO.

keytool -printcert -file %apkorFile% > "%C_PATH%%~n1.RSA.txt"

type "%C_PATH%%~n1.RSA.txt"

GOTO BATend



:APKFile

ECHO.[ INFO ] INPUT:%apkorFile%

ECHO.[ INFO ] OUT: %C_PATH%%~n1.RSA.txt

RD /S /Q %~n1_META-INF 2>nul

::jar tf %apkorFile%|Findstr "RSA"

::解压签名目录

jar -xf %apkorFile% META-INF

::重合名文件夹

REN META-INF %~n1_META-INF

::查看签名文件信息

CD %~n1_META-INF

FOR %%I IN (*.RSA) DO (

ECHO.[ INFO ] %%I

ECHO.

keytool -printcert -file %%I > "%C_PATH%%~n1.RSA.txt"

type "%C_PATH%%~n1.RSA.txt"

)

CD %~dp1

RD /S /Q %~n1_META-INF 2>nul



:BATend

ECHO.

ECHO.[ EXIT ] 按任意键关闭窗口...

PAUSE>nul