Skip to content

Instantly share code, notes, and snippets.

@ChaosLeung
Last active December 24, 2021 01:57
Show Gist options
  • Save ChaosLeung/798115ce4e9c83f23ffcd36414f1a89a to your computer and use it in GitHub Desktop.
Save ChaosLeung/798115ce4e9c83f23ffcd36414f1a89a to your computer and use it in GitHub Desktop.
Modified version helper scripts base from "Exploring Java Hidden Costs" presentation.
#!/bin/bash
set -e
METHODS=$(diffuse members --methods $1 | \grep 'access\$')
ACCESSORS=$(echo "$METHODS" | wc -l | xargs)
METHOD_AND_READ=$(echo "$METHODS" | egrep 'access\$\d+00\(' | wc -l | xargs)
WRITE=$(echo "$METHODS" | egrep 'access\$\d+02\(' | wc -l | xargs)
PREINC=$(echo "$METHODS" | egrep 'access\$\d+04\(' | wc -l | xargs)
PREDEC=$(echo "$METHODS" | egrep 'access\$\d+06\(' | wc -l | xargs)
POSTINC=$(echo "$METHODS" | egrep 'access\$\d+08\(' | wc -l | xargs)
POSTDEC=$(echo "$METHODS" | egrep 'access\$\d+10\(' | wc -l | xargs)
OTHER=$(($ACCESSORS - $METHOD_AND_READ - $WRITE - $PREINC - $PREDEC - $POSTINC - $POSTDEC))
NAME=$(basename $1)
echo -e "$NAME\t$ACCESSORS\t$METHOD_AND_READ\t$WRITE\t$PREINC\t$PREDEC\t$POSTINC\t$POSTDEC\t$OTHER"
#!/usr/bin/python
import os
import subprocess
import sys
list = subprocess.check_output(['diffuse', 'members', '--methods', '--apk', sys.argv[1]]).decode('utf-8')
primitive_types = ['int', 'byte', 'short', 'long', 'float', 'double', 'boolean', 'char']
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):
# Do not compare different numbered parameter lists.
continue
match = True
erased = False
for idx, param in enumerate(params):
other_param = other_params[idx]
if param != 'Object' and not param in primitive_types 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))
#!/bin/bash
set -e
ALL=$(diffuse members --methods $1)
LAMBDA_METHODS=$(echo "$ALL" | \grep "Lambda\d\+\|[lL]ambda\$\|-\$\$Lambda") || true
NAME=$(basename $1)
COUNT=0
if [ "$LAMBDA_METHODS" != "" ]; then
COUNT=$(echo "$LAMBDA_METHODS" | wc -l | xargs)
fi
D8_3X="FALSE"
if [[ $LAMBDA_METHODS =~ "SyntheticLambda" ]]; then
D8_3X="TRUE"
fi
echo -e "$NAME\t$COUNT\t$D8_3X"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment