Skip to content

Instantly share code, notes, and snippets.

@etng
Created May 2, 2018 22:44
Show Gist options
  • Save etng/dc281a5e3014ecab845a6be028625928 to your computer and use it in GitHub Desktop.
Save etng/dc281a5e3014ecab845a6be028625928 to your computer and use it in GitHub Desktop.
提取0day包中内容
from __future__ import print_function
import os
import glob
import sys
from shutil import rmtree, copyfile
unzip_path = '"C:/Program Files/7-Zip/7z.exe"'
unrar_path = '"C:/Program Files/WinRAR/rar.exe"'
dst = "D:/download/books1"
def extract0day(p):
# try:
# assert 'file_id.diz' in os.listdir(p)
# except:
# print 'not 0day dir: ', p
# if raw_input('press y to continue') == 'y':
# return
zipfiles = [_ for _ in os.listdir(p) if _.endswith('.zip')]
[os.path.exists(_) or os.makedirs(_) for _ in 'tmp tmp1'.split()]
cmd_fmt = '{} x -otmp -aoa {}'
cmds = [cmd_fmt.format(unzip_path, os.path.join(p, _)) for _ in zipfiles]
print(cmds)
#sys.exit()
map(os.system, cmds)
entry_rar = glob.glob('tmp/*.rar')[0]
os.system('{} x {} -o+ -y {}'.format(unrar_path, entry_rar, 'tmp1'))
print(os.listdir('tmp1'))
#import ipdb;ipdb.set_trace()
for filename in glob.glob('tmp/*.nfo'):
print("copy", filename)
copyfile(filename, os.path.join(dst, os.path.basename(filename)))
for filename in glob.glob('tmp1/*.*'):
print("copy", filename)
copyfile(filename, os.path.join(dst, os.path.basename(filename)))
print(p)
if raw_input('press y to continue') == 'y':
rmtree('tmp1')
rmtree('tmp')
if len(sys.argv) > 1:
p = sys.argv[1]
else:
for filename in os.listdir('.'):
if os.path.isdir(filename) and filename not in ('tmp', 'unzipped', 'tmp1'):
extract0day(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment