Created
September 28, 2017 18:09
-
-
Save CalebFenton/b23550864120621a8f459caca90a1b9f to your computer and use it in GitHub Desktop.
Selecting Popular Android Hashes
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
#!/usr/bin/env python | |
import json | |
import operator | |
def get_top(hash_to_count, hash_to_name, top=1000): | |
sorted_counts = sorted(hash_to_count.items(), key=operator.itemgetter(1), reverse=True) | |
results = [] | |
for h, c in sorted_counts[0:top]: | |
results.append((h, c, hash_to_name[h])) | |
return results | |
def print_top(top): | |
i = 0 | |
for h, c, n in top: | |
i += 1 | |
print('|{}|{}|{}|{}|'.format(i, h, c, n)) | |
def select_class_hashes(output, threshold=75): | |
with open('class-hashes-full.json', 'rb') as f: | |
class_hashes = json.load(f) | |
cp = class_hashes['classHashToClassPath'] | |
cc = class_hashes['classHashToCount'] | |
# For generating markdown table: | |
#top = get_top(cc, cp, top=100) | |
#print_top(top) | |
selected_hashes = [] | |
for hash, count in cc.iteritems(): | |
if count >= threshold: | |
selected_hashes.append(hash) | |
selected_hashes = sorted(map(lambda e: int(e), selected_hashes)) | |
with open(output, 'wb') as f: | |
json.dump(selected_hashes, f) | |
def select_method_hashes(output, threshold=100): | |
with open('method-hashes-full.json', 'rb') as f: | |
method_hashes = json.load(f) | |
ms = method_hashes['methodHashToMethodSignature'] | |
mc = method_hashes['methodHashToCount'] | |
selected_hashes = [] | |
for hash, count in mc.iteritems(): | |
if count >= threshold: | |
selected_hashes.append(hash) | |
selected_hashes = sorted(map(lambda e: int(e), selected_hashes)) | |
with open(output, 'wb') as f: | |
json.dump(selected_hashes, f) | |
print("Selecting common class hashes") | |
select_class_hashes('common_class_hashes.json') | |
print("Selecting common method hashes") | |
select_method_hashes('common_method_hashes.json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment