Last active
May 12, 2016 09:41
-
-
Save cedricbonhomme/8aaac623480912661ff29e4395bb5414 to your computer and use it in GitHub Desktop.
Generates a GEXF file for Gephi based on links between intents of a set of Android applications.
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 | |
# -*- coding: utf-8 -*- | |
import sys | |
import networkx as nx | |
import primo | |
from primo.linking.find_links import FindLinks | |
G = nx.DiGraph() | |
if __name__ == "__main__": | |
# Point of entry in execution mode | |
files_path = sys.argv[1:] | |
intent_links, components, intent_filters, applications, intents = \ | |
FindLinks(protobufs=files_path, skip_empty=True) | |
for component_intent, targets_and_attributes in intent_links.items(): | |
if not component_intent.component.application.SendsExternalIntent(): | |
# only communications between applications | |
continue | |
G.add_node(component_intent.component.application.name) | |
G.node[component_intent.component.application.name]['used_permissions'] = ", ".join(component_intent.component.application.used_permissions) | |
for target, probability in zip(targets_and_attributes[0], targets_and_attributes[1]): | |
if probability != 0: | |
if type(target) == primo.linking.components.Component: | |
target_name = target.application.name | |
elif type(target) == primo.linking.intent_filters.IntentFilter: | |
target_name = target.application_id | |
G.add_edge(component_intent.component.application.name, | |
target_name, | |
weight=probability) | |
G.node[target_name]['used_permissions'] = ", ".join(component_intent.component.application.used_permissions) | |
G.node[component_intent.component.application.name]['viz'] = {'color': {'r': 0, 'g': 0, 'b': 255, 'a': 0}} | |
G.node[target_name]['viz'] = {'color': {'r': 255, 'g': 0, 'b': 0, 'a': 0}} | |
G.edge[component_intent.component.application.name][target_name]['weight'] = probability | |
nx.write_gexf(G, "links.gexf", version="1.2draft") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment