From f9ca506e11591ca903dfce58720d0b9831f48377 Mon Sep 17 00:00:00 2001 From: Sebastian Bachmann Date: Sat, 21 Apr 2018 18:51:54 +0200 Subject: [PATCH] rename tool --- androcfg.py => androcg.py | 38 ++++++++++++------------ docs/tools/{androcfg.rst => androcg.rst} | 8 ++--- setup.py | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) rename androcfg.py => androcg.py (80%) rename docs/tools/{androcfg.rst => androcg.rst} (81%) diff --git a/androcfg.py b/androcg.py similarity index 80% rename from androcfg.py rename to androcg.py index 0dbef463..897c94ff 100755 --- a/androcfg.py +++ b/androcg.py @@ -27,9 +27,9 @@ def generate_graph(dx, classname=".*", methodname=".*", descriptor=".*", :rtype: DiGraph """ - CFG = nx.DiGraph() + CG = nx.DiGraph() - # Note: If you create the CFG from many classes at the same time, the drawing + # Note: If you create the CG from many classes at the same time, the drawing # will be a total mess... for m in dx.find_methods(classname=classname, methodname=methodname, descriptor=descriptor, accessflags=accessflags): @@ -44,7 +44,7 @@ def generate_graph(dx, classname=".*", methodname=".*", descriptor=".*", else: is_this_external = False - CFG.add_node(orig_method, external=is_this_external) + CG.add_node(orig_method, external=is_this_external) for other_class, callee, offset in m.get_xref_to(): if isinstance(callee, ExternalMethod): @@ -52,38 +52,38 @@ def generate_graph(dx, classname=".*", methodname=".*", descriptor=".*", else: is_external = False - if callee not in CFG.node: - CFG.add_node(callee, external=is_external) + if callee not in CG.node: + CG.add_node(callee, external=is_external) # As this is a DiGraph and we are not interested in duplicate edges, # check if the edge is already in the edge set. # If you need all calls, you probably want to check out MultiDiGraph - if not CFG.has_edge(orig_method, callee): - CFG.add_edge(orig_method, callee) + if not CG.has_edge(orig_method, callee): + CG.add_edge(orig_method, callee) - return CFG + return CG -def plot(CFG): +def plot(CG): """ Plot the call graph using matplotlib For larger graphs, this should not be used! """ - pos = nx.spring_layout(CFG) + pos = nx.spring_layout(CG) internal = [] external = [] - for n in CFG.node: + for n in CG.node: if isinstance(n, ExternalMethod): external.append(n) else: internal.append(n) - nx.draw_networkx_nodes(CFG, pos=pos, node_color='r', nodelist=internal) - nx.draw_networkx_nodes(CFG, pos=pos, node_color='b', nodelist=external) - nx.draw_networkx_edges(CFG, pos, arrow=True) - nx.draw_networkx_labels(CFG, pos=pos, labels={x: "{} {}".format(x.get_class_name(), x.get_name()) for x in CFG.edge}) + nx.draw_networkx_nodes(CG, pos=pos, node_color='r', nodelist=internal) + nx.draw_networkx_nodes(CG, pos=pos, node_color='b', nodelist=external) + nx.draw_networkx_edges(CG, pos, arrow=True) + nx.draw_networkx_labels(CG, pos=pos, labels={x: "{} {}".format(x.get_class_name(), x.get_name()) for x in CG.edge}) plt.draw() plt.show() @@ -95,7 +95,7 @@ def _write_gml(G, path): def main(): - parser = ArgumentParser(description="Create a Call Graph based on the data" + parser = ArgumentParser(description="Create a call graph based on the data" "of Analysis and export it into a graph format.") parser.add_argument("APK", nargs=1, help="The APK to analyze") @@ -117,7 +117,7 @@ def main(): a, d, dx = AnalyzeAPK(args.APK[0]) - CFG = generate_graph(dx, args.classname, args.methodname, args.descriptor, args.accessflag) + CG = generate_graph(dx, args.classname, args.methodname, args.descriptor, args.accessflag) write_methods = dict(gml=_write_gml, gexf=nx.write_gexf, @@ -128,7 +128,7 @@ def main(): ) if args.show: - plot(CFG) + plot(CG) else: writer = args.output.rsplit(".", 1)[1] if writer in ["bz2", "gz"]: @@ -137,7 +137,7 @@ def main(): print("Could not find a method to export files to {}!".format(writer)) sys.exit(1) - write_methods[writer](CFG, args.output) + write_methods[writer](CG, args.output) if __name__ == "__main__": diff --git a/docs/tools/androcfg.rst b/docs/tools/androcg.rst similarity index 81% rename from docs/tools/androcfg.rst rename to docs/tools/androcg.rst index 50881601..6adf7517 100644 --- a/docs/tools/androcfg.rst +++ b/docs/tools/androcg.rst @@ -1,9 +1,9 @@ -androcfg - Create Call Graph from APK -===================================== +androcg - Create Call Graph from APK +==================================== -.. program-output:: python ../androcfg.py -h +.. program-output:: python ../androcg.py -h -androcfg can create files that can be read using graph visualization software, for example gephi_. +androcg can create files that can be read using graph visualization software, for example gephi_. The call graph is constructed from the :class:`~androguard.analysis.analysis.Analysis` object and then converted into a networkx `DiGraph`. diff --git a/setup.py b/setup.py index c45367b1..a6b23c7e 100644 --- a/setup.py +++ b/setup.py @@ -87,7 +87,7 @@ setup( 'androlyze.py', 'androdd.py', 'androgui.py', - 'androcfg.py', + 'androcg.py', ], install_requires=install_requires, extras_require={