INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Updates the DU chain of the instruction located at loc such that there is
no more reference to it so that we can remove it.
When an instruction is found to be dead (i.e it has no side effect, and the
register defined is not used) we have to update the DU chain of all the
variables that may me used by th... | def update_chain(graph, loc, du, ud):
"""
Updates the DU chain of the instruction located at loc such that there is
no more reference to it so that we can remove it.
When an instruction is found to be dead (i.e it has no side effect, and the
register defined is not used) we have to update the DU cha... |
Check that the path from loc1 to loc2 is clear.
We have to check that there is no side effect between the two location
points. We also have to check that the variable `reg` is not redefined
along one of the possible pathes from loc1 to loc2. | def clear_path(graph, reg, loc1, loc2):
"""
Check that the path from loc1 to loc2 is clear.
We have to check that there is no side effect between the two location
points. We also have to check that the variable `reg` is not redefined
along one of the possible pathes from loc1 to loc2.
"""
lo... |
Run a dead code elimination pass.
Instructions are checked to be dead. If it is the case, we remove them and
we update the DU & UD chains of its variables to check for further dead
instructions. | def dead_code_elimination(graph, du, ud):
"""
Run a dead code elimination pass.
Instructions are checked to be dead. If it is the case, we remove them and
we update the DU & UD chains of its variables to check for further dead
instructions.
"""
for node in graph.rpo:
for i, ins in no... |
Propagate the temporary registers between instructions and remove them if
necessary.
We process the nodes of the graph in reverse post order. For each
instruction in the node, we look at the variables that it uses. For each of
these variables we look where it is defined and if we can replace it with
... | def register_propagation(graph, du, ud):
"""
Propagate the temporary registers between instructions and remove them if
necessary.
We process the nodes of the graph in reverse post order. For each
instruction in the node, we look at the variables that it uses. For each of
these variables we look ... |
Builds the Def-Use and Use-Def (DU/UD) chains of the variables of the
method. | def build_def_use(graph, lparams):
"""
Builds the Def-Use and Use-Def (DU/UD) chains of the variables of the
method.
"""
analysis = reach_def_analysis(graph, lparams)
UD = defaultdict(list)
for node in graph.rpo:
for i, ins in node.get_loc_with_ins():
for var in ins.get_... |
Compute the intervals of the graph
Returns
interval_graph: a graph of the intervals of G
interv_heads: a dict of (header node, interval) | def intervals(graph):
"""
Compute the intervals of the graph
Returns
interval_graph: a graph of the intervals of G
interv_heads: a dict of (header node, interval)
"""
interval_graph = Graph() # graph of intervals
heads = [graph.entry] # list of header nodes
interv_heads = {} # int... |
Compute the derived sequence of the graph G
The intervals of G are collapsed into nodes, intervals of these nodes are
built, and the process is repeated iteratively until we obtain a single
node (if the graph is not irreducible) | def derived_sequence(graph):
"""
Compute the derived sequence of the graph G
The intervals of G are collapsed into nodes, intervals of these nodes are
built, and the process is repeated iteratively until we obtain a single
node (if the graph is not irreducible)
"""
deriv_seq = [graph]
de... |
Return the Java source code of a whole class
:param _class: `ClassDefItem` object, to get the source from
:return: | def get_source_class(self, _class):
"""
Return the Java source code of a whole class
:param _class: `ClassDefItem` object, to get the source from
:return:
"""
if not _class.get_name() in self.classes:
return ""
return self.classes[_class.get_name()] |
Tests if any class inside a DalvikVMObject
uses ASCII Obfuscation (e.g. UTF-8 Chars in Classnames)
:param vm: `DalvikVMObject`
:return: True if ascii obfuscation otherwise False | def is_ascii_obfuscation(vm):
"""
Tests if any class inside a DalvikVMObject
uses ASCII Obfuscation (e.g. UTF-8 Chars in Classnames)
:param vm: `DalvikVMObject`
:return: True if ascii obfuscation otherwise False
"""
for classe in vm.get_classes():
if is_ascii_problem(classe.get_name... |
Prints the content of this method to stdout.
This will print the method signature and the decompiled code. | def show(self):
"""
Prints the content of this method to stdout.
This will print the method signature and the decompiled code.
"""
args, ret = self.method.get_descriptor()[1:].split(")")
if self.code:
# We patch the descriptor here and add the registers, if c... |
Returns True if the method seems to be an Android API method.
This method might be not very precise unless an list of known API methods
is given.
:return: boolean | def is_android_api(self):
"""
Returns True if the method seems to be an Android API method.
This method might be not very precise unless an list of known API methods
is given.
:return: boolean
"""
if not self.is_external():
# Method must be external ... |
.. deprecated:: 3.1.0
Use :meth:`get_method` instead. | def GetMethod(self, name, descriptor):
"""
.. deprecated:: 3.1.0
Use :meth:`get_method` instead.
"""
warnings.warn("deprecated, use get_method instead. This function might be removed in a later release!", DeprecationWarning)
return self.get_method(name, descriptor) |
Get the method by name and descriptor,
or create a new one if the requested method does not exists.
:param name: method name
:param descriptor: method descriptor, for example `'(I)V'`
:return: :class:`ExternalMethod` | def get_method(self, name, descriptor):
"""
Get the method by name and descriptor,
or create a new one if the requested method does not exists.
:param name: method name
:param descriptor: method descriptor, for example `'(I)V'`
:return: :class:`ExternalMethod`
""... |
Tries to guess if the current class is an Android API class.
This might be not very precise unless an apilist is given, with classes that
are in fact known APIs.
Such a list might be generated by using the android.jar files.
:return: boolean | def is_android_api(self):
"""
Tries to guess if the current class is an Android API class.
This might be not very precise unless an apilist is given, with classes that
are in fact known APIs.
Such a list might be generated by using the android.jar files.
:return: boolea... |
Search for the given method name and descriptor
and return a fake (ExternalMethod) if required.
:param name: name of the method
:param descriptor: descriptor of the method, for example `'(I I I)V'`
:return: :class:`ExternalMethod` | def get_fake_method(self, name, descriptor):
"""
Search for the given method name and descriptor
and return a fake (ExternalMethod) if required.
:param name: name of the method
:param descriptor: descriptor of the method, for example `'(I I I)V'`
:return: :class:`Externa... |
Add a Field Read to this class
:param method:
:param classobj:
:param field:
:return: | def AddFXrefRead(self, method, classobj, field):
"""
Add a Field Read to this class
:param method:
:param classobj:
:param field:
:return:
"""
if field not in self._fields:
self._fields[field] = FieldClassAnalysis(field)
self._fields[f... |
Add a Field Write to this class
:param method:
:param classobj:
:param field:
:return: | def AddFXrefWrite(self, method, classobj, field):
"""
Add a Field Write to this class
:param method:
:param classobj:
:param field:
:return:
"""
if field not in self._fields:
self._fields[field] = FieldClassAnalysis(field)
self._fields... |
Creates a crossreference to another class.
XrefTo means, that the current class calls another class.
The current class should also be contained in the another class' XrefFrom list.
:param REF_TYPE ref_kind: type of call
:param classobj: :class:`ClassAnalysis` object to link
:par... | def AddXrefTo(self, ref_kind, classobj, methodobj, offset):
"""
Creates a crossreference to another class.
XrefTo means, that the current class calls another class.
The current class should also be contained in the another class' XrefFrom list.
:param REF_TYPE ref_kind: type of ... |
Creates a crossreference from this class.
XrefFrom means, that the current class is called by another class.
:param REF_TYPE ref_kind: type of call
:param classobj: :class:`ClassAnalysis` object to link
:param methodobj:
:param offset: Offset in the methods bytecode, where the c... | def AddXrefFrom(self, ref_kind, classobj, methodobj, offset):
"""
Creates a crossreference from this class.
XrefFrom means, that the current class is called by another class.
:param REF_TYPE ref_kind: type of call
:param classobj: :class:`ClassAnalysis` object to link
:p... |
Add a DalvikVMFormat to this Analysis
:param vm: :class:`dvm.DalvikVMFormat` to add to this Analysis | def add(self, vm):
"""
Add a DalvikVMFormat to this Analysis
:param vm: :class:`dvm.DalvikVMFormat` to add to this Analysis
"""
self.vms.append(vm)
for current_class in vm.get_classes():
self.classes[current_class.get_name()] = ClassAnalysis(current_class)
... |
Create Class, Method, String and Field crossreferences
for all classes in the Analysis.
If you are using multiple DEX files, this function must
be called when all DEX files are added.
If you call the function after every DEX file, the
crossreferences might be wrong! | def create_xref(self):
"""
Create Class, Method, String and Field crossreferences
for all classes in the Analysis.
If you are using multiple DEX files, this function must
be called when all DEX files are added.
If you call the function after every DEX file, the
c... |
Create the xref for `current_class`
There are four steps involved in getting the xrefs:
* Xrefs for classes
* for method calls
* for string usage
* for field manipulation
All these information are stored in the *Analysis Objects.
Note that thi... | def _create_xref(self, current_class):
"""
Create the xref for `current_class`
There are four steps involved in getting the xrefs:
* Xrefs for classes
* for method calls
* for string usage
* for field manipulation
All these information ... |
Search for a :class:`EncodedMethod` in all classes in this analysis
:param class_name: name of the class, for example 'Ljava/lang/Object;'
:param method_name: name of the method, for example 'onCreate'
:param method_descriptor: descriptor, for example '(I I Ljava/lang/String)V
:return: ... | def get_method_by_name(self, class_name, method_name, method_descriptor):
"""
Search for a :class:`EncodedMethod` in all classes in this analysis
:param class_name: name of the class, for example 'Ljava/lang/Object;'
:param method_name: name of the method, for example 'onCreate'
... |
Returns the crossreferencing object for a given Method.
Beware: the similar named function :meth:`~get_method()` will return
a :class:`MethodAnalysis` object, while this function returns a :class:`MethodClassAnalysis` object!
This Method will only work after a run of :meth:`~create_xref()`
... | def get_method_analysis(self, method):
"""
Returns the crossreferencing object for a given Method.
Beware: the similar named function :meth:`~get_method()` will return
a :class:`MethodAnalysis` object, while this function returns a :class:`MethodClassAnalysis` object!
This Meth... |
Returns the crossreferencing object for a given method.
This function is similar to :meth:`~get_method_analysis`, with the difference
that you can look up the Method by name
:param class_name: name of the class, for example `'Ljava/lang/Object;'`
:param method_name: name of the method,... | def get_method_analysis_by_name(self, class_name, method_name, method_descriptor):
"""
Returns the crossreferencing object for a given method.
This function is similar to :meth:`~get_method_analysis`, with the difference
that you can look up the Method by name
:param class_name... |
Get the FieldAnalysis for a given fieldname
:param field: TODO
:return: :class:`FieldClassAnalysis` | def get_field_analysis(self, field):
"""
Get the FieldAnalysis for a given fieldname
:param field: TODO
:return: :class:`FieldClassAnalysis`
"""
class_analysis = self.get_class_analysis(field.get_class_name())
if class_analysis:
return class_analysis.... |
Returns a list of `MethodClassAnalysis` objects | def get_methods(self):
"""
Returns a list of `MethodClassAnalysis` objects
"""
for c in self.classes.values():
for m in c.get_methods():
yield m |
Returns a list of `FieldClassAnalysis` objects | def get_fields(self):
"""
Returns a list of `FieldClassAnalysis` objects
"""
for c in self.classes.values():
for f in c.get_fields():
yield f |
Find classes by name, using regular expression
This method will return all ClassAnalysis Object that match the name of
the class.
:param name: regular expression for class name (default ".*")
:param no_external: Remove external classes from the output (default False)
:rtype: gen... | def find_classes(self, name=".*", no_external=False):
"""
Find classes by name, using regular expression
This method will return all ClassAnalysis Object that match the name of
the class.
:param name: regular expression for class name (default ".*")
:param no_external: R... |
Find a method by name using regular expression.
This method will return all MethodClassAnalysis objects, which match the
classname, methodname, descriptor and accessflags of the method.
:param classname: regular expression for the classname
:param methodname: regular expression for the ... | def find_methods(self, classname=".*", methodname=".*", descriptor=".*",
accessflags=".*", no_external=False):
"""
Find a method by name using regular expression.
This method will return all MethodClassAnalysis objects, which match the
classname, methodname, descriptor and ac... |
Find strings by regex
:param string: regular expression for the string to search for
:rtype: generator of `StringAnalysis` | def find_strings(self, string=".*"):
"""
Find strings by regex
:param string: regular expression for the string to search for
:rtype: generator of `StringAnalysis`
"""
for s, sa in self.strings.items():
if re.match(string, s):
yield sa |
Generate a directed graph based on the methods found by the filters applied.
The filters are the same as in
:meth:`~androguard.core.analaysis.analaysis.Analysis.find_methods`
A networkx.DiGraph is returned, containing all edges only once!
that means, if a method calls some method twice ... | def get_call_graph(self, classname=".*", methodname=".*", descriptor=".*",
accessflags=".*", no_isolated=False, entry_points=[]):
"""
Generate a directed graph based on the methods found by the filters applied.
The filters are the same as in
:meth:`~androguard.core... |
find fields by regex
:param classname: regular expression of the classname
:param fieldname: regular expression of the fieldname
:param fieldtype: regular expression of the fieldtype
:param accessflags: regular expression of the access flags
:rtype: generator of `FieldClassAnaly... | def find_fields(self, classname=".*", fieldname=".*", fieldtype=".*", accessflags=".*"):
"""
find fields by regex
:param classname: regular expression of the classname
:param fieldname: regular expression of the fieldname
:param fieldtype: regular expression of the fieldtype
... |
.. warning:: this feature is experimental and is currently not enabled by default! Use with caution!
Creates attributes for all classes, methods and fields on the Analysis object itself.
This makes it easier to work with Analysis module in an iPython shell.
Classes can be search by typing :cod... | def create_ipython_exports(self):
"""
.. warning:: this feature is experimental and is currently not enabled by default! Use with caution!
Creates attributes for all classes, methods and fields on the Analysis object itself.
This makes it easier to work with Analysis module in an iPytho... |
Returns the permissions and the API method based on the API level specified.
This can be used to find usage of API methods which require a permission.
Should be used in combination with an :class:`~androguard.core.bytecodes.apk.APK`.
The returned permissions are a list, as some API methods requ... | def get_permissions(self, apilevel=None):
"""
Returns the permissions and the API method based on the API level specified.
This can be used to find usage of API methods which require a permission.
Should be used in combination with an :class:`~androguard.core.bytecodes.apk.APK`.
... |
Find the usage of a permission inside the Analysis.
example::
from androguard.misc import AnalyzeAPK
a, d, dx = AnalyzeAPK("somefile.apk")
for meth in dx.get_permission_usage('android.permission.SEND_SMS', a.get_effective_target_sdk_version()):
print("Using ... | def get_permission_usage(self, permission, apilevel=None):
"""
Find the usage of a permission inside the Analysis.
example::
from androguard.misc import AnalyzeAPK
a, d, dx = AnalyzeAPK("somefile.apk")
for meth in dx.get_permission_usage('android.permission.... |
save your session to use it later.
Returns the filename of the written file.
If not filename is given, a file named `androguard_session_<DATE>.ag` will
be created in the current working directory.
`<DATE>` is a timestamp with the following format: `%Y-%m-%d_%H%M%S`.
This function will overwrite ex... | def Save(session, filename=None):
"""
save your session to use it later.
Returns the filename of the written file.
If not filename is given, a file named `androguard_session_<DATE>.ag` will
be created in the current working directory.
`<DATE>` is a timestamp with the following format: `%Y-%m-%d... |
Print information to stdout about the current session.
Gets all APKs, all DEX files and all Analysis objects. | def show(self):
"""
Print information to stdout about the current session.
Gets all APKs, all DEX files and all Analysis objects.
"""
print("APKs in Session: {}".format(len(self.analyzed_apk)))
for d, a in self.analyzed_apk.items():
print("\t{}: {}".format(d, ... |
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 | 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).hexd... |
Add a DEX file to the Session and run analysis.
:param filename: the (file)name of the DEX file
:param data: binary data of the dex file
:param dx: an existing Analysis Object (optional)
:return: A tuple of SHA256 Hash, DalvikVMFormat Object and Analysis object | def addDEX(self, filename, data, dx=None):
"""
Add a DEX file to the Session and run analysis.
:param filename: the (file)name of the DEX file
:param data: binary data of the dex file
:param dx: an existing Analysis Object (optional)
:return: A tuple of SHA256 Hash, Dalv... |
Generic method to add a file to the session.
This is the main method to use when adding files to a Session!
If an APK file is supplied, all DEX files are analyzed too.
For DEX and ODEX files, only this file is analyzed (what else should be
analyzed).
Returns the SHA256 of the ... | def add(self, filename, raw_data=None, dx=None):
"""
Generic method to add a file to the session.
This is the main method to use when adding files to a Session!
If an APK file is supplied, all DEX files are analyzed too.
For DEX and ODEX files, only this file is analyzed (what ... |
Returns all Java Classes from the DEX objects as an array of DEX files. | def get_classes(self):
"""
Returns all Java Classes from the DEX objects as an array of DEX files.
"""
for idx, digest in enumerate(self.analyzed_vms):
dx = self.analyzed_vms[digest]
for vm in dx.vms:
filename = self.analyzed_digest[digest]
... |
Returns the :class:`~androguard.core.analysis.analysis.Analysis` object
which contains the `current_class`.
:param current_class: The class to search for
:type current_class: androguard.core.bytecodes.dvm.ClassDefItem
:rtype: androguard.core.analysis.analysis.Analysis | def get_analysis(self, current_class):
"""
Returns the :class:`~androguard.core.analysis.analysis.Analysis` object
which contains the `current_class`.
:param current_class: The class to search for
:type current_class: androguard.core.bytecodes.dvm.ClassDefItem
:rtype: an... |
Returns the filename of the DEX file where the class is in.
Returns the first filename this class was present.
For example, if you analyzed an APK, this should return the filename of
the APK and not of the DEX file.
:param current_class: ClassDefItem
:returns: None if class was... | def get_filename_by_class(self, current_class):
"""
Returns the filename of the DEX file where the class is in.
Returns the first filename this class was present.
For example, if you analyzed an APK, this should return the filename of
the APK and not of the DEX file.
:p... |
Return the SHA256 hash of the object containing the ClassDefItem
Returns the first digest this class was present.
For example, if you analyzed an APK, this should return the digest of
the APK and not of the DEX file. | def get_digest_by_class(self, current_class):
"""
Return the SHA256 hash of the object containing the ClassDefItem
Returns the first digest this class was present.
For example, if you analyzed an APK, this should return the digest of
the APK and not of the DEX file.
"""
... |
Yields all StringAnalysis for all unique Analysis objects | def get_strings(self):
"""
Yields all StringAnalysis for all unique Analysis objects
"""
seen = []
for digest, dx in self.analyzed_vms.items():
if dx in seen:
continue
seen.append(dx)
yield digest, self.analyzed_digest[digest], ... |
Return the total number of strings in all Analysis objects | def get_nb_strings(self):
"""
Return the total number of strings in all Analysis objects
"""
nb = 0
seen = []
for digest, dx in self.analyzed_vms.items():
if dx in seen:
continue
seen.append(dx)
nb += len(dx.get_strings_... |
Returns APK, DalvikVMFormat and Analysis of a specified APK.
You must specify either `filename` or `digest`.
It is possible to use both, but in this case only `digest` is used.
example::
s = Session()
digest = s.add("some.apk")
a, d, dx = s.get_objects_apk(... | def get_objects_apk(self, filename=None, digest=None):
"""
Returns APK, DalvikVMFormat and Analysis of a specified APK.
You must specify either `filename` or `digest`.
It is possible to use both, but in this case only `digest` is used.
example::
s = Session()
... |
Yields all dex objects inclduing their Analysis objects
:returns: tuple of (sha256, DalvikVMFormat, Analysis) | def get_objects_dex(self):
"""
Yields all dex objects inclduing their Analysis objects
:returns: tuple of (sha256, DalvikVMFormat, Analysis)
"""
# TODO: there is no variant like get_objects_apk
for digest, d in self.analyzed_dex.items():
yield digest, d, self... |
Parse all the paths (['Lcom/example/myclass/MyActivity$1;', ...])
and build a tree using the QTreeWidgetItem insertion method. | def fill(self):
"""Parse all the paths (['Lcom/example/myclass/MyActivity$1;', ...])
and build a tree using the QTreeWidgetItem insertion method."""
log.debug("Fill classes tree")
for idx, filename, digest, classes in self.session.get_classes():
for c in sorted(classes, k... |
try to parse additional attributes, but ends up to hexdump if the scheme is unknown | def _dump_additional_attributes(additional_attributes):
""" try to parse additional attributes, but ends up to hexdump if the scheme is unknown """
attributes_raw = io.BytesIO(additional_attributes)
attributes_hex = binascii.hexlify(additional_attributes)
if not len(additional_attributes):
ret... |
Print Fingerprints, Issuer and Subject of an X509 Certificate.
:param cert: X509 Certificate to print
:param short: Print in shortform for DN (Default: False)
:type cert: :class:`asn1crypto.x509.Certificate`
:type short: Boolean | def show_Certificate(cert, short=False):
"""
Print Fingerprints, Issuer and Subject of an X509 Certificate.
:param cert: X509 Certificate to print
:param short: Print in shortform for DN (Default: False)
:type cert: :class:`asn1crypto.x509.Certificate`
:type short: Boolean
... |
Ensure incoming value is always the value, not the resid
androguard will sometimes return the Android "resId" aka
Resource ID instead of the actual value. This checks whether
the value is actually a resId, then performs the Android
Resource lookup as needed. | def ensure_final_value(packageName, arsc, value):
"""Ensure incoming value is always the value, not the resid
androguard will sometimes return the Android "resId" aka
Resource ID instead of the actual value. This checks whether
the value is actually a resId, then performs the Android
Resource look... |
Read (appid, versionCode, versionName) from an APK
This first tries to do quick binary XML parsing to just get the
values that are needed. It will fallback to full androguard
parsing, which is slow, if it can't find the versionName value or
versionName is set to a Android String Resource (e.g. an inte... | def get_apkid(apkfile):
"""Read (appid, versionCode, versionName) from an APK
This first tries to do quick binary XML parsing to just get the
values that are needed. It will fallback to full androguard
parsing, which is slow, if it can't find the versionName value or
versionName is set to a Androi... |
Return the appname of the APK
This name is read from the AndroidManifest.xml
using the application android:label.
If no label exists, the android:label of the main activity is used.
If there is also no main activity label, an empty string is returned.
:rtype: :class:`str` | def get_app_name(self):
"""
Return the appname of the APK
This name is read from the AndroidManifest.xml
using the application android:label.
If no label exists, the android:label of the main activity is used.
If there is also no main activity label, an empty string is ... |
Return the first icon file name, which density is not greater than max_dpi,
unless exact icon resolution is set in the manifest, in which case
return the exact file.
This information is read from the AndroidManifest.xml
From https://developer.android.com/guide/practices/screens_support... | def get_app_icon(self, max_dpi=65536):
"""
Return the first icon file name, which density is not greater than max_dpi,
unless exact icon resolution is set in the manifest, in which case
return the exact file.
This information is read from the AndroidManifest.xml
From ht... |
Return the filetype guessed for a buffer
:param buffer: bytes
:returns: str of filetype | def _get_file_magic_name(self, buffer):
"""
Return the filetype guessed for a buffer
:param buffer: bytes
:returns: str of filetype
"""
default = "Unknown"
# Faster way, test once, return default.
if self.__no_magic:
return default
tr... |
Return the files inside the APK with their associated types (by using python-magic)
At the same time, the CRC32 are calculated for the files.
:rtype: a dictionnary | def get_files_types(self):
"""
Return the files inside the APK with their associated types (by using python-magic)
At the same time, the CRC32 are calculated for the files.
:rtype: a dictionnary
"""
if self._files == {}:
# Generate File Types / CRC List
... |
Overwrite some probably wrong detections by mime libraries
:param buffer: bytes of the file to detect
:param orig: guess by mime libary
:returns: corrected guess | def _patch_magic(self, buffer, orig):
"""
Overwrite some probably wrong detections by mime libraries
:param buffer: bytes of the file to detect
:param orig: guess by mime libary
:returns: corrected guess
"""
if ("Zip" in orig) or ('(JAR)' in orig) and androconf.i... |
Calculates and compares the CRC32 and returns the raw buffer.
The CRC32 is added to `files_crc32` dictionary, if not present.
:param filename: filename inside the zipfile
:rtype: bytes | def _get_crc32(self, filename):
"""
Calculates and compares the CRC32 and returns the raw buffer.
The CRC32 is added to `files_crc32` dictionary, if not present.
:param filename: filename inside the zipfile
:rtype: bytes
"""
buffer = self.zip.read(filename)
... |
Calculates and returns a dictionary of filenames and CRC32
:returns: dict of filename: CRC32 | def get_files_crc32(self):
"""
Calculates and returns a dictionary of filenames and CRC32
:returns: dict of filename: CRC32
"""
if self.files_crc32 == {}:
for i in self.get_files():
self._get_crc32(i)
return self.files_crc32 |
Return the files inside the APK with their associated types and crc32
:rtype: str, str, int | def get_files_information(self):
"""
Return the files inside the APK with their associated types and crc32
:rtype: str, str, int
"""
for k in self.get_files():
yield k, self.get_files_types()[k], self.get_files_crc32()[k] |
Return the raw data of the specified filename
inside the APK
:rtype: bytes | def get_file(self, filename):
"""
Return the raw data of the specified filename
inside the APK
:rtype: bytes
"""
try:
return self.zip.read(filename)
except KeyError:
raise FileNotPresent(filename) |
Return the names of all DEX files found in the APK.
This method only accounts for "offical" dex files, i.e. all files
in the root directory of the APK named classes.dex or classes[0-9]+.dex
:rtype: a list of str | def get_dex_names(self):
"""
Return the names of all DEX files found in the APK.
This method only accounts for "offical" dex files, i.e. all files
in the root directory of the APK named classes.dex or classes[0-9]+.dex
:rtype: a list of str
"""
dexre = re.compile... |
Yields all the attribute values in xml files which match with the tag name and the specific attribute
:param str tag_name: specify the tag name
:param str attribute: specify the attribute
:param bool format_value: specify if the value needs to be formatted with packagename | def get_all_attribute_value(
self, tag_name, attribute, format_value=True, **attribute_filter
):
"""
Yields all the attribute values in xml files which match with the tag name and the specific attribute
:param str tag_name: specify the tag name
:param str attribute: specify ... |
Return the attribute value in xml files which matches the tag name and the specific attribute
:param str tag_name: specify the tag name
:param str attribute: specify the attribute
:param bool format_value: specify if the value needs to be formatted with packagename | def get_attribute_value(
self, tag_name, attribute, format_value=False, **attribute_filter
):
"""
Return the attribute value in xml files which matches the tag name and the specific attribute
:param str tag_name: specify the tag name
:param str attribute: specify the attribu... |
Return the value of the android prefixed attribute in a specific tag.
This function will always try to get the attribute with a android: prefix first,
and will try to return the attribute without the prefix, if the attribute could not be found.
This is useful for some broken AndroidManifest.xml... | def get_value_from_tag(self, tag, attribute):
"""
Return the value of the android prefixed attribute in a specific tag.
This function will always try to get the attribute with a android: prefix first,
and will try to return the attribute without the prefix, if the attribute could not be... |
Return a list of all the matched tags in all available xml
:param str tag: specify the tag name | def find_tags(self, tag_name, **attribute_filter):
"""
Return a list of all the matched tags in all available xml
:param str tag: specify the tag name
"""
all_tags = [
self.find_tags_from_xml(
i, tag_name, **attribute_filter
)
... |
Return a list of all the matched tags in a specific xml
w
:param str xml_name: specify from which xml to pick the tag from
:param str tag_name: specify the tag name | def find_tags_from_xml(
self, xml_name, tag_name, **attribute_filter
):
"""
Return a list of all the matched tags in a specific xml
w
:param str xml_name: specify from which xml to pick the tag from
:param str tag_name: specify the tag name
"""
xml = s... |
r"""
Return true if the attributes matches in attribute filter.
An attribute filter is a dictionary containing: {attribute_name: value}.
This function will return True if and only if all attributes have the same value.
This function allows to set the dictionary via kwargs, thus you can ... | def is_tag_matched(self, tag, **attribute_filter):
r"""
Return true if the attributes matches in attribute filter.
An attribute filter is a dictionary containing: {attribute_name: value}.
This function will return True if and only if all attributes have the same value.
This func... |
Return names of the main activities
These values are read from the AndroidManifest.xml
:rtype: a set of str | def get_main_activities(self):
"""
Return names of the main activities
These values are read from the AndroidManifest.xml
:rtype: a set of str
"""
x = set()
y = set()
for i in self.xml:
if self.xml[i] is None:
continue
... |
Return the name of the main activity
This value is read from the AndroidManifest.xml
:rtype: str | def get_main_activity(self):
"""
Return the name of the main activity
This value is read from the AndroidManifest.xml
:rtype: str
"""
activities = self.get_main_activities()
if len(activities) > 0:
return self._format_value(activities.pop())
... |
Find intent filters for a given item and name.
Intent filter are attached to activities, services or receivers.
You can search for the intent filters of such items and get a dictionary of all
attached actions and intent categories.
:param itemtype: the type of parent item to look for, ... | def get_intent_filters(self, itemtype, name):
"""
Find intent filters for a given item and name.
Intent filter are attached to activities, services or receivers.
You can search for the intent filters of such items and get a dictionary of all
attached actions and intent categorie... |
Return all permissions implied by the target SDK or other permissions.
:rtype: list of string | def get_uses_implied_permission_list(self):
"""
Return all permissions implied by the target SDK or other permissions.
:rtype: list of string
"""
target_sdk_version = self.get_effective_target_sdk_version()
READ_CALL_LOG = 'android.permission.READ_CALL_LOG'
... |
Return permissions with details.
THis can only return details about the permission, if the permission is
defined in the AOSP.
:rtype: dict of {permission: [protectionLevel, label, description]} | def get_details_permissions(self):
"""
Return permissions with details.
THis can only return details about the permission, if the permission is
defined in the AOSP.
:rtype: dict of {permission: [protectionLevel, label, description]}
"""
l = {}
for i in ... |
Returns requested permissions declared within AOSP project.
This includes several other permissions as well, which are in the platform apps.
:rtype: list of str | def get_requested_aosp_permissions(self):
"""
Returns requested permissions declared within AOSP project.
This includes several other permissions as well, which are in the platform apps.
:rtype: list of str
"""
aosp_permissions = []
all_permissions = self.get_pe... |
Returns requested aosp permissions with details.
:rtype: dictionary | def get_requested_aosp_permissions_details(self):
"""
Returns requested aosp permissions with details.
:rtype: dictionary
"""
l = {}
for i in self.permissions:
try:
l[i] = self.permission_module[i]
except KeyError:
... |
Returns list of requested permissions not declared within AOSP project.
:rtype: list of strings | def get_requested_third_party_permissions(self):
"""
Returns list of requested permissions not declared within AOSP project.
:rtype: list of strings
"""
third_party_permissions = []
all_permissions = self.get_permissions()
for perm in all_permissions:
... |
Return the effective targetSdkVersion, always returns int > 0.
If the targetSdkVersion is not set, it defaults to 1. This is
set based on defaults as defined in:
https://developer.android.com/guide/topics/manifest/uses-sdk-element.html
:rtype: int | def get_effective_target_sdk_version(self):
"""
Return the effective targetSdkVersion, always returns int > 0.
If the targetSdkVersion is not set, it defaults to 1. This is
set based on defaults as defined in:
https://developer.android.com/guide/topics/manifest/... |
Return the DER coded X.509 certificate from the signature file.
:param filename: Signature filename in APK
:returns: DER coded X.509 certificate as binary | def get_certificate_der(self, filename):
"""
Return the DER coded X.509 certificate from the signature file.
:param filename: Signature filename in APK
:returns: DER coded X.509 certificate as binary
"""
pkcs7message = self.get_file(filename)
pkcs7obj = cms.Cont... |
Return a X.509 certificate object by giving the name in the apk file
:param filename: filename of the signature file in the APK
:returns: a :class:`Certificate` certificate | def get_certificate(self, filename):
"""
Return a X.509 certificate object by giving the name in the apk file
:param filename: filename of the signature file in the APK
:returns: a :class:`Certificate` certificate
"""
cert = self.get_certificate_der(filename)
cer... |
Create a new zip file
:param filename: the output filename of the zip
:param deleted_files: a regex pattern to remove specific file
:param new_files: a dictionnary of new files
:type filename: string
:type deleted_files: None or a string
:type ne... | def new_zip(self, filename, deleted_files=None, new_files={}):
"""
Create a new zip file
:param filename: the output filename of the zip
:param deleted_files: a regex pattern to remove specific file
:param new_files: a dictionnary of new files
:type ... |
Parse digests | def parse_signatures_or_digests(self, digest_bytes):
""" Parse digests """
if not len(digest_bytes):
return []
digests = []
block = io.BytesIO(digest_bytes)
data_len = self.read_uint32_le(block)
while block.tell() < data_len:
algorithm_... |
Parse the V2 signing block and extract all features | def parse_v3_signing_block(self):
"""
Parse the V2 signing block and extract all features
"""
self._v3_signing_data = []
# calling is_signed_v3 should also load the signature, if any
if not self.is_signed_v3():
return
block_bytes = self._v2_blocks[s... |
Parse the V2 signing block and extract all features | def parse_v2_signing_block(self):
"""
Parse the V2 signing block and extract all features
"""
self._v2_signing_data = []
# calling is_signed_v2 should also load the signature
if not self.is_signed_v2():
return
block_bytes = self._v2_blocks[self._APK... |
Return a list of DER coded X.509 public keys from the v3 signature block | def get_public_keys_der_v3(self):
"""
Return a list of DER coded X.509 public keys from the v3 signature block
"""
if self._v3_signing_data == None:
self.parse_v3_signing_block()
public_keys = []
for signer in self._v3_signing_data:
public_keys.... |
Return a list of DER coded X.509 public keys from the v3 signature block | def get_public_keys_der_v2(self):
"""
Return a list of DER coded X.509 public keys from the v3 signature block
"""
if self._v2_signing_data == None:
self.parse_v2_signing_block()
public_keys = []
for signer in self._v2_signing_data:
public_keys.... |
Return a list of DER coded X.509 certificates from the v3 signature block | def get_certificates_der_v3(self):
"""
Return a list of DER coded X.509 certificates from the v3 signature block
"""
if self._v3_signing_data == None:
self.parse_v3_signing_block()
certs = []
for signed_data in [signer.signed_data for signer in self._v3_sign... |
Return a list of DER coded X.509 certificates from the v3 signature block | def get_certificates_der_v2(self):
"""
Return a list of DER coded X.509 certificates from the v3 signature block
"""
if self._v2_signing_data == None:
self.parse_v2_signing_block()
certs = []
for signed_data in [signer.signed_data for signer in self._v2_sign... |
Return a list of :class:`asn1crypto.x509.Certificate` which are found
in the META-INF folder (v1 signing).
Note that we simply extract all certificates regardless of the signer.
Therefore this is just a list of all certificates found in all signers. | def get_certificates_v1(self):
"""
Return a list of :class:`asn1crypto.x509.Certificate` which are found
in the META-INF folder (v1 signing).
Note that we simply extract all certificates regardless of the signer.
Therefore this is just a list of all certificates found in all sign... |
Return a list of unique :class:`asn1crypto.x509.Certificate` which are found
in v1, v2 and v3 signing
Note that we simply extract all certificates regardless of the signer.
Therefore this is just a list of all certificates found in all signers. | def get_certificates(self):
"""
Return a list of unique :class:`asn1crypto.x509.Certificate` which are found
in v1, v2 and v3 signing
Note that we simply extract all certificates regardless of the signer.
Therefore this is just a list of all certificates found in all signers.
... |
Return a list of the signature file names (v1 Signature / JAR
Signature)
:rtype: List of filenames matching a Signature | def get_signature_names(self):
"""
Return a list of the signature file names (v1 Signature / JAR
Signature)
:rtype: List of filenames matching a Signature
"""
signature_expr = re.compile(r"^(META-INF/)(.*)(\.RSA|\.EC|\.DSA)$")
signatures = []
for i in se... |
Return a list of the data of the signature files.
Only v1 / JAR Signing.
:rtype: list of bytes | def get_signatures(self):
"""
Return a list of the data of the signature files.
Only v1 / JAR Signing.
:rtype: list of bytes
"""
signature_expr = re.compile(r"^(META-INF/)(.*)(\.RSA|\.EC|\.DSA)$")
signature_datas = []
for i in self.get_files():
... |
Export analysis method to dot format
:param mx: :class:`~androguard.core.analysis.analysis.MethodAnalysis`
:param colors: dict of colors to use, if colors is None the default colors are used
:returns: a string which contains the dot graph | def method2dot(mx, colors=None):
"""
Export analysis method to dot format
:param mx: :class:`~androguard.core.analysis.analysis.MethodAnalysis`
:param colors: dict of colors to use, if colors is None the default colors are used
:returns: a string which contains the dot graph
"""
if not co... |
Export method to a specific file format
@param output : output filename
@param _format : format type (png, jpg ...) (default : png)
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer if None | def method2format(output, _format="png", mx=None, raw=None):
"""
Export method to a specific file format
@param output : output filename
@param _format : format type (png, jpg ...) (default : png)
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer if None
... |
Export method to a png file format
:param output: output filename
:type output: string
:param mx: specify the MethodAnalysis object
:type mx: :class:`MethodAnalysis` object
:param raw: use directly a dot raw buffer
:type raw: string | def method2png(output, mx, raw=False):
"""
Export method to a png file format
:param output: output filename
:type output: string
:param mx: specify the MethodAnalysis object
:type mx: :class:`MethodAnalysis` object
:param raw: use directly a dot raw buffer
:type raw: string
"""
... |
Export method to a jpg file format
:param output: output filename
:type output: string
:param mx: specify the MethodAnalysis object
:type mx: :class:`MethodAnalysis` object
:param raw: use directly a dot raw buffer (optional)
:type raw: string | def method2jpg(output, mx, raw=False):
"""
Export method to a jpg file format
:param output: output filename
:type output: string
:param mx: specify the MethodAnalysis object
:type mx: :class:`MethodAnalysis` object
:param raw: use directly a dot raw buffer (optional)
:type raw: string
... |
Get a JSON representation of a DEX file
:param vm: :class:`~androguard.core.bytecodes.dvm.DalvikVMFormat`
:return: | def vm2json(vm):
"""
Get a JSON representation of a DEX file
:param vm: :class:`~androguard.core.bytecodes.dvm.DalvikVMFormat`
:return:
"""
d = {"name": "root", "children": []}
for _class in vm.get_classes():
c_class = {"name": _class.get_name(), "children": []}
for method... |
Convert a object to a bytearray or call get_raw() of the object
if no useful type was found. | def object_to_bytes(obj):
"""
Convert a object to a bytearray or call get_raw() of the object
if no useful type was found.
"""
if isinstance(obj, str):
return bytearray(obj, "UTF-8")
elif isinstance(obj, bool):
return bytearray()
elif isinstance(obj, int):
return pack... |
Transform a typed class name into a form which can be used as a python
attribute
example::
>>> FormatClassToPython('Lfoo/bar/foo/Barfoo$InnerClass;')
'Lfoo_bar_foo_Barfoo_InnerClass'
:param i: classname to transform
:rtype: str | def FormatClassToPython(i):
"""
Transform a typed class name into a form which can be used as a python
attribute
example::
>>> FormatClassToPython('Lfoo/bar/foo/Barfoo$InnerClass;')
'Lfoo_bar_foo_Barfoo_InnerClass'
:param i: classname to transform
:rtype: str
"""
i = i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.