Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
adesnos committed Sep 1, 2012
1 parent 656a252 commit 8b363ba
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 32 deletions.
66 changes: 34 additions & 32 deletions androguard/core/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,18 +1593,18 @@ def push_info(self, class_name, access, idx, method, idx_method) :

self.__methods[ method ][ class_name ].append( p )

def get_packages_by_method(self, method) :
try :
return self.__methods[ method ]
except KeyError :
def get_packages_by_method(self, method):
try:
return self.__methods[method]
except KeyError:
return {}

def get_package(self, name) :
return self.__packages[ name ]
def get_package(self, name):
return self.__packages[name]

def get_packages_by_bb(self, bb):
"""
@rtype : return a list of packaged used in a basic block
:rtype: return a list of packaged used in a basic block
"""
l = []
for i in self.__packages :
Expand All @@ -1620,28 +1620,31 @@ def get_packages(self):
for i in self.__packages:
yield self.__packages[i], i

def get_internal_packages_from_package(self, package) :
def get_internal_packages_from_package(self, package):
classes = self.__vm.get_classes_names()
l = []
for m, _ in self.get_packages() :
for m, _ in self.get_packages():
paths = m.get_methods()
for j in paths :
if j.get_method().get_class_name() == package and j.get_class_name() in classes :
l.append( j )
for j in paths:
src_class_name, _, _ = j.get_src(self.__vm.get_class_manager())
dst_class_name, _, _ = j.get_dst(self.__vm.get_class_manager())

if src_class_name == package and dst_class_name in classes:
l.append(j)
return l

def get_internal_packages(self) :
def get_internal_packages(self):
"""
@rtype : return a list of the internal packages called in the application
:rtype: return a list of the internal packages called in the application
"""
classes = self.__vm.get_classes_names()
l = []
for m, _ in self.get_packages() :
for m, _ in self.get_packages():
paths = m.get_methods()
for j in paths :
if j.get_access_flag() == TAINTED_PACKAGE_CALL :
dst_class_name, _, _ = j.get_dst( self.__vm.get_class_manager() )
if dst_class_name in classes and m.get_name() in classes :
for j in paths:
if j.get_access_flag() == TAINTED_PACKAGE_CALL:
dst_class_name, _, _ = j.get_dst(self.__vm.get_class_manager())
if dst_class_name in classes and m.get_name() in classes:
l.append(j)
return l

Expand Down Expand Up @@ -1680,24 +1683,23 @@ def get_external_packages(self):
l.append(j)
return l

def search_packages(self, package_name) :
def search_packages(self, package_name):
"""
@param package_name : a regexp for the name of the package
@rtype : a list of called packages' paths
:param package_name: a regexp for the name of the package
:rtype: a list of called packages' paths
"""
ex = re.compile( package_name )
ex = re.compile(package_name)

l = []
for m, _ in self.get_packages() :
if ex.match( m.get_name() ) != None :
l.extend( m.get_methods() )
for m, _ in self.get_packages():
if ex.search(m.get_name()) != None:
l.extend(m.get_methods())
return l

def search_unique_packages(self, package_name) :
"""
@param package_name : a regexp for the name of the package
:param package_name: a regexp for the name of the package
"""
ex = re.compile( package_name )

Expand Down Expand Up @@ -1726,7 +1728,7 @@ def search_methods(self, class_name, name, descriptor, re_expr=True) :
ex = re.compile( class_name )

for m, _ in self.get_packages() :
if ex.match( m.get_name() ) != None :
if ex.search( m.get_name() ) != None :
l.extend( m.search_method( name, descriptor ) )

return l
Expand All @@ -1741,7 +1743,7 @@ def search_objects(self, class_name) :
l = []

for m, _ in self.get_packages() :
if ex.match( m.get_name() ) != None :
if ex.search( m.get_name() ) != None :
l.extend( m.get_objects_paths() )

return l
Expand Down
18 changes: 18 additions & 0 deletions demos/apk_format_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python

import sys

PATH_INSTALL = "./"
sys.path.append( PATH_INSTALL )

from androguard.core.bytecodes import dvm, apk

TEST = "./apks/crash/mikecc/e0399fdd481992bc049b6e9d765da7f007f89875.apk"

a = apk.APK( TEST, zipmodule=2 )
a.show()

j = dvm.DalvikVMFormat( a.get_dex() )

# SHOW CLASS (verbose)
#j.show()
1 change: 1 addition & 0 deletions demos/dalvikvm_format_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def check(self, b1, b2, off) :


TEST = "examples/android/TestsAndroguard/bin/TestsAndroguard.apk"
#TEST = "apks/malwares/smszombie/40F3F16742CD8AC8598BF859A23AC290.apk"
FILENAME = "./toto.apk"

androconf.set_debug()
Expand Down

0 comments on commit 8b363ba

Please sign in to comment.