Skip to content

Commit

Permalink
Merge pull request #614 from reox/master
Browse files Browse the repository at this point in the history
Fixing GUI Issues, adding documentation
  • Loading branch information
reox committed Jan 28, 2019
2 parents c130e51 + 9699210 commit 0c9ebc1
Show file tree
Hide file tree
Showing 32 changed files with 279 additions and 141 deletions.
42 changes: 28 additions & 14 deletions androguard/core/bytecodes/axml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def show(self):
class AXMLParser(object):
"""
AXMLParser reads through all chunks in the AXML file
and implements a state machone to return information about
and implements a state machine to return information about
the current chunk, which can then be read by :class:`~AXMLPrinter`.
An AXML file is a file which contains multiple chunks of data, defined
Expand Down Expand Up @@ -699,8 +699,8 @@ def nsmap(self):
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
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+prefix mappings might be included several times
4) prefix might be empty
Expand Down Expand Up @@ -731,21 +731,21 @@ def text(self):
def getName(self):
"""
Legacy only!
use :func:`~androguard.core.bytecodes.AXMLParser.name` instead
use :py:attr:`~androguard.core.bytecodes.AXMLParser.name` instead
"""
return self.name

def getText(self):
"""
Legacy only!
use :func:`~androguard.core.bytecodes.AXMLParser.text` instead
use :py:attr:`~androguard.core.bytecodes.AXMLParser.text` instead
"""
return self.text

def getPrefix(self):
"""
Legacy only!
use :func:`~androguard.core.bytecodes.AXMLParser.namespace` instead
use :py:attr:`~androguard.core.bytecodes.AXMLParser.namespace` instead
"""
return self.namespace

Expand Down Expand Up @@ -814,19 +814,30 @@ def getAttributeName(self, index):
return res

def getAttributeValueType(self, index):
"""
Return the type of the attribute at the given index
:param index: index of the attribute
"""
offset = self._get_attribute_offset(index)
return self.m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE]

def getAttributeValueData(self, index):
"""
Return the data of the attribute at the given index
:param index: index of the attribute
"""
offset = self._get_attribute_offset(index)
return self.m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA]

def getAttributeValue(self, index):
"""
This function is only used to look up strings
All other work is made by format_value
All other work is done by
:func:`~androguard.core.bytecodes.axml.format_value`
# FIXME should unite those functions
:param index:
:param index: index of the attribute
:return:
"""
offset = self._get_attribute_offset(index)
Expand Down Expand Up @@ -967,24 +978,25 @@ def __init__(self, raw_buff):

def get_buff(self):
"""
Returns the raw XML file
:return: bytes, encoded as UTF-8
Returns the raw XML file without prettification applied.
:returns: bytes, encoded as UTF-8
"""
return self.get_xml(pretty=False)

def get_xml(self, pretty=True):
"""
Get the XML as an UTF-8 string
:return: bytes encoded as UTF-8
:returns: bytes encoded as UTF-8
"""
return etree.tostring(self.root, encoding="utf-8", pretty_print=pretty)

def get_xml_obj(self):
"""
Get the XML as an ElementTree object
:return: :class:`~lxml.etree.Element`
:returns: :class:`lxml.etree.Element`
"""
return self.root

Expand All @@ -1005,7 +1017,7 @@ def is_packed(self):
some broken version of a tool.
Some file corruption might also be appear to be a packed file.
:return: True if packer detected, False otherwise
:returns: True if packer detected, False otherwise
"""
return self.packerwarning

Expand Down Expand Up @@ -2234,7 +2246,9 @@ def get_language_and_region(self):

def get_config_name_friendly(self):
"""
Here for legacy reasons...
Here for legacy reasons.
use :meth:`~get_qualifier` instead.
"""
return self.get_qualifier()

Expand Down
28 changes: 23 additions & 5 deletions androguard/core/bytecodes/dvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4137,7 +4137,10 @@ def get_formatted_operands(self):
return None

