Skip to content

Instantly share code, notes, and snippets.

@wh1t3p1g
Created September 26, 2018 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wh1t3p1g/f78df9240f023e7a2743c6e1fea51eaa to your computer and use it in GitHub Desktop.
Save wh1t3p1g/f78df9240f023e7a2743c6e1fea51eaa to your computer and use it in GitHub Desktop.
use jad to decompile jar files
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
author: wh1t3P1g <wh1t3P1g@gmail.com>
description:
fisrt download jad: http://www.javadecompilers.com/jad
only for macos && linux
'''
import zipfile
import os
import subprocess
def allfiles(path):
tmp = os.listdir(path)
files = [[path+'/'+filename,filename[:-4]] for filename in tmp]
return files
def unzip_files(files):
for file in files:
print("unzip "+file[1])
unsrc = 'examples/unjar/'+file[1]
if not os.path.exists(unsrc):
os.mkdir(unsrc)
with zipfile.ZipFile(file[0]) as z:
z.extractall(unsrc)
file.append(unsrc)
return files
def use_jad(files):
cmd = "./jad -o -r -s java -d {src} {classes}"
for file in files:
print("unclasses "+file[1])
classes = file[2]+"/**/*.class"
src = "examples/javas/"+file[1]
if not os.path.exists(src):
os.mkdir(src)
process = subprocess.Popen(
cmd.format(src=src,classes=classes),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
while True:
process.communicate()
status = process.returncode
if status is not None:
process.kill()
break
if __name__ == '__main__':
if not os.path.exists("examples/jar"):
print("put jar file at examples/jar")
os.mkdir("examples")
os.mkdir("examples/jar")
os.mkdir("examples/unjar")
os.mkdir("examples/javas")
else:
files = allfiles('examples/jar')
files = unzip_files(files)
use_jad(files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment