Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Gascon committed Jan 27, 2015
1 parent b7e0b7b commit 100bf94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion adagio.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def exit():
args.out = os.path.realpath(args.out)
mode ='PDG'

if type:
if mode:
print_logo()
process_dir(args.dir, args.out, mode)

Expand Down
22 changes: 9 additions & 13 deletions adagio/core/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

""" A module to build NX graph objects from APKs. """

import sys
import os
import zipfile
import networkx as nx
import numpy as np
Expand Down Expand Up @@ -35,7 +33,6 @@ def build_fcg(self):
# nx graph for FCG extracted from APK: nodes = method_name,
# labels = encoded instructions
fcg = nx.DiGraph()
print "Loading file {0}...".format(self.filename)
try:
self.a = APK(self.filename)
self.d = DalvikVMFormat(self.a.get_dex())
Expand Down Expand Up @@ -97,12 +94,11 @@ class PDG():

def __init__(self, filename):
self.filename = filename
self.icfg = self.build_icfg()
self.g = self.build_icfg()
self.nodes = {}

def build_icfg(self):
icfg = nx.DiGraph()
print "Loading file {0}...".format(self.filename)
try:
self.a = APK(self.filename)
self.d = DalvikVMFormat(self.a.get_dex())
Expand Down Expand Up @@ -216,15 +212,15 @@ def process_dir(read_dir, out_dir, mode='FCG'):
print '[] Loading {0}'.format(f)
try:
if mode is 'FCG':
g = FCG(f)
graph = FCG(f)
elif mode is 'PDG':
g = PDG(f)
graph= PDG(f)

# if an exception happens, save the .apk in the corresponding dir
except Exception as e:
err = e.__class__.__name__
err_dir = err + "/"
d = os.path.join(self.read_dir, err_dir)
d = os.path.join(read_dir, err_dir)
if not os.path.exists(d):
os.makedirs(d)
cmd = "cp {} {}".format(f, d)
Expand All @@ -233,12 +229,12 @@ def process_dir(read_dir, out_dir, mode='FCG'):
continue

h = get_sha256(f)
if self.out_dir:
out = self.out_dir
if out_dir:
out = out_dir
else:
out = self.read_dir
fnx = os.path.join(out, "{}.pdg.pz".format(h))
pz.save(g, fnx)
out = read_dir
fnx = os.path.join(out, "{}.pz".format(h))
pz.save(graph.g, fnx)
print "[*] Saved {}\n".format(fnx)
progress += 1
pbar.update(progress)
Expand Down

0 comments on commit 100bf94

Please sign in to comment.