Skip to content

Commit

Permalink
Added template for PDG module
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Gascon committed Jan 14, 2015
1 parent b19066e commit e797b15
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
8 changes: 4 additions & 4 deletions adagio.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def exit():
generator = FCGGenerator(args.dir, args.out)

elif args.pdgraphs:
# args.out = os.path.realpath(args.out)
# generator = PDGGenerator(args.dir, args.out)
print "Not implemented yet!"
sys.exit()
args.out = os.path.realpath(args.out)
generator = PDGGenerator(args.dir, args.out)
# print "Not implemented yet!"
# sys.exit()

if generator:
print_logo()
Expand Down
4 changes: 2 additions & 2 deletions adagio/core/FCG.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def build_fcg(self, filename):
try:
a, d, dx = AnalyzeAPK(filename)
except zipfile.BadZipfile:
#if file is not an APK, may be a dex object
# if file is not an APK, may be a dex object
d, dx = AnalyzeDex(filename)

for method in d.get_methods():
Expand All @@ -108,7 +108,7 @@ def build_fcg(self, filename):
remote_method = cob[0]
children.append(self.get_node_name(remote_method))

#find all instructions in method and encode using coloring
# find all instructions in method and encode using coloring
instructions = []
for i in method.get_instructions():
instructions.append(i.get_name())
Expand Down
40 changes: 34 additions & 6 deletions adagio/core/PDG.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def process(self):
sys.setrecursionlimit(100000)
files = []

# check if fcg doesnt exist yet and mark the file to be processed
# check if pdg doesnt exist yet and mark the file to be processed
for dirName, subdirList, fileList in os.walk(self.read_dir):
for f in fileList:
files.append(os.path.join(dirName, f))
Expand All @@ -44,8 +44,8 @@ def process(self):
# loop through .apk files and save them in .pdg.pz format
for f in files:

# f = os.path.join(self.read_dir, fn)
print "[] Loading {0}".format(f)
f = os.path.join(self.read_dir, fn)
print '[] Loading {0}'.format(f)
try:
g = self.build_pdg(f)

Expand Down Expand Up @@ -75,11 +75,39 @@ def process(self):
print "Done."

def build_pdg(self, filename):
#TODO
return
pdg = nx.DiGraph()
print "Loading file {0}...".format(filename)
try:
a, d, dx = AnalyzeAPK(filename)
except zipfile.BadZipfile:
#if file is not an APK, may be a dex object
d, dx = AnalyzeDex(filename)

methods = d.get_methods()

# set up progress bar
widgets = ['Building PDG: ',
Percentage(), ' ',
Bar(marker='#', left='[', right=']'),
' ', ETA(), ' ']
pbar = ProgressBar(widgets=widgets, maxval=len(methods))
pbar.start()
progress = 0

for method in methods:
for bb in dx.get_method(method).basic_blocks.get():
children = []
label = self.get_bb_label(bb)
children = self.get_children(bb, dx)
pdg.add_node(label)
pdg.add_edges_from([(label, child) for child in children])
progress += 1
pbar.update(progress)
pbar.finish()
return pdg

def build_icfg_nx(self, filename):
""" Using NX and Androguard, build an interprocedural control flow
""" Using NX and Androguard, build an interprocedural control flow (ICFG)
graph NX object so that node names are basic blocks names: (class name,
method name, descriptor, bb)
"""
Expand Down

0 comments on commit e797b15

Please sign in to comment.