def get_hex(self):
s = binascii.hexlify(self.get_raw()).decode("ascii")
"""
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))


Expand Down Expand Up @@ -4247,7 +4250,12 @@ def get_output(self, idx=-1):
return buff

def get_operands(self, idx=-1):
return [(OPERAND_RAW, repr(self.get_data()))]
# FIXME: not sure of binascii is the right choise here,
# but before it was repr(), which lead to weird outputs of bytearrays
if isinstance(self.get_data(), bytearray):
return [(OPERAND_RAW, binascii.hexlify(self.get_data()).decode('ascii'))]
else:
return [(OPERAND_RAW, repr(self.get_data()))]

def get_formatted_operands(self):
return None
Expand Down Expand Up @@ -4291,7 +4299,11 @@ def get_raw(self):
"=I", self.size) + self.data

def get_hex(self):
s = binascii.hexlify(self.get_raw())
"""
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))


Expand Down Expand Up @@ -4419,7 +4431,10 @@ def get_raw(self):
for i in self.targets)

def get_hex(self):
s = binascii.hexlify(self.get_raw())
"""
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))


Expand Down Expand Up @@ -4552,7 +4567,10 @@ def get_raw(self):
"=i", self.first_key) + b''.join(pack("=l", i) for i in self.targets)

def get_hex(self):
s = binascii.hexlify(self.get_raw())
"""
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))


Expand Down
15 changes: 5 additions & 10 deletions androguard/gui/BinViewMode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .TextDecorators import *
from .ViewMode import *
from .cemu import *
from . import TextSelection


class BinViewMode(ViewMode):
Expand Down Expand Up @@ -75,7 +76,6 @@ def cache(self):
pix = QtGui.QImage(self.width, self.height, QtGui.QImage.Format_ARGB32)
self.scrollPages(1, cachePix=pix, pageOffset=i)
self.Paints[self.dataModel.getPageOffset(i)] = pix
# print 'cache'

def _getNewPixmap(self, width, height):
return QtGui.QPixmap(width, height)
Expand Down Expand Up @@ -129,20 +129,19 @@ def draw(self, refresh=False, row=0, howMany=0):
if self.dataModel.getOffset() in self.Paints:
self.refresh = False
self.qpix = QtGui.QPixmap(self.Paints[self.dataModel.getOffset()])
# print 'hit'
self.drawAdditionals()
return

if self.refresh or refresh:
qp = QtGui.QPainter()
qp.begin(self.qpix)
# start = time()
start = time()
if not howMany:
howMany = self.ROWS

self.drawTextMode(qp, row=row, howMany=howMany)
# end = time() - start
# print 'Time ' + str(end)
end = time() - start
log.debug('draw Time ' + str(end))
self.refresh = False
qp.end()

Expand All @@ -154,7 +153,7 @@ def draw2(self, qp, refresh=False):
start = time()
self.drawTextMode(qp, howMany=self.ROWS)
end = time() - start
# print 'Time ' + str(end)
log.debug('draw2 Time ' + str(end))
qp = QtGui.QPainter()
qp.begin(self.qpix)

Expand Down Expand Up @@ -296,10 +295,6 @@ def scroll_v(self, dy, cachePix=None, pageOffset=None):

end = time() - start

# print end
# sys.exit()


def scroll(self, dx, dy, cachePix=None, pageOffset=None):
if not cachePix:
if self.dataModel.getOffset() in self.Paints:
Expand Down
12 changes: 8 additions & 4 deletions androguard/gui/DataModel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import mmap
Expand Down Expand Up @@ -30,7 +29,7 @@ def dataOffset(self):

@dataOffset.setter
def dataOffset(self, value):
print("DATA OFFSET", value)
log.debug("DATA OFFSET %s", value)
self._lastOffset = self._dataOffset
self._dataOffset = value

Expand Down Expand Up @@ -306,7 +305,6 @@ def size(self):

class ApkModel(DataModel):
def __init__(self, apkobj):
print(apkobj)
self._filename = str(apkobj)
self.raw = apkobj.get_raw()
self.data = MyByte(self.raw)
Expand All @@ -331,9 +329,15 @@ def size(self):


class DexClassModel(DataModel):
def __init__(self, current_class):
def __init__(self, current_class, dx):
"""
:param current_class: a ClassDefItem
:param dx: a Analysis object
"""
self.current_class = current_class
self._filename = current_class.get_name()
self.dx = dx

raw = self.GetRawData(current_class)
super(DexClassModel, self).__init__(raw)
Expand Down

0 comments on commit 0c9ebc1

Please sign in to comment.