AxmlParserPY对framework-res.apk反编译失败的修正

来源:互联网 发布:mac系统占用空间大 编辑:程序博客网 时间:2024/06/05 08:48

AXmlPrinter2中存在一样的问题,原因是framework内的xml编译的时候采用宽字符方式生成字符串表,修正如下:

#stringblock.py   

    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.getByte(self.m_strings, offset)
        offset += 1
        isansi = self.getByte(self.m_strings, offset)

        data = ""

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

            else:

                #multibyte

                offset += 1
                data += unichr(self.getByte(self.m_strings, offset))
                

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

            length -= 1
        return data
        
    def getByte(self, array, offset):
        value = array[offset / 4].get_value()
        offset%=4
        if offset == 0:
            return value & 0xFF
        if offset == 1:
            return (value>>8) & 0xFF
        if offset == 2:
            return (value>>16) & 0xFF
        if offset == 3:
            return (value>>24) & 0xFF