一个高效的Apk提取脚本

Quibbler 2021-8-5 947

一个高效的Apk提取脚本


        开发者如何将手机上已安装应用的安装包提取导出到电脑上呢?


        以前是这样做的,只需要简单三步:

        利用焦点拿到当前打开的应用包名(如果已经知道需要导出的应用包名,可以跳过此步)

    adb shell dumpsys window | findStr mCurrentFocus

        知道应用包名后,通过pm获取安装包路径

    adb shell pm path $package

        最后就是将apk从手机中pull出来。注意如果路径包含'/base.apk'需要加一个'/'改成'//base.apk',后面写的脚本有这一步处理。

    adb pull $path


        还可以更快,更高效,翻出被遗忘的shell记忆,将前面有关联的三步操作写成一个shell脚本。一键提取当前打开的应用安装包,并以包名重命名Apk。传到并没有几个人知道的Github:github/quibbler01/apk-extraction

#Copyright [2021] [Quibbler.cn]
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.


#current focused App, output: mCurrentFocus=Window{c053bb9 u0 com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity}
focus=`adb shell dumpsys window | findStr mCurrentFocus`


#extract out {package/class}, output: com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity
classpath=`echo ${focus} | awk '{print $3}'`


#crop string extract package name, output: com.ss.android.ugc.aweme
package=`echo ${classpath%/*}`


#figure out this package install path, output: package:/data/app/com.ss.android.ugc.aweme-bWD-6eHGY_JWxoiHreHc5A==/base.apk
path=`adb shell pm path $package`

#sub path from pm output's, output: data/app/com.ss.android.ugc.aweme-bWD-6eHGY_JWxoiHreHc5A==/base.apk
path=`echo ${path#*/}`

#and replace '/' with '//' if path include '/base.apk',E.g: data/app/com.vivo.easyshare-Q46ic5yVLxvgkiPRkB318Q==//base.apk
if [[ $path =~ /base.apk ]]; then
	path=`echo ${path///base.apk///base.apk}`
fi


#pull apk out renanme with package name
adb pull $path  $package.apk


        apk_extraction用着比较方便,突然又想到一个功能点:不带参数运行脚本导出当前手机焦点应用(默认);如果带着包名参数运行该脚本,那么提取指定包名的安装包,如:

    #有空提交到GitHub上
    apk_extraction -p com.tencent.mobileqq

        


相关博客:

        APK反编译

        Apk的安装过程探究

        命令纠错工具:thefuck

        

不忘初心的阿甘
最新回复 (2)
  • shangxiaobo 2021-8-6
    2
    加油 鹏哥
    有志者 事竟成
  • 析物言理 2021-8-6
    3
    哈哈 波兄
    自助者 天助之
    • 安卓笔记本
      4
        登录 注册 QQ
返回
仅供学习交流,切勿用于商业用途。如有错误欢迎指出:fluent0418@gmail.com