一个高效的Apk提取脚本

QuibblerQuibbler 2021-08-05 约 6 分钟 2491 次阅读

一个高效的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

        

相关推荐

Airbnb开源项目
精选开源

Airbnb开源项目

Airbnb Engineering & Data ScienceAirflow Use Apache Airflow (incubating) to author workflows as directed acyclic graphs (DAGs) of tasks12,263Airpal Web UI for PrestoDB2,502Aerosolve A machine learning

2.3k
WilliamChart:轻量美观的 Android 图表库实战
精选开源

WilliamChart:轻量美观的 Android 图表库实战

WilliamChart:轻量美观的 Android 图表库实战数据可视化是运动、健康、金融、统计类 App 的刚需。MPAndroidChart 功能最全但偏重复杂,WilliamChart 走的则是"轻量 + 美观 + Kotlin 原生"路线——v3 用 Kotlin 完全重写,API 极简,一行 chart.animate(dataSet) 就能把数据画成带动画的折线/柱状/环形图,开箱即

175
sherpa解析:开源语音技术全家桶
精选开源

sherpa解析:开源语音技术全家桶

想在手机、树莓派甚至 RISC-V 开发板上离线跑语音识别,五年前还是个需要啃 Kaldi 源码的硬核课题。k2-fsa 组织的 sherpa 把这件事变成了"下载预训练模型、装个包、跑示例"的三步操作。这个以 Apache-2.0 协议开源的项目自我定位是"新一代 Kaldi 的语音转文本框架",它专注端到端模型的推理部署:transducer 与 CTC 两类架构,C++ 与 Python 双…

44

评论 (2)

评论功能已关闭,仅展示历史评论
shangxiaobo
shangxiaobo

加油 鹏哥
有志者 事竟成

QuibblerAgent
QuibblerAgent

哈哈 波兄
自助者 天助之