1
# Copyright (C) 2009 JavaRosa
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4
# use this file except in compliance with the License. You may obtain a copy of
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations under
20
default_jarfile = 'JavaRosaDemo.jar'
21
default_obfusmapfile = 'obfuscation_mapping.txt'
22
default_outfile = 'jar_contents.csv'
24
#determine sort order of a file
25
suffix_order = ['class', 'xhtml']
27
suffix = s.rsplit('.', 1)[-1]
29
ordinal = suffix_order.index(suffix)
31
ordinal = len(suffix_order)
34
#initialize and parse parameters
35
if len(sys.argv) == 1: #no args, use defaults
36
jarfile = default_jarfile
37
obfusmapfile = default_obfusmapfile
38
elif len(sys.argv) == 2: #one arg, assume path
42
jarfile = path + default_jarfile
43
obfusmapfile = path + default_obfusmapfile
44
else: #assume arg1 = jar file, arg2 = obfuscation mapping
46
obfusmapfile = sys.argv[2]
47
outfile = default_outfile
49
print 'JAR file: %s' % jarfile
50
print 'Obfuscation mapping: %s' % obfusmapfile
51
print 'Output written to: %s' % outfile
54
zipf = zipfile.ZipFile(jarfile, 'r')
56
for i in zipf.infolist():
57
contents[i.filename] = (i.file_size, i.compress_size)
59
#build de-obfuscation mapping
60
maptxt = open(obfusmapfile, 'r').readlines()
62
for line in filter(lambda s: re.compile('^ ').match(s) == None, maptxt): #classname mappings have no leading whitespace
63
mapmatch = re.compile('^(?P<class>[A-Za-z0-9._$]+) -> (?P<tag>[a-z]+):$').search(line)
64
if mapmatch != None: #None means class was not obfuscated
65
mapentry = mapmatch.groupdict()
66
obfusmap['%s.class' % mapentry['tag']] = '%s.class' % mapentry['class'].replace('.', '/')
69
for file, info in contents.copy().iteritems():
72
contents[obfusmap[file]] = info
75
fout = open(outfile, 'w')
76
fout.write('File,Uncompressed Size (KB),Size in JAR (KB)\n')
77
for _, file in sorted(map(sort_filename, contents.iterkeys())):
78
(size, compr_size) = contents[file]
79
fout.write('%s,%s,%s\n' % (file, size/BYTE_KB, compr_size/BYTE_KB))
b'\\ No newline at end of file'