android.content.res.AXmlResourceParser Java Examples

The following examples show how to use android.content.res.AXmlResourceParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidXmlConvertor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(AXmlResourceParser parser, int index) {
	int type = parser.getAttributeValueType(index);
	int data = parser.getAttributeValueData(index);

	if (type == TypedValue.TYPE_STRING) {
		return parser.getAttributeValue(index);
	}
	if (type == TypedValue.TYPE_ATTRIBUTE) {
		return String.format("?%s%08X", getPackage(data), data);
	}
	if (type == TypedValue.TYPE_REFERENCE) {
		return String.format("@%s%08X", getPackage(data), data);
	}
	if (type == TypedValue.TYPE_FLOAT) {
		return String.valueOf(Float.intBitsToFloat(data));
	}
	if (type == TypedValue.TYPE_INT_HEX) {
		return String.format("0x%08X", data);
	}
	if (type == TypedValue.TYPE_INT_BOOLEAN) {
		return data == 0 ? "false" : "true";
	}
	if (type == TypedValue.TYPE_DIMENSION) {
		return Float.toString(complexToFloat(data)) +
			DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type == TypedValue.TYPE_FRACTION) {
		return Float.toString(complexToFloat(data)) +
			FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
		return String.format("#%08X", data);
	}
	if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
		return String.valueOf(data);
	}
	return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example #2
Source File: AXMLPrinter.java    From LibScout with Apache License 2.0 5 votes vote down vote up
public static String getAttributeValue(AXmlResourceParser parser,int index) {
	int type=parser.getAttributeValueType(index);
	int data=parser.getAttributeValueData(index);
	if (type==TypedValue.TYPE_STRING) {
		return parser.getAttributeValue(index);
	}
	if (type==TypedValue.TYPE_ATTRIBUTE) {
		return String.format("?%s%08X",getPackage(data),data);
	}
	if (type==TypedValue.TYPE_REFERENCE) {
		return String.format("@%s%08X",getPackage(data),data);
	}
	if (type==TypedValue.TYPE_FLOAT) {
		return String.valueOf(Float.intBitsToFloat(data));
	}
	if (type==TypedValue.TYPE_INT_HEX) {
		return String.format("0x%08X",data);
	}
	if (type==TypedValue.TYPE_INT_BOOLEAN) {
		return data!=0?"true":"false";
	}
	if (type==TypedValue.TYPE_DIMENSION) {
		return Float.toString(complexToFloat(data))+
			DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type==TypedValue.TYPE_FRACTION) {
		return Float.toString(complexToFloat(data))+
			FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type>=TypedValue.TYPE_FIRST_COLOR_INT && type<=TypedValue.TYPE_LAST_COLOR_INT) {
		return String.format("#%08X",data);
	}
	if (type>=TypedValue.TYPE_FIRST_INT && type<=TypedValue.TYPE_LAST_INT) {
		return String.valueOf(data);
	}
	return String.format("<0x%X, type 0x%02X>",data,type);
}
 
Example #3
Source File: ResignerLogic.java    From apkReSign with Apache License 2.0 5 votes vote down vote up
private static String getAttributeValue(AXmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data))
                + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data))
                + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT
            && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
