自动化打包资源混淆集成python实践----资源混淆
前面自動化打包資源混淆集成python實踐----打包一文講述了四種打包方案,以及美團打包方案、apk注釋添加渠道號方案的實現(xiàn)。這里講集成資源混淆。
1、資源混淆帶來的好處:
? ?1)對資源文件起一定的保護作用,使其不能知其名不知意(如login.png ----a.png> )
? ?2)對壓縮apk包大小,起一定的作用(混淆資源ID長度,對apk進行深度壓縮)
2.方案種類
? ?1)美團資源混淆
? ? ? ? 原理:干涉appt過程,改寫appt 源碼,在生成resources.arsc和*.ap_時把資源文件的名稱進行替換
? ?2)微信資源混淆
? ? ? ? 原理:對apk 中的resources.arsc進行內(nèi)容修改,同時對apk進行深度壓縮。
3.Python 集成微信資源混淆
? ? 1)思路:gradle 打包 ---->微信資源打包 --->多渠道打包
? ? 2)python實現(xiàn)
? ? ? ? ?(1)使用微信資源混淆方法
? ? ? ? ? ? ? ? ? 法1:定義gradle?andResGuard ?task,?./gradlew?andresguard?
? ? ? ? ? ? ? ? ? 法2:直接用命令行執(zhí)行 ?java -jar resourceproguard.jar input.apk -7zip /shwenzhang/tool/7za -zipalign /shwenzhang/sdk/tools/zipalign
? ? ? ? ? ? ? ? ? ps:這里使用法2使用混淆
? ? ? ? (2)源碼:
? ? ? ? ? ?
def func_andResGuard(apkPath,isChannels = False):#根據(jù)AndResGuard-cli-1.1.0.jar,config.xml 實際路徑替換guardJarFile = workSpace + '/AndResGuard/AndResGuard-cli-1.1.0.jar'guardConfigFile = workSpace + '/AndResGuard/config.xml'outDir = workSpace + '/AndResGuard/build'cmd = 'java -jar ' + guardJarFile + ' '+apkPath + ' -config ' + guardConfigFile + ' -out '+ outDir +' -zipalign ' + zipalignFileproc = subprocess.Popen(cmd,shell = True)if isChannels:func_listen_process(proc,AndResGuardProcessListener(apkPath,True))else:func_listen_process(proc,AndResGuardProcessListener(apkPath))#andResGuard進程監(jiān)聽器 class AndResGuardProcessListener(ProcessListener):curTime = 0isChannels = FalseapkPath = ''preApkSize = 0def __init__(self,apkPath,isChannels = False):self.isChannels = isChannelsself.apkPath = apkPathdef start(self):size =os.path.getsize(self.apkPath)self.preApkSize = size /float(1024)/1024self.curTime = time.time()print '\n ------> AndResGuard start \n' def doing(self):returndef end(self):time.sleep(30)files = os.listdir(workSpace + '/AndResGuard/build')for f in files :if 'signed_7zip_aligned' in f:size = os.path.getsize(workSpace + '/AndResGuard/build/' + f)print '\n ------> AndResGuard before apk size : ' + str(float('%0.2f'%(self.preApkSize))) + 'M\n'size = size /float(1024)/1024print '\n ------> AndResGuard after apk size : ' + str(float('%0.2f'%size)) + 'M\n'os.chmod( self.apkPath, stat.S_IWRITE )os.remove(self.apkPath)shutil.copyfile(workSpace + '/AndResGuard/build/' + f,self.apkPath)breakelse :print ''self.curTime = time.time() - self.curTime - 10print '\n ------> AndResGuard end , cost time '+ str(int(self.curTime)) +'s\n\n'if self.isChannels:func_channelsReleasePack(workSpace)?
4、混淆壓縮效果:
?
ps:使用友盟分享功能時,需要在config.xml添加資源白名單(友盟根據(jù)資源名獲取資源ID,而資源名被混淆了,導(dǎo)致資源找不到),填寫正確的簽名信息(否則微信分享調(diào)用 不起來)。
github:github:AndroidPackCi
?
?
?
參考資料:
美團Android資源混淆保護實踐
安裝包立減1M--微信Android資源混淆打包工具
https://github.com/shwenzhang/AndResGuard
Android應(yīng)用程序資源的編譯和打包過程分析
轉(zhuǎn)載于:https://www.cnblogs.com/sihaixuan/p/5326289.html
總結(jié)
以上是生活随笔為你收集整理的自动化打包资源混淆集成python实践----资源混淆的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到水池里有蛇预示着什么
- 下一篇: python中实现定时器Timer