Ejemplo 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 ) )
      #FIXME
      buff.read(4) # ?
      self.stringsOffset = SV( '<L', buff.read( 4 ) )
      self.stylesOffset = SV( '<L', buff.read( 4 ) )

      #print self.chunkSize, self.stringCount, self.styleOffsetCount, self.stringsOffset, self.stylesOffset

      self.m_stringOffsets = []

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

      #print self.m_stringOffsets

      if self.styleOffsetCount.get_value() != 0 :
         raise("ooo")
     
      size = self.chunkSize.get_value() - self.stringsOffset.get_value()
      if self.stylesOffset.get_value() != 0 :
         size = self.stylesOffset.get_value() - self.stringsOffset.get_value()
      
      #print size, size % 4
      
      self.m_strings = []
      for i in range(0, size / 4) :
         self.m_strings.append( SV( '<L', buff.read( 4 ) ) )

      if self.stylesOffset.get_value() != 0 :
         raise("ooo")
Ejemplo n.º 2
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, 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 ) ) )
Ejemplo n.º 3
0
    def __init__(self, buff, header):
        self._cache = {}
        self.header = header

        self.stringCount, = unpack('<i', buff.read(4))
        self.styleOffsetCount, = unpack('<i', buff.read(4))
        self.flags, = unpack('<i', buff.read(4))
        self.m_isUTF8 = (self.flags & (1 << 8) != 0)

        self.stringsOffset, = unpack('<i', buff.read(4))
        self.stylesOffset, = unpack('<i', buff.read(4))

        if self.styleOffsetCount == 0 and self.stylesOffset > 0:
            print "Styles Offset given, but styleCount is zero."

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

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

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

        size = self.header.size - self.stringsOffset

        if self.stylesOffset != 0 and self.styleOffsetCount != 0:
            size = self.stylesOffset - self.stringsOffset

        if (size % 4) != 0:
            pass

        self.m_strings = buff.read(size)

        if self.stylesOffset != 0 and self.styleOffsetCount != 0:
            size = self.header.size - self.stylesOffset
            if (size % 4) != 0:
                pass

            for i in range(0, size // 4):
                self.m_styles.append(SV('<i', buff.read(4)))
Ejemplo n.º 4
0
    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, 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
Ejemplo n.º 5
0
class StringBlock :
    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, 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 += unichr( self.getShort(self.m_strings, offset) )
            
            # FIXME
            if data[-1] == "&" :
                data = data[:-1]

            length -= 1

        return data

    def getShort(self, array, offset) :
        value = array[offset/4].get_value()
        if ((offset%4)/2) == 0 :
            return value & 0xFFFF
        else :
            return value >> 16
Ejemplo n.º 6
0
class StringBlock :

	
    ATTRIBUTE_IX_NAMESPACE_URI  = 0
    ATTRIBUTE_IX_NAME           = 1
    ATTRIBUTE_IX_VALUE_STRING   = 2
    ATTRIBUTE_IX_VALUE_TYPE     = 3
    ATTRIBUTE_IX_VALUE_DATA     = 4
    ATTRIBUTE_LENGTH            = 5

    CHUNK_AXML_FILE             = 0x00080003
    CHUNK_RESOURCEIDS           = 0x00080180
    CHUNK_XML_FIRST             = 0x00100100
    CHUNK_XML_START_NAMESPACE   = 0x00100100
    CHUNK_XML_END_NAMESPACE     = 0x00100101
    CHUNK_XML_START_TAG         = 0x00100102
    CHUNK_XML_END_TAG           = 0x00100103
    CHUNK_XML_TEXT              = 0x00100104
    CHUNK_XML_LAST              = 0x00100104

    START_DOCUMENT              = 0
    END_DOCUMENT                = 1
    START_TAG                   = 2
    END_TAG                     = 3
    TEXT                        = 4

    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, 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 += unichr( self.getShort(self.m_strings, offset) )
            
            # FIXME
            if data[-1] == "&" :
                data = data[:-1]

            length -= 1

        return data

    def getShort(self, array, offset) :

        value = array[offset/4].get_value()
        if ((offset%4)/2) == 0 :
            return value & 0xFFFF
        else :
            return value >> 16
Ejemplo n.º 7
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_styleOffsets.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, 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)))
Ejemplo n.º 8
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_styleOffsets.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, 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 += unichr(self.getShort(self.m_strings, offset))

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

            length -= 1

        return data

    def getShort(self, array, offset):
        value = array[offset / 4].get_value()
        if ((offset % 4) / 2) == 0:
            return value & 0xFFFF
        else:
            return value >> 16
Ejemplo n.º 9
0
class StringBlock:
    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, 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 += unichr(self.getShort(self.m_strings, offset))

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

            length -= 1

        return data

    def getShort(self, array, offset):
        value = array[offset / 4].get_value()
        if ((offset % 4) / 2) == 0:
            return value & 0xFFFF
        else:
            return value >> 16
