예제 #1
0
        private async Task <Attribute_> readAttribute()
        {
            int        nsRef     = buffer.getInt();
            int        nameRef   = buffer.getInt();
            Attribute_ attribute = new Attribute_();

            if (nsRef > 0)
            {
                attribute.setNamespace(stringPool.get(nsRef));
            }

            attribute.setName(stringPool.get(nameRef));
            if (attribute.getName().Equals(string.Empty) && resourceMap != null && nameRef < resourceMap.Length)
            {
                // some processed apk file make the string pool value empty, if it is a xmlmap attr.
                attribute.setName(resourceMap[nameRef]);
                //TODO: how to get the namespace of attribute
            }

            int rawValueRef = buffer.getInt();

            if (rawValueRef > 0)
            {
                attribute.setRawValue(stringPool.get(rawValueRef));
            }
            ResourceValue resValue = await ParseUtils.readResValue(buffer, stringPool);

            attribute.setTypedValue(resValue);

            return(attribute);
        }
예제 #2
0
        private async Task <XmlNodeStartTag> readXmlNodeStartTag()
        {
            int             nsRef           = buffer.getInt();
            int             nameRef         = buffer.getInt();
            XmlNodeStartTag xmlNodeStartTag = new XmlNodeStartTag();

            if (nsRef > 0)
            {
                xmlNodeStartTag.setNamespace(stringPool.get(nsRef));
            }
            xmlNodeStartTag.setName(stringPool.get(nameRef));

            // read attributes.
            // attributeStart and attributeSize are always 20 (0x14)
            int attributeStart = await Buffers.readUShort(buffer);

            int attributeSize = await Buffers.readUShort(buffer);

            int attributeCount = await Buffers.readUShort(buffer);

            int idIndex = await Buffers.readUShort(buffer);

            int classIndex = await Buffers.readUShort(buffer);

            int styleIndex = await Buffers.readUShort(buffer);

            // read attributes
            Attributes attributes = new Attributes(attributeCount);

            for (int count = 0; count < attributeCount; count++)
            {
                Attribute_ attribute = await readAttribute();

                if (xmlStreamer != null)
                {
                    string value = attribute.toStringValue(resourceTable, locale);
                    if (intAttributes.Contains(attribute.getName()) && Utils.isNumeric(value))
                    {
                        try
                        {
                            value = getFinalValueAsString(attribute.getName(), value);
                        }
                        catch
                        {
                            //ignore exception
                        }
                    }
                    attribute.setValue(value);
                    attributes.set(count, attribute);
                }
            }
            xmlNodeStartTag.setAttributes(attributes);

            if (xmlStreamer != null)
            {
                xmlStreamer.onStartTag(xmlNodeStartTag);
            }

            return(xmlNodeStartTag);
        }
예제 #3
0
        private void onAttribute(Attribute_ attribute)
        {
            sb.Append(" ");
            string nspace = this.namespaces.getPrefixViaUri(attribute.getNamespace());

            if (nspace == null)
            {
                nspace = attribute.getNamespace();
            }
            if (nspace != null && !nspace.Equals(string.Empty))
            {
                sb.Append(nspace).Append(':');
            }
            string escapedFinalValue = XmlEscaper.escapeXml10(attribute.getValue());

            sb.Append(attribute.getName()).Append('=').Append('"').Append(escapedFinalValue).Append('"');
        }