Created
November 25, 2013 13:02
-
-
Save NorimasaNabeta/7640885 to your computer and use it in GitHub Desktop.
ブラウザのキャッシュ・ディレクトリを浚い、フラッシュアプリのリソースファイルを分類して集める(ブラウザ起動時にはキャッシュ内のファイルはブラウザが握っているので、アクセスエラーになる。実行するまえにブラウザを落とすことが必要)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: python; coding: utf-8 -*- | |
# | |
# Time-stamp: <Mon Nov 25 21:48:04 東京 (標準時) 2013> | |
# | |
# | |
import os | |
import sys | |
import glob | |
import shutil | |
import hashlib | |
# for debug | |
# | |
# | |
def buffer2hexlist(buffer, start, count): | |
result = [] | |
for item in range(count): | |
result.append('%02X' % ord(buffer[start + item])) | |
return result | |
# file signature string | |
# | |
# | |
def fileSignature(filePath): | |
magic = { | |
'SWF': [ '43', '57', '53' ], | |
'ID3': [ '49', '44', '33' ], | |
'MP3': [ 'FF', 'FB' ], | |
'JPG': [ 'FF', 'D8' ], | |
'PNG': [ '89', '50', '4E', '47' ], | |
'BMP': [ '42', '4D' ], | |
'GIF': [ '47', '49', '46', '38' ], | |
'GZIP': [ '1F', '8B' ] | |
} | |
with open(filePath, "rb") as file: | |
data = file.read(8) | |
blist = buffer2hexlist(data, 0, 8) | |
file.close() | |
for ftype, signature in magic.iteritems(): | |
flag = 1 | |
for id,val in zip(signature, blist): | |
if id != val: | |
flag = 0 | |
break | |
if flag == 1: | |
return ftype | |
return 'UNKNOWN' | |
# move to your storage | |
# | |
# | |
def retrieveFile( fileType, fileName ): | |
result = ' ' | |
storageDir = os.path.join(".",fileType) | |
dupfile = os.path.join(storageDir,fileName) | |
# strorage folder check and create | |
if not os.path.exists(storageDir): | |
os.makedirs(storageDir) | |
# file check and copy | |
if not os.path.exists(dupfile): | |
shutil.copyfile(f, dupfile) | |
result = '+' | |
# else: | |
# print "already have" | |
return result | |
# Chrome's default cache | |
# "c:/Users/Admiral/AppData/Local/Google/Chrome/User Data/Default/Cache" | |
# | |
# USAGE: | |
# $ python kanColleCache.py "c:/Users/Admiral/AppData/Local/Google/Chrome/User Data/Default/Cache" | |
# | |
# UNKNOWN のdata_0+5,index 以外を解析のためにフォルダに保存しる。 | |
# | |
if __name__ == '__main__': | |
for path in sys.argv[1:]: | |
for fname in os.listdir(path): | |
f = os.path.join(path,fname) | |
if os.path.isdir(f): | |
continue | |
hash = hashlib.md5(f).hexdigest() | |
fsig = fileSignature(f) | |
result = ' ' | |
if fsig == 'SWF': | |
# swf or swc file | |
result = retrieveFile('SWF', hash+".swf") | |
elif fsig == 'MP3': | |
result = retrieveFile('MP3', hash+".mp3") | |
# elif fsig == 'GZIP': | |
# # compressed jQuery library files | |
# result = retrieveFile('GZIP', hash+".gz") | |
# elif fsig == 'PNG': | |
# result = retrieveFile('PNG', hash+".png") | |
# elif ((fsig == 'UNKNOWN') | |
# and (fname != 'index') | |
# and (fname != 'data_0') and (fname != 'data_1') and (fname != 'data_2') and (fname != 'data_3')): | |
# result = retrieveFile('UNKNOWN', hash) | |
print "%(pmark)s%(hash)s : %(signature)s %(filename)s" % { | |
'pmark':result, 'hash':hash, 'signature':fsig, 'filename':fname} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment