Windows Batch / ADB - 检查安装的.apk是否与目录中的.apk匹配

时间:2017-03-15 16:14:54

标签: android batch-file adb aapt

我正在使用 FOR 命令和 AAPT 命令从目录中的多个 APK 中获取包名称。我使用单独的 FOR 命令和 ADB 命令列出设备中所有第三方安装的应用程序。

我不确定如何交叉引用这些以获得我想要的输出。我试图查看 ADB 命令的输出中是否出现 AAPT 命令的任何内容。如果2个变量匹配,则不执行任何操作。否则,如果 AAPT 与任何 ADB 输出都不匹配,请显示该循环的 AAPT 命令的包名称。

我希望你能理解我想要实现的目标。请参阅下面的尝试:

::Global
@echo off

set AAPT=tools\aapt.exe
set GREP=tools\grep.exe
set CUT=tools\cut.exe

:: Applications
cls
@echo.
@echo ------------------------ CHECK APPLICATIONS INSTALLED --------------------------

SETLOCAL ENABLEDELAYEDEXPANSION
@echo -- EXTRACT PACKAGENAME FROM APK --
FOR /F "tokens=1,2 skip=1" %%N IN ('adb devices') DO (
    SET IS_DEV=%%O
    if "!IS_DEV!" == "device" (
        SET SERIAL=%%N
        for /f "delims=" %%P in ('dir /b ^"APKs\*.apk^"') do (
            SET APK=%%P
            for /f "tokens=1 delims=" %%Q in ('%AAPT% d badging APKs\!APK! ^| !GREP! "package: name=" ^| !CUT! -d' -f2') do (
                set package=%%Q
                if "!package!" == "" set package=Unknown (
                echo !package!
                )
            )
        )
    )
)
@echo.
@echo -- EXTRACT INSTALLED PACKAGENAME --
FOR /F "tokens=1,2 skip=1" %%R IN ('adb devices') DO (
    if "!IS_DEV!" == "device" (
        FOR /F "tokens=1 delims=" %%U IN ('adb shell "pm list packages -3" ^| !CUT! -f 2 -d ":"^') DO (
        SET DEVPACKAGE=%%U
        echo !DEVPACKAGE!
                )
            )
        )
    )
)
@echo.
@echo -- CHECK IF ALL "DEVPACKAGE" MATCHES "PACKAGE" AND LOOP --
for /f "delims=" %%S in ('dir /b ^"APKs\*.apk^"') do (
    if "!package:*%DEVPACKAGE%=!" neq "!package!" (
    echo !package! matched
    ) else (
    echo !package! did not match
    )
)
ENDLOCAL
@pause

我收到的输出是:

------------------------ CHECK APPLICATIONS INSTALLED --------------------------

-- EXTRACT PACKAGENAME FROM APK --
com.microsoft.office.lync15
com.microsoft.office.officehub
com.yammer.v1
com.teslacoilsw.launcher
yes.worldpaytotal
com.yahoo.mobile.client.android.weather

-- EXTRACT INSTALLED PACKAGENAME --
com.yahoo.mobile.client.android.weather
de.worldiety.photiety.cewe.smartphoto.de
com.estrongs.android.pop
com.yammer.v1
de.zalando.mobile
com.microsoft.office.officehub
de.kaufda.android
com.microsoft.office.lync15
com.kronos.mobile.android
com.manageengine.adssp.passwordselfservice
com.teslacoilsw.launcher
yes.worldpaytotal

-- CHECK IF ALL "DEVPACKAGE" MATCHES "PACKAGE" AND LOOP --
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
Press any key to continue . . .

如果有人能够提供帮助,我将不胜感激!

0 个答案:

没有答案