Esempio n. 1
0
    def __init__(self, buff):
        buff.read(4)

        self.chunkSize = SV('<L', buff.read(4))
        self.stringCount = SV('<L', buff.read(4))
        self.styleOffsetCount = SV('<L', buff.read(4))

        # unused value ?
        buff.read(4) # ?

        self.stringsOffset = SV('<L', buff.read(4))
        self.stylesOffset = SV('<L', buff.read(4))

        self.m_stringOffsets = []
        self.m_styleOffsets = []
        self.m_strings = []
        self.m_styles = []

        for i in range(0, self.stringCount.get_value()):
            self.m_stringOffsets.append(SV('<L', buff.read(4)))

        for i in range(0, self.styleOffsetCount.get_value()):
            self.m_stylesOffsets.append(SV('<L', buff.read(4)))

        size = self.chunkSize.get_value() - self.stringsOffset.get_value()
        if self.stylesOffset.get_value() != 0:
            size = self.stylesOffset.get_value() - self.stringsOffset.get_value()

        # FIXME
        if (size % 4) != 0:
            pass

        for i in range(0, int(size / 4)):
            self.m_strings.append(SV('=L', buff.read(4)))

        if self.stylesOffset.get_value() != 0:
            size = self.chunkSize.get_value() - self.stringsOffset.get_value()

            # FIXME
            if (size % 4) != 0:
                pass

            for i in range(0, size / 4):
                self.m_styles.append(SV('=L', buff.read(4)))
Esempio n. 2
0
class StringBlock:
    """
    axml format translated from:
    http://code.google.com/p/android4me/source/browse/src/android/content/res/AXmlResourceParser.java
    """
    def __init__(self, buff):
        buff.read(4)

        self.chunkSize = SV('<L', buff.read(4))
        self.stringCount = SV('<L', buff.read(4))
        self.styleOffsetCount = SV('<L', buff.read(4))

        # unused value ?
        buff.read(4) # ?

        self.stringsOffset = SV('<L', buff.read(4))
        self.stylesOffset = SV('<L', buff.read(4))

        self.m_stringOffsets = []
        self.m_styleOffsets = []
        self.m_strings = []
        self.m_styles = []

        for i in range(0, self.stringCount.get_value()):
            self.m_stringOffsets.append(SV('<L', buff.read(4)))

        for i in range(0, self.styleOffsetCount.get_value()):
            self.m_stylesOffsets.append(SV('<L', buff.read(4)))

        size = self.chunkSize.get_value() - self.stringsOffset.get_value()
        if self.stylesOffset.get_value() != 0:
            size = self.stylesOffset.get_value() - self.stringsOffset.get_value()

        # FIXME
        if (size % 4) != 0:
            pass

        for i in range(0, int(size / 4)):
            self.m_strings.append(SV('=L', buff.read(4)))

        if self.stylesOffset.get_value() != 0:
            size = self.chunkSize.get_value() - self.stringsOffset.get_value()

            # FIXME
            if (size % 4) != 0:
                pass

            for i in range(0, size / 4):
                self.m_styles.append(SV('=L', buff.read(4)))

    def getRaw(self, idx):
        if idx < 0 or self.m_stringOffsets == [] or idx >= len(self.m_stringOffsets):
            return None

        offset = self.m_stringOffsets[ idx ].get_value()
        length = self.getShort(self.m_strings, offset)

        data = ""

        while length > 0:
            offset += 2
            # Unicode character
            data += chr(self.getShort(self.m_strings, offset))

            # FIXME
            if data[-1] == "&":
                data = data[:-1]

            length -= 1

        return data

    def getShort(self, array, offset):
        value = array[int(offset / 4)].get_value()
        if (int((offset % 4)) / 2) == 0:
            return value & 0xFFFF
        else:
            return value >> 16
Esempio n. 3
0
class StringBlock:
    """
    axml format translated from:
    http://code.google.com/p/android4me/source/browse/src/android/content/res/AXmlResourceParser.java
    """
    def __init__(self, buff):
        buff.read(4)

        self.chunkSize = SV('<L', buff.read(4))
        self.stringCount = SV('<L', buff.read(4))
        self.styleOffsetCount = SV('<L', buff.read(4))

        # unused value ?
        buff.read(4)  # ?

        self.stringsOffset = SV('<L', buff.read(4))
        self.stylesOffset = SV('<L', buff.read(4))

        self.m_stringOffsets = []
        self.m_styleOffsets = []
        self.m_strings = []
        self.m_styles = []

        for i in range(0, self.stringCount.get_value()):
            self.m_stringOffsets.append(SV('<L', buff.read(4)))

        for i in range(0, self.styleOffsetCount.get_value()):
            self.m_stylesOffsets.append(SV('<L', buff.read(4)))

        size = self.chunkSize.get_value() - self.stringsOffset.get_value()
        if self.stylesOffset.get_value() != 0:
            size = self.stylesOffset.get_value(
            ) - self.stringsOffset.get_value()

        # FIXME
        if (size % 4) != 0:
            pass

        for i in range(0, int(size / 4)):
            self.m_strings.append(SV('=L', buff.read(4)))

        if self.stylesOffset.get_value() != 0:
            size = self.chunkSize.get_value() - self.stringsOffset.get_value()

            # FIXME
            if (size % 4) != 0:
                pass

            for i in range(0, size / 4):
                self.m_styles.append(SV('=L', buff.read(4)))

    def getRaw(self, idx):
        if idx < 0 or self.m_stringOffsets == [] or idx >= len(
                self.m_stringOffsets):
            return None

        offset = self.m_stringOffsets[idx].get_value()
        length = self.getShort(self.m_strings, offset)

        data = ""

        while length > 0:
            offset += 2
            # Unicode character
            data += chr(self.getShort(self.m_strings, offset))

            # FIXME
            if data[-1] == "&":
                data = data[:-1]

            length -= 1

        return data

    def getShort(self, array, offset):
        value = array[int(offset / 4)].get_value()
        if (int((offset % 4)) / 2) == 0:
            return value & 0xFFFF
        else:
            return value >> 16
