INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Return package and class name in a java variant from a typed variant name.
If no package could be found, the package is an empty string.
example::
>>> get_package_class_name('Ljava/lang/Object;')
('java.lang', 'Object')
:param name: the name
:rtype: tuple
:return: | def get_package_class_name(name):
"""
Return package and class name in a java variant from a typed variant name.
If no package could be found, the package is an empty string.
example::
>>> get_package_class_name('Ljava/lang/Object;')
('java.lang', 'Object')
:param name: the name
... |
Transform a (method) name into a form which can be used as a python
attribute
example::
>>> FormatNameToPython('<clinit>')
'clinit'
:param i: name to transform
:rtype: str | def FormatNameToPython(i):
"""
Transform a (method) name into a form which can be used as a python
attribute
example::
>>> FormatNameToPython('<clinit>')
'clinit'
:param i: name to transform
:rtype: str
"""
i = i.replace("<", "")
i = i.replace(">", "")
i = i.r... |
Format a descriptor into a form which can be used as a python attribute
example::
>>> FormatDescriptorToPython('(Ljava/lang/Long; Ljava/lang/Long; Z Z)V')
'Ljava_lang_LongLjava_lang_LongZZV
:param i: name to transform
:rtype: str | def FormatDescriptorToPython(i):
"""
Format a descriptor into a form which can be used as a python attribute
example::
>>> FormatDescriptorToPython('(Ljava/lang/Long; Ljava/lang/Long; Z Z)V')
'Ljava_lang_LongLjava_lang_LongZZV
:param i: name to transform
:rtype: str
"""
i... |
Read bytes with length `size` without incrementing the current offset
:param int size: length to read in bytes
:rtype: bytearray | def read_b(self, size):
"""
Read bytes with length `size` without incrementing the current offset
:param int size: length to read in bytes
:rtype: bytearray
"""
return self.__buff[self.__idx:self.__idx + size] |
Read all bytes from the start of `off` until the end of the buffer
This method can be used to determine a checksum of a buffer from a given
point on.
:param int off: starting offset
:rtype: bytearray | def readat(self, off):
"""
Read all bytes from the start of `off` until the end of the buffer
This method can be used to determine a checksum of a buffer from a given
point on.
:param int off: starting offset
:rtype: bytearray
"""
if isinstance(off, SV):... |
Read from the current offset a total number of `size` bytes
and increment the offset by `size`
:param int size: length of bytes to read
:rtype: bytearray | def read(self, size):
"""
Read from the current offset a total number of `size` bytes
and increment the offset by `size`
:param int size: length of bytes to read
:rtype: bytearray
"""
if isinstance(size, SV):
size = size.value
buff = self.__b... |
Save the current buffer to `filename`
Exisiting files with the same name will be overwritten.
:param str filename: the name of the file to save to | def save(self, filename):
"""
Save the current buffer to `filename`
Exisiting files with the same name will be overwritten.
:param str filename: the name of the file to save to
"""
with open(filename, "wb") as fd:
fd.write(self.__buff) |
Read a null terminated string from a file-like object.
:param f: file-like object
:rtype: bytearray | def read_null_terminated_string(f):
"""
Read a null terminated string from a file-like object.
:param f: file-like object
:rtype: bytearray
"""
x = bytearray()
while True:
z = f.read(1)
if ord(z) == 0:
return x
else:
x.append(ord(z)) |
Transform an access flag field to the corresponding string
:param value: the value of the access flags
:type value: int
:rtype: string | def get_access_flags_string(value):
"""
Transform an access flag field to the corresponding string
:param value: the value of the access flags
:type value: int
:rtype: string
"""
flags = []
for k, v in ACCESS_FLAGS.items():
if (k & value) == k:
flags.append(v)
... |
Read a signed LEB128 at the current position of the buffer.
:param buff: a file like object
:return: decoded sLEB128 | def readsleb128(buff):
"""
Read a signed LEB128 at the current position of the buffer.
:param buff: a file like object
:return: decoded sLEB128
"""
result = 0
shift = 0
for x in range(0, 5):
cur = get_byte(buff)
result |= (cur & 0x7f) << shift
shift += 7
... |
Determine the next offsets inside the bytecode of an :class:`EncodedMethod`.
The offsets are calculated in number of bytes from the start of the method.
Note, that offsets inside the bytecode are denoted in 16bit units but this method returns actual bytes!
Offsets inside the opcode are counted from the beg... | def determineNext(i, cur_idx, m):
"""
Determine the next offsets inside the bytecode of an :class:`EncodedMethod`.
The offsets are calculated in number of bytes from the start of the method.
Note, that offsets inside the bytecode are denoted in 16bit units but this method returns actual bytes!
Offs... |
Returns try-catch handler inside the method.
:param vm: a :class:`~DalvikVMFormat`
:param m: a :class:`~EncodedMethod`
:return: | def determineException(vm, m):
"""
Returns try-catch handler inside the method.
:param vm: a :class:`~DalvikVMFormat`
:param m: a :class:`~EncodedMethod`
:return:
"""
# no exceptions !
if m.get_code().get_tries_size() <= 0:
return []
h_off = {}
handler_catch_list = m.g... |
Return the value of the 'kind' argument
:param cm: a ClassManager object
:type cm: :class:`ClassManager`
:param kind: the type of the 'kind' argument
:type kind: int
:param value: the value of the 'kind' argument
:type value: int
:rtype: string | def get_kind(cm, kind, value):
"""
Return the value of the 'kind' argument
:param cm: a ClassManager object
:type cm: :class:`ClassManager`
:param kind: the type of the 'kind' argument
:type kind: int
:param value: the value of the 'kind' argument
:type value: int
:rtype: string
... |
Returns an Unicode String
This is the actual string. Beware that some strings might be not
decodeable with usual UTF-16 decoder, as they use surrogates that are
not supported by python. | def get_unicode(self):
"""
Returns an Unicode String
This is the actual string. Beware that some strings might be not
decodeable with usual UTF-16 decoder, as they use surrogates that are
not supported by python.
"""
s = mutf8.decode(self.data)
if len(s) !... |
Returns a printable string.
In this case, all lonely surrogates are escaped, thus are represented in the
string as 6 characters: \\ud853
Valid surrogates are encoded as 32bit values, ie. \U00024f5c. | def get(self):
"""
Returns a printable string.
In this case, all lonely surrogates are escaped, thus are represented in the
string as 6 characters: \\ud853
Valid surrogates are encoded as 32bit values, ie. \U00024f5c.
"""
s = mutf8.decode(self.data)
if len... |
Return the class name of the field
:rtype: string | def get_class_name(self):
"""
Return the class name of the field
:rtype: string
"""
if self.class_idx_value is None:
self.class_idx_value = self.CM.get_type(self.class_idx)
return self.class_idx_value |
Return the prototype of the method
:rtype: string | def get_proto(self):
"""
Return the prototype of the method
:rtype: string
"""
if self.proto_idx_value is None:
self.proto_idx_value = self.CM.get_proto(self.proto_idx)
return self.proto_idx_value |
Display the information (with a pretty print) about the field | def show(self):
"""
Display the information (with a pretty print) about the field
"""
bytecode._PrintSubBanner("Field Information")
bytecode._PrintDefault("{}->{} {} [access_flags={}]\n".format(
self.get_class_name(), self.get_name(), self.get_descriptor(),
... |
From the Dalvik Bytecode documentation:
> The N arguments to a method land in the last N registers
> of the method's invocation frame, in order.
> Wide arguments consume two registers.
> Instance methods are passed a this reference as their first argument.
This method will prin... | def each_params_by_register(self, nb, proto):
"""
From the Dalvik Bytecode documentation:
> The N arguments to a method land in the last N registers
> of the method's invocation frame, in order.
> Wide arguments consume two registers.
> Instance methods are passed a this... |
Return a shorter formatted String which encodes this method.
The returned name has the form:
<classname> <methodname> ([arguments ...])<returntype>
* All Class names are condensed to the actual name (no package).
* Access flags are not returned.
* <init> and <clinit> are NOT rep... | def get_short_string(self):
"""
Return a shorter formatted String which encodes this method.
The returned name has the form:
<classname> <methodname> ([arguments ...])<returntype>
* All Class names are condensed to the actual name (no package).
* Access flags are not ret... |
Display the information (with a pretty print) about the method | def show(self):
"""
Display the information (with a pretty print) about the method
"""
self.show_info()
self.show_notes()
if self.code:
self.each_params_by_register(self.code.get_registers_size(), self.get_descriptor())
self.code.show() |
Display the notes about the method | def show_notes(self):
"""
Display the notes about the method
"""
if self.notes:
bytecode._PrintSubBanner("Notes")
for i in self.notes:
bytecode._PrintNote(i)
bytecode._PrintSubBanner() |
Get a particular instruction by using (default) the index of the address if specified
:param idx: index of the instruction (the position in the list of the instruction)
:type idx: int
:param off: address of the instruction
:type off: int
:rtype: an :class:`Instruction` object | def get_instruction(self, idx, off=None):
"""
Get a particular instruction by using (default) the index of the address if specified
:param idx: index of the instruction (the position in the list of the instruction)
:type idx: int
:param off: address of the instruction
:t... |
Return direct and virtual methods
:rtype: a list of :class:`EncodedMethod` objects | def get_methods(self):
"""
Return direct and virtual methods
:rtype: a list of :class:`EncodedMethod` objects
"""
return [x
for x in self.direct_methods] + [x
for x in self.virtual_methods] |
Return static and instance fields
:rtype: a list of :class:`EncodedField` objects | def get_fields(self):
"""
Return static and instance fields
:rtype: a list of :class:`EncodedField` objects
"""
return [x for x in self.static_fields] + [x
for x in self.instance_fields] |
:rtype: bytearray | def get_raw(self):
"""
:rtype: bytearray
"""
buff = bytearray()
buff += writesleb128(self.size)
for i in self.handlers:
buff += i.get_raw()
if self.size <= 0:
buff += writeuleb128(self.catch_all_addr)
return buff |
:rtype: bytearray | def get_raw(self):
"""
:rtype: bytearray
"""
buff = bytearray()
buff += self.get_obj()
for i in self.list:
buff += i.get_raw()
return buff |
Return the 'kind' argument of the instruction
:rtype: int | def get_kind(self):
"""
Return the 'kind' argument of the instruction
:rtype: int
"""
if self.OP > 0xff:
if self.OP >= 0xf2ff:
return DALVIK_OPCODES_OPTIMIZED[self.OP][1][1]
return DALVIK_OPCODES_EXTENDED_WIDTH[self.OP][1][1]
retur... |
Return the name of the instruction
:rtype: string | def get_name(self):
"""
Return the name of the instruction
:rtype: string
"""
if self.OP > 0xff:
if self.OP >= 0xf2ff:
return DALVIK_OPCODES_OPTIMIZED[self.OP][1][0]
return DALVIK_OPCODES_EXTENDED_WIDTH[self.OP][1][0]
return DALVIK... |
Print the instruction | def show(self, idx):
"""
Print the instruction
"""
print(self.get_name() + " " + self.get_output(idx), end=' ') |
Return the display of the instruction
:rtype: string | def show_buff(self, pos):
"""
Return the display of the instruction
:rtype: string
"""
buff = self.get_name() + " "
for i in range(0, len(self.data)):
buff += "\\x%02x" % self.data[i]
return buff |
Returns a HEX String, separated by spaces every byte | def get_hex(self):
"""
Returns a HEX String, separated by spaces every byte
"""
s = binascii.hexlify(self.get_raw()).decode("ascii")
return " ".join(s[i:i + 2] for i in range(0, len(s), 2)) |
Return the keys of the instruction
:rtype: a list of long | def get_keys(self):
"""
Return the keys of the instruction
:rtype: a list of long
"""
return [(self.first_key + i) for i in range(0, len(self.targets))] |
Return an additional output of the instruction
:rtype: string | def get_output(self, idx=-1):
"""
Return an additional output of the instruction
:rtype: string
"""
return " ".join("%x" % (self.first_key + i)
for i in range(0, len(self.targets))) |
Return the display of the instruction
:rtype: string | def show_buff(self, pos):
"""
Return the display of the instruction
:rtype: string
"""
buff = self.get_name() + " "
buff += "%x:" % self.first_key
for i in self.targets:
buff += " %x" % i
return buff |
Set a new raw buffer to disassemble
:param insn: the buffer
:type insn: string | def set_insn(self, insn):
"""
Set a new raw buffer to disassemble
:param insn: the buffer
:type insn: string
"""
self.insn = insn
self.size = len(self.insn) |
Get the instructions
:rtype: a generator of each :class:`Instruction` (or a cached list of instructions if you have setup instructions) | def get_instructions(self):
"""
Get the instructions
:rtype: a generator of each :class:`Instruction` (or a cached list of instructions if you have setup instructions)
"""
# it is possible to a cache for instructions (avoid a new disasm)
if self.cached_instructions is No... |
Add a message to a specific instruction by using (default) the index of the address if specified
:param msg: the message
:type msg: string
:param idx: index of the instruction (the position in the list of the instruction)
:type idx: int
:param off: address of the instruction
... | def add_inote(self, msg, idx, off=None):
"""
Add a message to a specific instruction by using (default) the index of the address if specified
:param msg: the message
:type msg: string
:param idx: index of the instruction (the position in the list of the instruction)
:typ... |
Get a particular instruction by using (default) the index of the address if specified
:param idx: index of the instruction (the position in the list of the instruction)
:type idx: int
:param off: address of the instruction
:type off: int
:rtype: an :class:`Instruction` object | def get_instruction(self, idx, off=None):
"""
Get a particular instruction by using (default) the index of the address if specified
:param idx: index of the instruction (the position in the list of the instruction)
:type idx: int
:param off: address of the instruction
:t... |
Get the position of an instruction by using the address
:param off: address of the instruction
:type off: int
:rtype: int | def off_to_pos(self, off):
"""
Get the position of an instruction by using the address
:param off: address of the instruction
:type off: int
:rtype: int
"""
idx = 0
nb = 0
for i in self.get_instructions():
if idx == off:
... |
Get a particular instruction by using the address
:param off: address of the instruction
:type off: int
:rtype: an :class:`Instruction` object | def get_ins_off(self, off):
"""
Get a particular instruction by using the address
:param off: address of the instruction
:type off: int
:rtype: an :class:`Instruction` object
"""
idx = 0
for i in self.get_instructions():
if idx == off:
... |
Display (with a pretty print) this object | def show(self):
"""
Display (with a pretty print) this object
"""
off = 0
for n, i in enumerate(self.get_instructions()):
print("{:8d} (0x{:08x}) {:04x} {:30} {}".format(n, off, i.get_op_value(), i.get_name(), i.get_output(self.idx)))
off += i.get_length() |
Return the raw buffer of this object
:rtype: bytearray | def get_raw(self):
"""
Return the raw buffer of this object
:rtype: bytearray
"""
buff = bytearray()
for i in self.get_instructions():
buff += i.get_raw()
return buff |
Get the reconstructed code as bytearray
:rtype: bytearray | def get_raw(self):
"""
Get the reconstructed code as bytearray
:rtype: bytearray
"""
code_raw = self.code.get_raw()
self.insns_size = (len(code_raw) // 2) + (len(code_raw) % 2)
buff = bytearray()
buff += pack("<H", self.registers_size) + \
... |
Return a string from the string table at index `idx`
:param int idx: index in the string section | def get_string(self, idx):
"""
Return a string from the string table at index `idx`
:param int idx: index in the string section
"""
if idx in self.hook_strings:
return self.hook_strings[idx]
try:
off = self.__manage_item[TypeMapItem.STRING_ID_ITE... |
Return the (unprocessed) string from the string table at index `idx`.
:param int idx: the index in the string section | def get_raw_string(self, idx):
"""
Return the (unprocessed) string from the string table at index `idx`.
:param int idx: the index in the string section
"""
try:
off = self.__manage_item[TypeMapItem.STRING_ID_ITEM][idx].get_string_data_off()
except IndexError... |
Return the resolved type name based on the index
This returns the string associated with the type.
:param int idx:
:return: the type name
:rtype: str | def get_type(self, idx):
"""
Return the resolved type name based on the index
This returns the string associated with the type.
:param int idx:
:return: the type name
:rtype: str
"""
_type = self.get_type_ref(idx)
if _type == -1:
retu... |
Flush all caches
Might be used after classes, methods or fields are added. | def _flush(self):
"""
Flush all caches
Might be used after classes, methods or fields are added.
"""
self.classes_names = None
self.__cache_methods = None
self.__cached_methods_idx = None
self.__cache_fields = None
# cache methods and fields as we... |
Return the names of classes
:param update: True indicates to recompute the list.
Maybe needed after using a MyClass.set_name().
:rtype: a list of string | def get_classes_names(self, update=False):
"""
Return the names of classes
:param update: True indicates to recompute the list.
Maybe needed after using a MyClass.set_name().
:rtype: a list of string
"""
if self.classes_names is None or update:
... |
Print with a pretty display the MapList object | def show(self):
"""
Print with a pretty display the MapList object
"""
bytecode._Print("MAP_LIST SIZE", self.size)
for i in self.map_item:
if i.item != self:
# FIXME this does not work for CodeItems!
# as we do not have the method analy... |
Return a specific class
:param name: the name of the class
:rtype: a :class:`ClassDefItem` object | def get_class(self, name):
"""
Return a specific class
:param name: the name of the class
:rtype: a :class:`ClassDefItem` object
"""
for i in self.get_classes():
if i.get_name() == name:
return i
return None |
Return a list all methods which corresponds to the regexp
:param name: the name of the method (a python regexp)
:rtype: a list with all :class:`EncodedMethod` objects | def get_method(self, name):
"""
Return a list all methods which corresponds to the regexp
:param name: the name of the method (a python regexp)
:rtype: a list with all :class:`EncodedMethod` objects
"""
# TODO could use a generator here
prog = re.compile(name)
... |
Return a list all fields which corresponds to the regexp
:param name: the name of the field (a python regexp)
:rtype: a list with all :class:`EncodedField` objects | def get_field(self, name):
"""
Return a list all fields which corresponds to the regexp
:param name: the name of the field (a python regexp)
:rtype: a list with all :class:`EncodedField` objects
"""
# TODO could use a generator here
prog = re.compile(name)
... |
Return all field objects
:rtype: a list of :class:`EncodedField` objects | def get_fields(self):
"""
Return all field objects
:rtype: a list of :class:`EncodedField` objects
"""
if self.__cache_all_fields is None:
self.__cache_all_fields = []
for i in self.get_classes():
for j in i.get_fields():
... |
Return all method objects
:rtype: a list of :class:`EncodedMethod` objects | def get_methods(self):
"""
Return all method objects
:rtype: a list of :class:`EncodedMethod` objects
"""
if self.__cache_all_methods is None:
self.__cache_all_methods = []
for i in self.get_classes():
for j in i.get_methods():
... |
Return a specific method by using an index
:param idx: the index of the method
:type idx: int
:rtype: None or an :class:`EncodedMethod` object | def get_method_by_idx(self, idx):
"""
Return a specific method by using an index
:param idx: the index of the method
:type idx: int
:rtype: None or an :class:`EncodedMethod` object
"""
if self.__cached_methods_idx is None:
self.__cached_methods_idx = ... |
Return the specific method
:param class_name: the class name of the method
:type class_name: string
:param method_name: the name of the method
:type method_name: string
:param descriptor: the descriptor of the method
:type descriptor: string
:rtype: None or a :c... | def get_method_descriptor(self, class_name, method_name, descriptor):
"""
Return the specific method
:param class_name: the class name of the method
:type class_name: string
:param method_name: the name of the method
:type method_name: string
:param descriptor: t... |
Return the specific methods of the class
:param class_name: the class name of the method
:type class_name: string
:param method_name: the name of the method
:type method_name: string
:rtype: None or a :class:`EncodedMethod` object | def get_methods_descriptor(self, class_name, method_name):
"""
Return the specific methods of the class
:param class_name: the class name of the method
:type class_name: string
:param method_name: the name of the method
:type method_name: string
:rtype: None or ... |
Return all methods of a specific class
:param class_name: the class name
:type class_name: string
:rtype: a list with :class:`EncodedMethod` objects | def get_methods_class(self, class_name):
"""
Return all methods of a specific class
:param class_name: the class name
:type class_name: string
:rtype: a list with :class:`EncodedMethod` objects
"""
l = []
for i in self.get_classes():
for j in... |
Return all fields of a specific class
:param class_name: the class name
:type class_name: string
:rtype: a list with :class:`EncodedField` objects | def get_fields_class(self, class_name):
"""
Return all fields of a specific class
:param class_name: the class name
:type class_name: string
:rtype: a list with :class:`EncodedField` objects
"""
l = []
for i in self.get_classes():
for j in i.... |
Return the specific field
:param class_name: the class name of the field
:type class_name: string
:param field_name: the name of the field
:type field_name: string
:param descriptor: the descriptor of the field
:type descriptor: string
:rtype: None or a :class:`... | def get_field_descriptor(self, class_name, field_name, descriptor):
"""
Return the specific field
:param class_name: the class name of the field
:type class_name: string
:param field_name: the name of the field
:type field_name: string
:param descriptor: the desc... |
Return all target strings matched the regex
:param regular_expressions: the python regex
:type regular_expressions: string
:rtype: a list of strings matching the regex expression | def get_regex_strings(self, regular_expressions):
"""
Return all target strings matched the regex
:param regular_expressions: the python regex
:type regular_expressions: string
:rtype: a list of strings matching the regex expression
"""
str_list = []
if ... |
Export classes/methods/fields' names in the python namespace | def create_python_export(self):
"""
Export classes/methods/fields' names in the python namespace
"""
setattr(self, "C", ExportObject())
for _class in self.get_classes():
self._create_python_export_class(_class) |
Disassembles a given offset in the DEX file
:param offset: offset to disassemble in the file (from the beginning of the file)
:type offset: int
:param size:
:type size: | def disassemble(self, offset, size):
"""
Disassembles a given offset in the DEX file
:param offset: offset to disassemble in the file (from the beginning of the file)
:type offset: int
:param size:
:type size:
"""
for i in DCode(
self.CM, ... |
Convert a path such as 'android.support.v4.app.ActivityCompat'
into a string 'Landroid/support/v4/app/ActivityCompat'
so we can change name of a class by d.CLASS_Landroid_support_v4_app_ActivityCompat.set_name(new_name) | def classdot2class(path):
""" Convert a path such as 'android.support.v4.app.ActivityCompat'
into a string 'Landroid/support/v4/app/ActivityCompat'
so we can change name of a class by d.CLASS_Landroid_support_v4_app_ActivityCompat.set_name(new_name)
"""
if path[0] == 'L' and path[-1] == ';':... |
Static method called before creating a XrefDialog
to check if there are xrefs to display
method (optional): method of the class we are looking xref from | def get_xrefs_list(cls, class_item, method=None):
"""Static method called before creating a XrefDialog
to check if there are xrefs to display
method (optional): method of the class we are looking xref from
"""
log.debug("Getting XREF for %s" % class_item)
item = c... |
Helper for get_xrefs_list
element is a ClassDefItem or MethodDefItem
At the end of the function, we lost if we worked on
a class or method but we do not care for now. | def get_xrefs_list_from_element(cls, element):
"""Helper for get_xrefs_list
element is a ClassDefItem or MethodDefItem
At the end of the function, we lost if we worked on
a class or method but we do not care for now.
"""
xref_items = element.XREFfrom.items
... |
Plot the call graph using matplotlib
For larger graphs, this should not be used, as it is very slow
and probably you can not see anything on it.
:param cg: A networkx call graph to plot | def plot(cg):
"""
Plot the call graph using matplotlib
For larger graphs, this should not be used, as it is very slow
and probably you can not see anything on it.
:param cg: A networkx call graph to plot
"""
from androguard.core.analysis.analysis import ExternalMethod
import matplotlib.... |
Wrapper around nx.write_gml | def _write_gml(G, path):
"""
Wrapper around nx.write_gml
"""
import networkx as nx
return nx.write_gml(G, path, stringizer=str) |
Start an interactive shell
:param session: Session file to load
:param filename: File to analyze, can be APK or DEX (or ODEX) | def androlyze_main(session, filename):
"""
Start an interactive shell
:param session: Session file to load
:param filename: File to analyze, can be APK or DEX (or ODEX)
"""
from androguard.core.androconf import ANDROGUARD_VERSION, CONF
from IPython.terminal.embed import InteractiveShellEmbe... |
Decode bytes as MUTF-8
See https://docs.oracle.com/javase/6/docs/api/java/io/DataInput.html#modified-utf-8
for more information
Surrogates will be returned as two 16 bit characters.
:param b: bytes to decode
:rtype: unicode (py2), str (py3) of 16bit chars
:raises: UnicodeDecodeError if string ... | def decode(b):
"""
Decode bytes as MUTF-8
See https://docs.oracle.com/javase/6/docs/api/java/io/DataInput.html#modified-utf-8
for more information
Surrogates will be returned as two 16 bit characters.
:param b: bytes to decode
:rtype: unicode (py2), str (py3) of 16bit chars
:raises: Un... |
Reorganize a String in such a way that surrogates are printable
and lonely surrogates are escaped.
:param s: input string
:return: string with escaped lonely surrogates and 32bit surrogates | def patch_string(s):
"""
Reorganize a String in such a way that surrogates are printable
and lonely surrogates are escaped.
:param s: input string
:return: string with escaped lonely surrogates and 32bit surrogates
"""
res = ''
it = PeekIterator(s)
for c in it:
if (ord(c) >>... |
Convert a string to a escaped ASCII representation including quotation marks
:param s: a string
:return: ASCII escaped string | def string(s):
"""
Convert a string to a escaped ASCII representation including quotation marks
:param s: a string
:return: ASCII escaped string
"""
ret = ['"']
for c in s:
if ' ' <= c < '\x7f':
if c == "'" or c == '"' or c == '\\':
ret.append('\\')
... |
Highlight a block of text. | def highlightBlock(self, string):
""" Highlight a block of text.
"""
prev_data = self.currentBlock().previous().userData()
if prev_data is not None:
self._lexer._saved_state_stack = prev_data.syntax_stack
elif hasattr(self._lexer, '_saved_state_stack'):
de... |
Sets the style to the specified Pygments style. | def set_style(self, style):
""" Sets the style to the specified Pygments style.
"""
style = SolarizedStyle # get_style_by_name(style)
self._style = style
self._clear_caches() |
Sets a CSS stylesheet. The classes in the stylesheet should
correspond to those generated by:
pygmentize -S <style> -f html
Note that 'set_style' and 'set_style_sheet' completely override each
other, i.e. they cannot be used in conjunction. | def set_style_sheet(self, stylesheet):
""" Sets a CSS stylesheet. The classes in the stylesheet should
correspond to those generated by:
pygmentize -S <style> -f html
Note that 'set_style' and 'set_style_sheet' completely override each
other, i.e. they cannot be used in conju... |
Returns a QTextCharFormat for token or None. | def _get_format(self, token):
""" Returns a QTextCharFormat for token or None.
"""
if token in self._formats:
return self._formats[token]
result = self._get_format_from_style(token, self._style)
self._formats[token] = result
return result |
Returns a brush for the color. | def _get_brush(self, color):
""" Returns a brush for the color.
"""
result = self._brushes.get(color)
if result is None:
qcolor = self._get_color(color)
result = QtGui.QBrush(qcolor)
self._brushes[color] = result
return result |
Returns a QColor built from a Pygments color string. | def _get_color(self, color):
""" Returns a QColor built from a Pygments color string.
"""
qcolor = QtGui.QColor()
qcolor.setRgb(int(color[:2], base=16),
int(color[2:4], base=16),
int(color[4:6], base=16))
return qcolor |
Reload completely the sources by asking Androguard
to decompile it again. Useful when:
- an element has been renamed to propagate the info
- the current tab is changed because we do not know what user
did since then, so we need to propagate previous changes as well | def reload_java_sources(self):
"""Reload completely the sources by asking Androguard
to decompile it again. Useful when:
- an element has been renamed to propagate the info
- the current tab is changed because we do not know what user
did since then, so we need t... |
Used to detect when cursor change position and to auto select word
underneath it | def cursor_position_changed(self):
"""Used to detect when cursor change position and to auto select word
underneath it"""
log.debug("cursor_position_changed")
cur = self.textCursor()
log.debug(cur.position())
log.debug(cur.selectedText())
if len(cur.selectedTe... |
Keyboard shortcuts | def keyPressEvent(self, event):
"""Keyboard shortcuts"""
key = event.key()
if key == QtCore.Qt.Key_X:
self.actionXref()
elif key == QtCore.Qt.Key_G:
self.actionGoto()
elif key == QtCore.Qt.Key_X:
self.actionXref()
elif key == QtCore.Qt.... |
Check if there is already a meth_name method in the current class
It is useful before allowing to rename a method to check name does
not already exist. | def method_name_exist(self, meth_name):
"""Check if there is already a meth_name method in the current class
It is useful before allowing to rename a method to check name does
not already exist.
"""
methods = self.current_class.get_methods()
for m in methods:
... |
Check if there is already a field_name field in the current class
It is useful before allowing to rename a field to check name does
not already exist. | def field_name_exist(self, field_name):
"""Check if there is already a field_name field in the current class
It is useful before allowing to rename a field to check name does
not already exist.
"""
fields = self.class_item.get_fields()
for f in fields:
... |
Called back after a user chose a new name for an element. | def renameElement(self, oldname, newname, info):
"""Called back after a user chose a new name for an element.
"""
log.debug("Renaming %s into %s in %s" %
(oldname, newname, self.current_filename))
start, end = info
try:
t = self.doc.binding[st... |
Format a value based on type and data.
By default, no strings are looked up and "<string>" is returned.
You need to define `lookup_string` in order to actually lookup strings from
the string table.
:param _type: The numeric type of the value
:param _data: The numeric data of the value
:param lo... | def format_value(_type, _data, lookup_string=lambda ix: "<string>"):
"""
Format a value based on type and data.
By default, no strings are looked up and "<string>" is returned.
You need to define `lookup_string` in order to actually lookup strings from
the string table.
:param _type: The numeri... |
Return a string containing all resources packages ordered by packagename, locale and type.
:param arscobj: :class:`~ARSCParser`
:return: a string | def get_arsc_info(arscobj):
"""
Return a string containing all resources packages ordered by packagename, locale and type.
:param arscobj: :class:`~ARSCParser`
:return: a string
"""
buff = ""
for package in arscobj.get_packages_names():
buff += package + ":\n"
for locale in ... |
Return the string at the index in the string table
:param idx: index in the string table
:return: str | def getString(self, idx):
"""
Return the string at the index in the string table
:param idx: index in the string table
:return: str
"""
if idx in self._cache:
return self._cache[idx]
if idx < 0 or not self.m_stringOffsets or idx > self.stringCount:
... |
Generic decoding with length check.
The string is decoded from bytes with the given encoding, then the length
of the string is checked.
The string is decoded using the "replace" method.
:param data: bytes
:param encoding: encoding name ("utf-8" or "utf-16")
:param str_le... | def _decode_bytes(data, encoding, str_len):
"""
Generic decoding with length check.
The string is decoded from bytes with the given encoding, then the length
of the string is checked.
The string is decoded using the "replace" method.
:param data: bytes
:param enc... |
Print some information on stdout about the string table | def show(self):
"""
Print some information on stdout about the string table
"""
print("StringBlock(stringsCount=0x%x, "
"stringsOffset=0x%x, "
"stylesCount=0x%x, "
"stylesOffset=0x%x, "
"flags=0x%x"
")" % (self.stringC... |
Returns the current namespace mapping as a dictionary
there are several problems with the map and we try to guess a few
things here:
1) a URI can be mapped by many prefixes, so it is to decide which one to take
2) a prefix might map to an empty string (some packers)
3) uri+pref... | def nsmap(self):
"""
Returns the current namespace mapping as a dictionary
there are several problems with the map and we try to guess a few
things here:
1) a URI can be mapped by many prefixes, so it is to decide which one to take
2) a prefix might map to an empty stri... |
Return the String assosciated with the tag name | def name(self):
"""
Return the String assosciated with the tag name
"""
if self.m_name == -1 or (self.m_event != START_TAG and self.m_event != END_TAG):
return ''
return self.sb[self.m_name] |
Return the String assosicated with the current text | def text(self):
"""
Return the String assosicated with the current text
"""
if self.m_name == -1 or self.m_event != TEXT:
return ''
return self.sb[self.m_name] |
Return the start inside the m_attributes array for a given attribute | def _get_attribute_offset(self, index):
"""
Return the start inside the m_attributes array for a given attribute
"""
if self.m_event != START_TAG:
log.warning("Current event is not START_TAG.")
offset = index * ATTRIBUTE_LENGHT
if offset >= len(self.m_attribu... |
Returns the numeric ID for the namespace URI of an attribute | def getAttributeUri(self, index):
"""
Returns the numeric ID for the namespace URI of an attribute
"""
offset = self._get_attribute_offset(index)
uri = self.m_attributes[offset + ATTRIBUTE_IX_NAMESPACE_URI]
return uri |
This function is only used to look up strings
All other work is done by
:func:`~androguard.core.bytecodes.axml.format_value`
# FIXME should unite those functions
:param index: index of the attribute
:return: | def getAttributeValue(self, index):
"""
This function is only used to look up strings
All other work is done by
:func:`~androguard.core.bytecodes.axml.format_value`
# FIXME should unite those functions
:param index: index of the attribute
:return:
"""
... |
Get the XML as an UTF-8 string
:returns: bytes encoded as UTF-8 | def get_xml(self, pretty=True):
"""
Get the XML as an UTF-8 string
:returns: bytes encoded as UTF-8
"""
return etree.tostring(self.root, encoding="utf-8", pretty_print=pretty) |
Apply some fixes to element named and attribute names.
Try to get conform to:
> Like element names, attribute names are case-sensitive and must start with a letter or underscore.
> The rest of the name can contain letters, digits, hyphens, underscores, and periods.
See: https://msdn.micr... | def _fix_name(self, prefix, name):
"""
Apply some fixes to element named and attribute names.
Try to get conform to:
> Like element names, attribute names are case-sensitive and must start with a letter or underscore.
> The rest of the name can contain letters, digits, hyphens, u... |
Return a cleaned version of a value
according to the specification:
> Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
See https://www.w3.org/TR/xml/#charsets
:param value: a value to clean
:return: the cleaned value | def _fix_value(self, value):
"""
Return a cleaned version of a value
according to the specification:
> Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
See https://www.w3.org/TR/xml/#charsets
:param value: a value to clean
:r... |
Retrieve a list of all available locales in a given packagename.
:param package_name: the package name to get locales of | def get_locales(self, package_name):
"""
Retrieve a list of all available locales in a given packagename.
:param package_name: the package name to get locales of
"""
self._analyse()
return list(self.values[package_name].keys()) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.