用python解压分析jar包实例

 更新时间:2020年01月16日 16:57:15   作者:海峰-清欢  
今天小编就为大家分享一篇用python解压分析jar包实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

写这个玩意的背景:在u8多渠道打包里,需要分析jar包,并把里面的文件按目录和类型分别放在root和assets文件夹里,之前师兄都是手动解压,一个一个文件夹找文件,效率比较低,刚好最近手上的android项目已经做完了,就决定写一个自动化分析jar文件并复制粘贴到指定文件夹的脚本。

# -*- coding: utf-8 -*-
import os
import shutil
import zipfile
 
count = 1
def getSumDir():
  sumfilelist = os.listdir(os.getcwd())
  for dir in sumfilelist:
    if ".idea" not in dir:
      classify(dir)
 
 
def getlibDir():
  sumfilelist = os.listdir(os.getcwd())
  for dir in sumfilelist:
    if "libs" in dir:
      jieyajar(dir)
 
 
def jieyajar(dir):
  files = os.listdir(dir)
  for jars in files:
    if "jar" in jars:
      zfile = zipfile.ZipFile('libs/' + jars, 'r')
      if not os.path.exists(os.getcwd() + '/jarlog/' + jars):
        os.makedirs(os.getcwd() + '/jarlog/' + jars)
      zfile.extractall(os.getcwd() + '/jarlog/' + jars)
 
      if not os.path.exists(os.getcwd() + '/jars/'):
        os.makedirs(os.getcwd() + '/jars/')
      zfile.extractall(os.getcwd() + '/jars/')
      zfile.close
 
  for file in os.listdir(os.getcwd()):
    if "jars" in file:
      classify(file)
 
 
# def classify(path):
#   if os.path.isfile(path):
#     if ".class" not in path:
#       if "assets" in os.path.dirname(path):
#         if not os.path.exists(os.path.dirname(os.getcwd()) + '/assets/' + os.path.dirname(path)):
#           os.makedirs(os.path.dirname(os.getcwd()) + '/assets/' + os.path.dirname(path))
#         shutil.copy(path, os.path.dirname(os.getcwd()) + '/assets/' + os.path.dirname(path))
#       else:
#         if not os.path.exists(os.path.dirname(os.getcwd())+'/root/'+os.path.dirname(path)):
#          os.makedirs(os.path.dirname(os.getcwd())+'/root/'+os.path.dirname(path))
#         shutil.copy(path,os.path.dirname(os.getcwd())+'/root/'+os.path.dirname(path))
#   else :
#     list = os.listdir(path)
#     for dir in list:
#       classify(path+"/"+dir)
 
def classify(path):
  global count
  if os.path.isfile(path):
    if ".class" not in path:
      if not os.path.exists(os.getcwd() + '/root/' + os.path.dirname(path)):
        os.makedirs(os.getcwd() + '/root/' + os.path.dirname(path))
      shutil.copy(path, os.getcwd() + '/root/' + os.path.dirname(path))
  else:
    if 'assets' in path and count == 1:
      count = count + 1
      shutil.copytree(os.getcwd()+'/'+path, os.getcwd() + '/assets')
    elif 'META-INF' not in path:
      list = os.listdir(path)
      for dir in list:
        classify(path + "/" + dir)
 
 
# getSumDir()
getlibDir()

嗯,主要就是对文件夹和文件的操作。。

以上这篇用python解压分析jar包实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • YOLOv5车牌识别实战教程(七)实时监控与分析

    YOLOv5车牌识别实战教程(七)实时监控与分析

    这篇文章主要介绍了YOLOv5车牌识别实战教程(七)实时监控与分析,在这个教程中,我们将一步步教你如何使用YOLOv5进行车牌识别,帮助你快速掌握YOLOv5车牌识别技能,需要的朋友可以参考下
    2023-04-04
  • python matplotlib实现双Y轴的实例

    python matplotlib实现双Y轴的实例

    今天小编就为大家分享一篇python matplotlib实现双Y轴的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-02-02
  • 对Pycharm创建py文件时自定义头部模板的方法详解

    对Pycharm创建py文件时自定义头部模板的方法详解

    今天小编就为大家分享一篇对Pycharm创建py文件时自定义头部模板的方法详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-02-02
  • python文件及目录操作代码汇总

    python文件及目录操作代码汇总

    这篇文章主要介绍了python文件及目录操作代码汇总,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-07-07
  • python内置模块datetime.timedelta计算时间间隔示例代码

    python内置模块datetime.timedelta计算时间间隔示例代码

    Python的datetime模块提供了处理日期和时间的功能,包括datetime.date、datetime.time、datetime.datetime、datetime.timedelta等类,timedelta用于表示时间间隔,支持日期和时间的加减运算,文中给出了详细的代码示例,需要的朋友可以参考下
    2025-04-04
  • 详解python如何通过numpy数组处理图像

    详解python如何通过numpy数组处理图像

    Numpy 是 Python 中科学计算的核心库,NumPy 这个词来源于 Numerical 和 Python 两个单词。它提供了一个高性能的多维数组对象,以及大量的库函数和操作,可以帮助程序员轻松地进行数值计算,广泛应用于机器学习模型、图像处理和计算机图形学、数学任务等领域
    2022-03-03
  • Python爬虫实战之虎牙视频爬取附源码

    Python爬虫实战之虎牙视频爬取附源码

    读万卷书不如行万里路,学的扎不扎实要通过实战才能看出来,本篇文章手把手带你爬取虎牙短视频数据,大家可以在实战过程中查缺补漏,加深学习
    2021-10-10
  • 基于Python实现一个春节倒计时脚本

    基于Python实现一个春节倒计时脚本

    春节即将到来,本文将为大家介绍一个通过Python实现的春节倒计时脚本,文中的示例代码简洁易懂,感兴趣的小伙伴可以自己动手尝试一下
    2022-01-01
  • python中对开区间和闭区间的理解

    python中对开区间和闭区间的理解

    这篇文章主要介绍了python中对开区间和闭区间的理解,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-07-07
  • selenium+headless chrome爬虫的实现示例

    selenium+headless chrome爬虫的实现示例

    这篇文章主要介绍了selenium+headless chrome爬虫的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-01-01

最新评论