Ejemplo n.º 10
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))
        #FIXME
        buff.read(4)  # ?
        self.stringsOffset = SV('<L', buff.read(4))
        self.stylesOffset = SV('<L', buff.read(4))

        #print self.chunkSize, self.stringCount, self.styleOffsetCount, self.stringsOffset, self.stylesOffset

        self.m_stringOffsets = []

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

        #print self.m_stringOffsets

        if self.styleOffsetCount.get_value() != 0:
            raise ("ooo")

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

        #print size, size % 4

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

        if self.stylesOffset.get_value() != 0:
            raise ("ooo")
Ejemplo n.º 11
0
class StringBlock:
    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))
        #FIXME
        buff.read(4)  # ?
        self.stringsOffset = SV('<L', buff.read(4))
        self.stylesOffset = SV('<L', buff.read(4))

        #print self.chunkSize, self.stringCount, self.styleOffsetCount, self.stringsOffset, self.stylesOffset

        self.m_stringOffsets = []

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

        #print self.m_stringOffsets

        if self.styleOffsetCount.get_value() != 0:
            raise ("ooo")

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

        #print size, size % 4

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

        if self.stylesOffset.get_value() != 0:
            raise ("ooo")

        #print "string", len(self.m_stringOffsets), len(self.m_strings)

        #for i in range(0, len(self.m_stringOffsets)) :
        #   print repr( self.getRaw( i ) )

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

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

        data = ""
        while length > 0:
            offset += 2
            data += pack("<B", self.getShort(self.m_strings, offset))
            length -= 1

        return data

    def getShort(self, array, offset):
        value = array[offset / 4].get_value()
        if (offset % 4) / 2 == 0:
            return value & 0xFFFF
        else:
            return value >> 16
Ejemplo n.º 12
0
class StringBlock :
   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 ) )
      #FIXME
      buff.read(4) # ?
      self.stringsOffset = SV( '<L', buff.read( 4 ) )
      self.stylesOffset = SV( '<L', buff.read( 4 ) )

      #print self.chunkSize, self.stringCount, self.styleOffsetCount, self.stringsOffset, self.stylesOffset

      self.m_stringOffsets = []

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

      #print self.m_stringOffsets

      if self.styleOffsetCount.get_value() != 0 :
         raise("ooo")
     
      size = self.chunkSize.get_value() - self.stringsOffset.get_value()
      if self.stylesOffset.get_value() != 0 :
         size = self.stylesOffset.get_value() - self.stringsOffset.get_value()
      
      #print size, size % 4
      
      self.m_strings = []
      for i in range(0, size / 4) :
         self.m_strings.append( SV( '<L', buff.read( 4 ) ) )

      if self.stylesOffset.get_value() != 0 :
         raise("ooo")

      #print "string", len(self.m_stringOffsets), len(self.m_strings)

      #for i in range(0, len(self.m_stringOffsets)) :
      #   print repr( self.getRaw( i ) )

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

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

      data = ""
      while length > 0 :
         offset += 2
         data += pack( "<B", self.getShort(self.m_strings, offset) )
         length -= 1
     
      return data

   def getShort(self, array, offset) :
      value = array[offset/4].get_value()
      if (offset%4)/2 == 0 :
         return value & 0xFFFF
      else :
         return value >> 16
Ejemplo n.º 13
0
class StringBlock:

    ATTRIBUTE_IX_NAMESPACE_URI = 0
    ATTRIBUTE_IX_NAME = 1
    ATTRIBUTE_IX_VALUE_STRING = 2
    ATTRIBUTE_IX_VALUE_TYPE = 3
    ATTRIBUTE_IX_VALUE_DATA = 4
    ATTRIBUTE_LENGTH = 5

    CHUNK_AXML_FILE = 0x00080003
    CHUNK_RESOURCEIDS = 0x00080180
    CHUNK_XML_FIRST = 0x00100100
    CHUNK_XML_START_NAMESPACE = 0x00100100
    CHUNK_XML_END_NAMESPACE = 0x00100101
    CHUNK_XML_START_TAG = 0x00100102
    CHUNK_XML_END_TAG = 0x00100103
    CHUNK_XML_TEXT = 0x00100104
    CHUNK_XML_LAST = 0x00100104

    START_DOCUMENT = 0
    END_DOCUMENT = 1
    START_TAG = 2
    END_TAG = 3
    TEXT = 4

    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, 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 += unichr(self.getShort(self.m_strings, offset))

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

            length -= 1

        return data

    def getShort(self, array, offset):

        value = array[offset / 4].get_value()
        if ((offset % 4) / 2) == 0:
            return value & 0xFFFF
        else:
            return value >> 16
Ejemplo n.º 14
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, 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 += unichr(self.getShort(self.m_strings, offset))

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

            length -= 1

        return data

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