jar包、class文件批量反编译并解压
该脚本可以在一个java工程目录下自动搜寻jar包、class文件,并在同级目录下创建一个新的文件夹来保存反编译和解压结果。
使用反编译插件为fernflower.jar,下面是下载地址:
https://github.com/JsonDiv/jar-decompile
环境:需要安装java环境
使用方法:修改代码中的两个参数,保存代码为xxx.py,使用命令python xxx.py即可。
批量反编译代码如下:
#python3
#aotoman
#20200318
import os
import zipfile
#参数:1、工程目录;2、编译插件路径
def decompile(filepath,toolpath):
for root,dirs,files in os.walk(filepath):
print('[+] '+root)
for filename in files:
if '.jar' in filename or '.class' in filename:
if not os.path.exists(root+'_src_'):#自动在jar包同级目录下创建以_src结尾的文件夹,用以存放反编译后的jar包和解压包
os.makedirs(root+'_src_')
try:
os.system('java -jar {0} {1} {2}'.format(toolpath,root+'/'+filename,root+'_src_'))
with zipfile.ZipFile(root+'_src_'+'/'+filename, 'r') as zzz:
zzz.extractall(root+'_src_'+'/'+filename[:-4])
os.remove(root+'_src_'+'/'+filename)
except:
print('error:'+root+'/'+filename)
if __name__ == '__main__':
filepath='/Users/testClass/' #1、需要编译的工程目录
toolpath='/Users/tools/jar_decompile/fernflower.jar' #2、编译软件路径
decompile(filepath,toolpath)