Esempio n. 4
0
    def __init__(self, buff):
        buff.read(4)

        self.chunkSize = SV('<L', buff.read(4))
        self.stringCount = SV('<L', buff.read(4))
        self.styleOffsetCount = SV('<L', buff.read(4))

        # unused value ?
        buff.read(4)  # ?

        self.stringsOffset = SV('<L', buff.read(4))
        self.stylesOffset = SV('<L', buff.read(4))

        self.m_stringOffsets = []
        self.m_styleOffsets = []
        self.m_strings = []
        self.m_styles = []

        for i in range(0, self.stringCount.get_value()):
            self.m_stringOffsets.append(SV('<L', buff.read(4)))

        for i in range(0, self.styleOffsetCount.get_value()):
            self.m_stylesOffsets.append(SV('<L', buff.read(4)))

        size = self.chunkSize.get_value() - self.stringsOffset.get_value()
        if self.stylesOffset.get_value() != 0:
            size = self.stylesOffset.get_value(
            ) - self.stringsOffset.get_value()

        # FIXME
        if (size % 4) != 0:
            pass

        for i in range(0, int(size / 4)):
            self.m_strings.append(SV('=L', buff.read(4)))

        if self.stylesOffset.get_value() != 0:
            size = self.chunkSize.get_value() - self.stringsOffset.get_value()

            # FIXME
            if (size % 4) != 0:
                pass

            for i in range(0, size / 4):
                self.m_styles.append(SV('=L', buff.read(4)))
    def doNext(self):
        if self.m_event == tc.END_DOCUMENT:
            return

        event = self.m_event

        self.reset()

        while 1:
            chunkType = -1

            # Fake END_DOCUMENT event.
            if event == tc.END_TAG:
                pass

            # START_DOCUMENT
            if event == tc.START_DOCUMENT:
                chunkType = tc.CHUNK_XML_START_TAG
            else:
                if self.buff.end() == True:
                    self.m_event = tc.END_DOCUMENT
                    break
                chunkType = SV('<L', self.buff.read(4)).get_value()

            if chunkType == tc.CHUNK_RESOURCEIDS:
                chunkSize = SV('<L', self.buff.read(4)).get_value()
                # FIXME
                if chunkSize < 8 or chunkSize % 4 != 0:
                    raise ("ooo")

                for i in range(0, int(chunkSize / 4 - 2)):
                    self.m_resourceIDs.append(SV('<L', self.buff.read(4)))

                continue

            # FIXME
            if chunkType < tc.CHUNK_XML_FIRST or chunkType > tc.CHUNK_XML_LAST:
                raise ("ooo")

            # Fake START_DOCUMENT event.
            if chunkType == tc.CHUNK_XML_START_TAG and event == -1:
                self.m_event = tc.START_DOCUMENT
                break

            self.buff.read(4)  #/*chunkSize*/
            lineNumber = SV('<L', self.buff.read(4)).get_value()
            self.buff.read(4)  #0xFFFFFFFF

            if chunkType == tc.CHUNK_XML_START_NAMESPACE or chunkType == tc.CHUNK_XML_END_NAMESPACE:
                if chunkType == tc.CHUNK_XML_START_NAMESPACE:
                    prefix = SV('<L', self.buff.read(4)).get_value()
                    uri = SV('<L', self.buff.read(4)).get_value()

                    self.m_prefixuri[prefix] = uri
                    self.m_uriprefix[uri] = prefix
                    self.m_prefixuriL.append((prefix, uri))
                else:
                    self.buff.read(4)
                    self.buff.read(4)
                    (prefix, uri) = self.m_prefixuriL.pop()
                    #del self.m_prefixuri[ prefix ]
                    #del self.m_uriprefix[ uri ]

                continue

            self.m_lineNumber = lineNumber

            if chunkType == tc.CHUNK_XML_START_TAG:
                self.m_namespaceUri = SV('<L', self.buff.read(4)).get_value()
                self.m_name = SV('<L', self.buff.read(4)).get_value()

                # FIXME
                self.buff.read(4)  #flags

                attributeCount = SV('<L', self.buff.read(4)).get_value()
                self.m_idAttribute = (attributeCount >> 16) - 1
                attributeCount = attributeCount & 0xFFFF
                self.m_classAttribute = SV('<L', self.buff.read(4)).get_value()
                self.m_styleAttribute = (self.m_classAttribute >> 16) - 1

                self.m_classAttribute = (self.m_classAttribute & 0xFFFF) - 1

                for i in range(0, attributeCount * tc.ATTRIBUTE_LENGTH):
                    self.m_attributes.append(
                        SV('<L', self.buff.read(4)).get_value())

                for i in range(tc.ATTRIBUTE_IX_VALUE_TYPE,
                               len(self.m_attributes), tc.ATTRIBUTE_LENGTH):
                    self.m_attributes[i] = (self.m_attributes[i] >> 24)

                self.m_event = tc.START_TAG
                break

            if chunkType == tc.CHUNK_XML_END_TAG:
                self.m_namespaceUri = SV('<L', self.buff.read(4)).get_value()
                self.m_name = SV('<L', self.buff.read(4)).get_value()
                self.m_event = tc.END_TAG
                break

            if chunkType == tc.CHUNK_XML_TEXT:
                self.m_name = SV('<L', self.buff.read(4)).get_value()

                # FIXME
                self.buff.read(4)  #?
                self.buff.read(4)  #?

                self.m_event = tc.TEXT
                break