Slide 96
Slide 96 text
#!/usr/bin/python
import os
import subprocess
import sys
list = subprocess.check_output(["dex-method-list", sys.argv[1]])
class_info_by_name = {}
for item in list.split('\n'):
first_space = item.find(' ')
open_paren = item.find('(')
close_paren = item.find(')')
last_space = item.rfind(' ')
class_name = item[0:first_space]
method_name = item[first_space + 1:open_paren]
params = [param for param in item[open_paren + 1:close_paren].split(', ') if len(param) > 0]
return_type = item[last_space + 1:]
if last_space < close_paren:
return_type = 'void'
# print class_name, method_name, params, return_type
if class_name not in class_info_by_name:
class_info_by_name[class_name] = {}
class_info = class_info_by_name[class_name]
if method_name not in class_info:
class_info[method_name] = []
method_info_by_name = class_info[method_name]
method_info_by_name.append({
'params': params,
'return': return_type
})
count = 0
for class_name, class_info in class_info_by_name.items():
for method_name, method_info_by_name in class_info.items():
for method_info in method_info_by_name:
for other_method_info in method_info_by_name:
if method_info == other_method_info:
continue # Do not compare against self.
params = method_info['params']
other_params = other_method_info['params']
if len(params) != len(other_params):
continue # Do not compare different numbered parameter lists.
match = True
erased = False
for idx, param in enumerate(params):
other_param = other_params[idx]
if param != 'Object' and not param[0].islower() and other_param == 'Object':
erased = True
elif param != other_param:
match = False
return_type = method_info['return']
other_return_type = other_method_info['return']
if return_type != 'Object' and other_return_type == 'Object':
erased = True
elif return_type != other_return_type:
match = False
if match and erased:
count += 1
# print "FOUND! %s %s %s %s" % (class_name, method_name, params, return_type)
# print " %s %s %s %s" % (class_name, method_name, other_params, other_return_type)
print os.path.basename(sys.argv[1]) + '\t' + str(count)
erased.py