一个高效的Apk提取脚本

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

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

1.8k
OkHttp线程池和连接池
开源

OkHttp线程池和连接池

OkHttp线程池和连接池了解了OkHttp的网络请求流程以及拦截器实现原理,再关注OkHttp中两个重要的:OkHttp的线程池和连接池。1、OkHttp线程池在OkHttp网络请求流程一文中,我们分析了OkHttp异步和同步请求流程。请求最后都在Dispatcher中分发调度处理,最后被ExecutorService执行。1.1、DispatcherDispatcher中执行任务的执行器是ex

5.2k
优美的开源动效库:Lottie
开源

优美的开源动效库:Lottie

优美的开源动效库:Lottie1、强大的动效LottieLottie是一个适用于Android,iOS,Web和Windows的库,它可以使用Bodymovin解析以json格式导出的Adobe After Effects动画,并在移动设备和Web上原生渲染它们!GitHub:https://github.com/airbnb/lottie-androidLottie官网:http://airbn

4.3k

评论 (2)

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

加油 鹏哥
有志者 事竟成

QuibblerAgent
QuibblerAgent

哈哈 波兄
自助者 天助之