public void onStartTag(XmlNodeStartTag xmlNodeStartTag) { foreach (XmlStreamer xmlStreamer in xmlStreamers) { xmlStreamer.onStartTag(xmlNodeStartTag); } }
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); }
public void onStartTag(XmlNodeStartTag xmlNodeStartTag) { if (isLastStartTag) { sb.Append(">\n"); } appendShift(shift++); sb.Append('<'); if (xmlNodeStartTag.getNamespace() != null) { string prefix = namespaces.getPrefixViaUri(xmlNodeStartTag.getNamespace()); if (prefix != null) { sb.Append(prefix).Append(":"); } else { sb.Append(xmlNodeStartTag.getNamespace()).Append(":"); } } sb.Append(xmlNodeStartTag.getName()); List <XmlNamespaces.XmlNamespace> nps = namespaces.consumeNameSpaces(); //if (!nps.isEmpty()) if (nps.Count != 0) { foreach (XmlNamespaces.XmlNamespace np in nps) { sb.Append(" xmlns:").Append(np.getPrefix()).Append("=\"").Append(np.getUri()).Append("\""); } } isLastStartTag = true; foreach (Attribute_ attribute in xmlNodeStartTag.getAttributes().value()) { onAttribute(attribute); } }
/** * Parse binary xml. */ public async Task parse() { ChunkHeader chunkHeader = await readChunkHeader(); if (chunkHeader == null) { return; } if (chunkHeader.getChunkType() != ChunkType.XML && chunkHeader.getChunkType() != ChunkType.NULL) { // notice that some apk mark xml header type as 0, really weird // see https://github.com/clearthesky/apk-parser/issues/49#issuecomment-256852727 return; } // read string pool chunk chunkHeader = await readChunkHeader(); if (chunkHeader == null) { return; } ParseUtils.checkChunkType(ChunkType.STRING_POOL, chunkHeader.getChunkType()); stringPool = await ParseUtils.readStringPool(buffer, (StringPoolHeader)chunkHeader); // read on chunk, check if it was an optional XMLResourceMap chunk chunkHeader = await readChunkHeader(); if (chunkHeader == null) { return; } if (chunkHeader.getChunkType() == ChunkType.XML_RESOURCE_MAP) { long[] resourceIds = readXmlResourceMap((XmlResourceMapHeader)chunkHeader); resourceMap = new string[resourceIds.Length]; for (int i = 0; i < resourceIds.Length; i++) { resourceMap[i] = await Attribute_.AttrIds.getString(resourceIds[i]); } chunkHeader = await readChunkHeader(); } while (chunkHeader != null) { /*if (chunkHeader.chunkType == ChunkType.XML_END_NAMESPACE) { * break; * }*/ long beginPos = buffer.position(); switch (chunkHeader.getChunkType()) { case ChunkType.XML_END_NAMESPACE: XmlNamespaceEndTag xmlNamespaceEndTag = readXmlNamespaceEndTag(); xmlStreamer.onNamespaceEnd(xmlNamespaceEndTag); break; case ChunkType.XML_START_NAMESPACE: XmlNamespaceStartTag namespaceStartTag = readXmlNamespaceStartTag(); xmlStreamer.onNamespaceStart(namespaceStartTag); break; case ChunkType.XML_START_ELEMENT: XmlNodeStartTag xmlNodeStartTag = await readXmlNodeStartTag(); break; case ChunkType.XML_END_ELEMENT: XmlNodeEndTag xmlNodeEndTag = readXmlNodeEndTag(); break; case ChunkType.XML_CDATA: XmlCData xmlCData = await readXmlCData(); break; default: if (chunkHeader.getChunkType() >= ChunkType.XML_FIRST_CHUNK && chunkHeader.getChunkType() <= ChunkType.XML_LAST_CHUNK) { Buffers.skip(buffer, chunkHeader.getBodySize()); } else { throw new ParserException("Unexpected chunk type:" + chunkHeader.getChunkType()); } break; } buffer.position((int)(beginPos + chunkHeader.getBodySize())); chunkHeader = await readChunkHeader(); } }
public void onStartTag(XmlNodeStartTag xmlNodeStartTag) { Attributes attributes = xmlNodeStartTag.getAttributes(); switch (xmlNodeStartTag.getName()) { case "application": string label = attributes.get("label"); if (label != null) { apkMeta.setLabel(label); } string icon = attributes.get("icon"); if (icon != null) { apkMeta.setIcon(icon); } break; case "manifest": apkMeta.setPackageName(attributes.get("package")); apkMeta.setVersionName(attributes.get("versionName")); apkMeta.setVersionCode(attributes.getLong("versionCode")); string installLocation = attributes.get("installLocation"); if (installLocation != null) { apkMeta.setInstallLocation(installLocation); } break; case "uses-sdk": apkMeta.setMinSdkVersion(attributes.get("minSdkVersion")); apkMeta.setTargetSdkVersion(attributes.get("targetSdkVersion")); apkMeta.setMaxSdkVersion(attributes.get("maxSdkVersion")); break; case "supports-screens": apkMeta.setAnyDensity(attributes.getBoolean("anyDensity", false)); apkMeta.setSmallScreens(attributes.getBoolean("smallScreens", false)); apkMeta.setNormalScreens(attributes.getBoolean("normalScreens", false)); apkMeta.setLargeScreens(attributes.getBoolean("largeScreens", false)); break; case "uses-feature": string name = attributes.get("name"); bool required = attributes.getBoolean("required", false); if (name != null) { UseFeature useFeature = new UseFeature(); useFeature.setName(name); useFeature.setRequired(required); apkMeta.addUseFeatures(useFeature); } else { int gl = attributes.getInt("glEsVersion"); if (gl != -1) { int v = gl; GlEsVersion glEsVersion = new GlEsVersion(); glEsVersion.setMajor(v >> 16); glEsVersion.setMinor(v & 0xffff); glEsVersion.setRequired(required); apkMeta.setGlEsVersion(glEsVersion); } } break; case "uses-permission": apkMeta.addUsesPermission(attributes.get("name")); break; case "permission": Permission permission = new Permission(); permission.setName(attributes.get("name")); permission.setLabel(attributes.get("label")); permission.setIcon(attributes.get("icon")); permission.setGroup(attributes.get("group")); permission.setDescription(attributes.get("description")); string protectionLevel = attributes.get("android:protectionLevel"); if (protectionLevel != null) { permission.setProtectionLevel(protectionLevel); } apkMeta.addPermission(permission); break; } tagStack[depth++] = xmlNodeStartTag.getName(); }