本文整理汇总了Python中androguard.core.bytecodes.apk.APK属性的典型用法代码示例。如果您正苦于以下问题:Python apk.APK属性的具体用法?Python apk.APK怎么用?Python apk.APK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类androguard.core.bytecodes.apk
的用法示例。
在下文中一共展示了apk.APK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sign_apk
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def sign_apk(filename, keystore, storepass):
"""
Use jarsigner to sign an APK file.
:param filename: APK file on disk to sign (path)
:param keystore: path to keystore
:param storepass: your keystorage passphrase
"""
from subprocess import Popen, PIPE, STDOUT
# TODO use apksigner instead of jarsigner
cmd = Popen([androconf.CONF["BIN_JARSIGNER"], "-sigalg", "MD5withRSA",
"-digestalg", "SHA1", "-storepass", storepass, "-keystore",
keystore, filename, "alias_name"],
stdout=PIPE,
stderr=STDOUT)
stdout, stderr = cmd.communicate()
示例2: addAPK
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def addAPK(self, filename, data):
"""
Add an APK file to the Session and run analysis on it.
:param filename: (file)name of APK file
:param data: binary data of the APK file
:return: a tuple of SHA256 Checksum and APK Object
"""
digest = hashlib.sha256(data).hexdigest()
log.debug("add APK:%s" % digest)
apk = APK(data, True)
self.analyzed_apk[digest] = [apk]
self.analyzed_files[filename].append(digest)
self.analyzed_digest[digest] = filename
dx = Analysis()
self.analyzed_vms[digest] = dx
for dex in apk.get_all_dex():
# we throw away the output... FIXME?
self.addDEX(filename, dex, dx)
log.debug("added APK:%s" % digest)
return digest, apk
示例3: androaxml_main
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def androaxml_main(inp, outp=None, resource=None):
ret_type = androconf.is_android(inp)
if ret_type == "APK":
a = apk.APK(inp)
if resource:
if resource not in a.files:
print("The APK does not contain a file called '{}'".format(resource), file=sys.stderr)
sys.exit(1)
axml = AXMLPrinter(a.get_file(resource)).get_xml_obj()
else:
axml = a.get_android_manifest_xml()
elif ".xml" in inp:
axml = AXMLPrinter(read(inp)).get_xml_obj()
else:
print("Unknown file type")
sys.exit(1)
buff = etree.tostring(axml, pretty_print=True, encoding="utf-8")
if outp:
with open(outp, "wb") as fd:
fd.write(buff)
else:
sys.stdout.write(highlight(buff.decode("UTF-8"), get_lexer_by_name("xml"), TerminalFormatter()))
示例4: __init__
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def __init__(self, name):
"""
:param name: filename to load
"""
self.vma = analysis.Analysis()
# Proper detection which supports multidex inside APK
ftype = androconf.is_android(name)
if ftype == 'APK':
for d in apk.APK(name).get_all_dex():
self.vma.add(dvm.DalvikVMFormat(d))
elif ftype == 'DEX':
self.vma.add(dvm.DalvikVMFormat(read(name)))
elif ftype == 'DEY':
self.vma.add(dvm.DalvikOdexVMFormat(read(name)))
else:
raise ValueError("Format not recognised for filename '%s'" % name)
self.classes = dict((dvclass.orig_class.get_name(), dvclass.orig_class) for dvclass in self.vma.get_classes())
# TODO why not?
# util.merge_inner(self.classes)
示例5: __init__
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def __init__(self,apkFile):
self.sha256 = self.sha256CheckSum(apkFile)
print "[-]Parsing APK"
self.a = apk.APK(apkFile)
print "[-]Baksmaling DEX files"
self.bakmali(apkFile)
self.manifest = self.a.get_android_manifest_axml().get_xml_obj()
self.application = self.manifest.findall("application")[0]
print "[+]Gathering Information"
self.extractActivitiesWithExcludeFromRecents()
self.extractActivitiesWithoutSecureFlag()
print " [-]Package Properties"
self.extractPackageProperties()
print " [-]Exported Components"
self.extractExportedComponents()
print " [-]Permissions"
self.extractPermissions()
print " [-]Files"
self.extractFiles()
#Return the Android Code Name for the particular Api Level.
示例6: _analyze
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def _analyze(self):
for i in self.__files:
ret_type = androconf.is_android( i )
if ret_type == "APK":
x = apk.APK( i )
bc = dvm.DalvikVMFormat( x.get_dex() )
elif ret_type == "DEX":
bc = dvm.DalvikVMFormat( read(i) )
elif ret_type == "DEY":
bc = dvm.DalvikOdexVMFormat( read(i) )
elif ret_type == "ELF":
from androguard.core.binaries import elf
bc = elf.ELF( read(i) )
else:
raise( "Unknown format" )
self.__bc.append( (i, BC( bc )) )
示例7: filter_file
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def filter_file(self, log, fileraw):
"""
This method is called in order to filer a specific app
:param log: an object which corresponds to a unique app
:param fileraw: the raw app (a string)
:rtype: a set with 2 elements, the return value (boolean) if it is necessary to
continue the analysis and the file type
"""
file_type = androconf.is_android_raw(fileraw)
if file_type == "APK" or file_type == "DEX" or file_type == "DEY" or file_type == "AXML" or file_type == "ARSC":
if file_type == "APK":
if androconf.is_valid_android_raw(fileraw):
return (True, "APK")
else:
return (True, file_type)
return (False, None)
示例8: __init__
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def __init__(self, app_path, output_dir=None):
"""
create an App instance
:param app_path: local file path of app
:return:
"""
assert app_path is not None
self.logger = logging.getLogger(self.__class__.__name__)
self.app_path = app_path
self.output_dir = output_dir
if output_dir is not None:
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
from androguard.core.bytecodes.apk import APK
self.apk = APK(self.app_path)
self.package_name = self.apk.get_package()
self.main_activity = self.apk.get_main_activity()
self.permissions = self.apk.get_permissions()
self.activities = self.apk.get_activities()
self.possible_broadcasts = self.get_possible_broadcasts()
self.dumpsys_main_activity = None
self.hashes = self.get_hashes()
示例9: get_hashes
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def get_hashes(self, block_size=2 ** 8):
"""
Calculate MD5,SHA-1, SHA-256
hashes of APK input file
@param block_size:
"""
md5 = hashlib.md5()
sha1 = hashlib.sha1()
sha256 = hashlib.sha256()
f = open(self.app_path, 'rb')
while True:
data = f.read(block_size)
if not data:
break
md5.update(data)
sha1.update(data)
sha256.update(data)
return [md5.hexdigest(), sha1.hexdigest(), sha256.hexdigest()]
示例10: get_app_name
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def get_app_name(app_path, app_dir, tools_dir, is_apk):
"""Get app name."""
if is_apk:
a = apk.APK(app_path)
real_name = a.get_app_name()
return real_name
else:
strings_path = os.path.join(app_dir,
'app/src/main/res/values/')
eclipse_path = os.path.join(app_dir,
'res/values/')
if os.path.exists(strings_path):
strings_dir = strings_path
elif os.path.exists(eclipse_path):
strings_dir = eclipse_path
if not os.path.exists(strings_dir):
logger.warning('Cannot find values folder.')
return ''
return get_app_name_from_values_folder(strings_dir)
示例11: check_apk
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def check_apk(self, apk):
"""
Check if a signature matches the application
@param apk : an L{APK} object
@rtype : None if no signatures match, otherwise the name of the signature
"""
if self.debug:
print "loading apk..",
sys.stdout.flush()
classes_dex = apk.get_dex()
ret, l = self.p._check_dalvik( classes_dex )
if ret == None:
#ret, l1 = self.p._check_bin( apk )
l1 = []
l.extend( l1 )
return ret, l
示例12: check_one_directory
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def check_one_directory(directory):
for root, dirs, files in os.walk( directory, followlinks=True ):
if files != []:
for f in files:
real_filename = root
if real_filename[-1] != "/":
real_filename += "/"
real_filename += f
print "filename: %s ..." % real_filename
ret_type = androconf.is_android( real_filename )
if ret_type == "APK":
a = apk.APK( real_filename )
d1 = dvm.DalvikVMFormat( a.get_dex() )
elif ret_type == "DEX":
d1 = dvm.DalvikVMFormat( read(real_filename) )
dx1 = analysis.VMAnalysis( d1 )
check_one_file( d1, dx1 )
示例13: main
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def main(options, arguments):
if options.input != None and options.database != None:
ret_type = androconf.is_android( options.input )
if ret_type == "APK":
a = apk.APK( options.input )
d1 = dvm.DalvikVMFormat( a.get_dex() )
elif ret_type == "DEX":
d1 = dvm.DalvikVMFormat( read(options.input) )
dx1 = analysis.VMAnalysis( d1 )
check_one_file(d1, dx1)
elif options.directory != None and options.database != None:
check_one_directory( options.directory )
elif options.database != None and options.listdatabase != None:
db = DBFormat( options.database )
db.show()
elif options.version != None:
print "Androappindb version %s" % androconf.ANDROGUARD_VERSION
示例14: main
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def main(options, arguments):
if options.input != None:
buff = ""
ret_type = androconf.is_android(options.input)
if ret_type == "APK":
a = apk.APK(options.input)
buff = a.get_android_manifest_xml().toprettyxml(encoding="utf-8")
elif ".xml" in options.input:
ap = apk.AXMLPrinter(read(options.input))
buff = minidom.parseString(ap.get_buff()).toprettyxml(
encoding="utf-8")
else:
print "Unknown file type"
return
if options.output != None:
fd = codecs.open(options.output, "w", "utf-8")
fd.write(buff)
fd.close()
else:
print buff
elif options.version != None:
print "Androaxml version %s" % androconf.ANDROGUARD_VERSION
示例15: filter_file
# 需要导入模块: from androguard.core.bytecodes import apk [as 别名]
# 或者: from androguard.core.bytecodes.apk import APK [as 别名]
def filter_file(self, log, fileraw):
"""
This method is called in order to filer a specific app
:param log: an object which corresponds to a unique app
:param fileraw: the raw app (a string)
:rtype: a set with 2 elements, the return value (boolean) if it is necessary to
continue the analysis and the file type
"""
file_type = androconf.is_android_raw(fileraw)
if file_type == "APK" or file_type == "DEX" or file_type == "DEY" or file_type == "AXML" or file_type == "ARSC":
if file_type == "APK":
if androconf.is_valid_android_raw(fileraw):
return (True, "APK")
else:
return (True, file_type)
return (False, None)