Example #4
Source File: AndroidXmlConvertor.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public static void convert(InputStream is, PrintWriter out, TaskMonitor monitor)
		throws IOException, CancelledException {

	monitor.setMessage("Converting Android Binary XML to Text...");

	AXmlResourceParser parser = new AXmlResourceParser();
	parser.open(is);

	try {
		int indent = -1;
		int type;
		while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
			monitor.checkCanceled();

			StringBuffer buffer = new StringBuffer();
			switch (type) {
				case XmlPullParser.START_DOCUMENT:
					buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
					buffer.append("\n");
					break;
				case XmlPullParser.START_TAG: {
					++indent;

					buffer.append(StringUtilities.pad("", '\t', indent));
					buffer.append("<");
					buffer.append(getNamespacePrefix(parser.getPrefix()));
					buffer.append(parser.getName());
					buffer.append("\n");

					int namespaceCountBefore = parser.getNamespaceCount(parser.getDepth() - 1);
					int namespaceCount = parser.getNamespaceCount(parser.getDepth());

					++indent;

					for (int i = namespaceCountBefore; i != namespaceCount; ++i) {
						buffer.append(StringUtilities.pad("", '\t', indent));
						buffer.append("xmlns:");
						buffer.append(parser.getNamespacePrefix(i));
						buffer.append("=");
						buffer.append("\"");
						buffer.append(parser.getNamespaceUri(i));
						buffer.append("\"");
						buffer.append("\n");
					}

					for (int i = 0; i < parser.getAttributeCount(); ++i) {
						buffer.append(StringUtilities.pad("", '\t', indent));
						buffer.append(getNamespacePrefix(parser.getAttributePrefix(i)));
						buffer.append(parser.getAttributeName(i));
						buffer.append("=");
						buffer.append("\"");
						buffer.append(getAttributeValue(parser, i));
						buffer.append("\"");
						buffer.append("\n");
					}

					buffer.append(StringUtilities.pad("", '\t', indent));
					buffer.append(">");
					buffer.append("\n");

					--indent;
				}
					break;
				case XmlPullParser.END_TAG: {
					buffer.append(StringUtilities.pad("", '\t', indent));
					buffer.append("<");
					buffer.append("/");
					buffer.append(getNamespacePrefix(parser.getPrefix()));
					buffer.append(parser.getName());
					buffer.append(">");
					buffer.append("\n");
					--indent;
				}
					break;
				case XmlPullParser.TEXT: {
					buffer.append(StringUtilities.pad("", '\t', indent));
					buffer.append(parser.getText());
					buffer.append("\n");
				}
			}

			out.print(buffer.toString());
		}
		out.println();
	}
	catch (XmlPullParserException | ArrayIndexOutOfBoundsException e) {
		throw new IOException("Failed to read AXML file", e);
	}
	finally {
		parser.close();
	}
}
 
Example #5
Source File: ProcessManifest.java    From LibScout with Apache License 2.0 4 votes vote down vote up
private String getAttributeValue(AXmlResourceParser parser, String attributeName) {
	for (int i = 0; i < parser.getAttributeCount(); i++)
		if (parser.getAttributeName(i).equals(attributeName))
			return AXMLPrinter.getAttributeValue(parser, i);
	return "";
}
 
Example #6
Source File: ResignerLogic.java    From apkReSign with Apache License 2.0 4 votes vote down vote up
public static String AXMLToXML(byte[] axml) throws Exception {
    AXmlResourceParser parser = new AXmlResourceParser();
    ByteArrayInputStream bais = new ByteArrayInputStream(axml);
    parser.open(bais);
    StringBuilder indent = new StringBuilder(10);
    StringBuilder output = new StringBuilder(axml.length * 2);
    final String indentStep = "   ";

    while (true) {
        int type = parser.next();
        if (type == XmlPullParser.END_DOCUMENT) {
            break;
        }
        switch (type) {
            case XmlPullParser.START_DOCUMENT: {
                output.append(String
                        .format("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
                output.append("\n");
                break;
            }
            case XmlPullParser.START_TAG: {
                output.append(String.format("%s<%s%s", indent,
                        getNamespacePrefix(parser.getPrefix()),
                        parser.getName()));
                output.append("\n");
                indent.append(indentStep);

                int namespaceCountBefore = parser.getNamespaceCount(parser
                        .getDepth() - 1);
                int namespaceCount = parser
                        .getNamespaceCount(parser.getDepth());
                for (int i = namespaceCountBefore; i != namespaceCount; ++i) {
                    output.append(String.format("%sxmlns:%s=\"%s\"", indent,
                            parser.getNamespacePrefix(i),
                            parser.getNamespaceUri(i)));
                    output.append("\n");
                }

                for (int i = 0; i != parser.getAttributeCount(); ++i) {
                    output.append(String.format("%s%s%s=\"%s\"", indent,
                            getNamespacePrefix(parser.getAttributePrefix(i)),
                            parser.getAttributeName(i),
                            getAttributeValue(parser, i)));
                    output.append("\n");
                }
                output.append(String.format("%s>", indent));
                output.append("\n");
                break;
            }
            case XmlPullParser.END_TAG: {
                indent.setLength(indent.length() - indentStep.length());
                output.append(String.format("%s</%s%s>", indent,
                        getNamespacePrefix(parser.getPrefix()),
                        parser.getName()));
                output.append("\n");
                break;
            }
            case XmlPullParser.TEXT: {
                output.append(String.format("%s%s", indent, parser.getText()));
                output.append("\n");
                break;
            }
        }
    }
    return output.toString();
}