Java 类android.content.res.AXmlResourceParser 实例源码

项目:ACDD    文件:PackageLite.java   
public static PackageLite parse(String apkPath) {
    ZipFile file = null;

    StringBuilder xmlSb = new StringBuilder(100);
    try {
        File apkFile = new File(apkPath);
        file = new ZipFile(apkFile, ZipFile.OPEN_READ);
        ZipEntry entry = file.getEntry(DEFAULT_XML);

        AXmlResourceParser parser=new AXmlResourceParser();
        parser.open(file.getInputStream(entry));
        PackageLite packageLite=new PackageLite();
        packageLite.apkMD5= ACDDFileUtils.getMD5(apkPath);
        packageLite.size=apkFile.length();
        packageLite.checkNativeLibs(file);
        packageLite.parse(parser);
        //System.err.println(packageLite.getBundleInfo().toString());
        file.close();
        return packageLite;
        //parser.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:Flashtool    文件:APKUtility.java   
public static String getPackageName(String apkname) throws Exception {
    ZipInputStream inStream = new ZipInputStream(new FileInputStream(apkname));
       ZipEntry entry;
       while (((entry = inStream.getNextEntry()) != null)) {
        if (entry.getName().equals("AndroidManifest.xml")) {
            AXmlResourceParser parser=new AXmlResourceParser();
            parser.open(inStream);
            while (true) {
                int type=parser.next();
                if (type==XmlPullParser.START_TAG) {
                    for (int i=0;i!=parser.getAttributeCount();++i) {
                        if (parser.getAttributeName(i).equals("package"))
                            return parser.getAttributeValue(i);
                    }
                    break;
                }
            }
            break;
        }
       }
       return "";
}
项目:LibScout    文件:AXMLPrinter.java   
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);
}
项目:ACDD    文件:AXMLPrinter.java   
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);
}
项目:Android-GetAPKInfo    文件:AXMLPrinter.java   
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);
}
项目:apkanalysis    文件:AXmlNode.java   
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);
    }
项目:apkReSign    文件:ResignerLogic.java   
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);
}
项目:semdroid    文件:AXMLPrinter.java   
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);
}
项目:LibScout    文件:ProcessManifest.java   
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 "";
}
项目:ACDD    文件:AXMLPrinter.java   
public static String getManifestXMLFromAPK(String apkPath) {
        ZipFile file = null;
        StringBuilder xmlSb = new StringBuilder(100);
        try {
            File apkFile = new File(apkPath);
            file = new ZipFile(apkFile, ZipFile.OPEN_READ);
            ZipEntry entry = file.getEntry(DEFAULT_XML);

            AXmlResourceParser parser=new AXmlResourceParser();
            parser.open(file.getInputStream(entry));

            StringBuilder sb=new StringBuilder(10);
            final String indentStep="   ";

            int type;
            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT) {
                switch (type) {
                    case XmlPullParser.START_DOCUMENT:
                    {
                        log(xmlSb,"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        break;
                    }
                    case XmlPullParser.START_TAG:
                    {
                        log(false,xmlSb,"%s<%s%s",sb,
                            getNamespacePrefix(parser.getPrefix()),parser.getName());
                        sb.append(indentStep);

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

                        for (int i=namespaceCountBefore;i!=namespaceCount;++i) {
                            log(xmlSb,"%sxmlns:%s=\"%s\"",
                                i==namespaceCountBefore?"  ":sb,
                                parser.getNamespacePrefix(i),
                                parser.getNamespaceUri(i));
                        }

                        for (int i=0,size=parser.getAttributeCount();i!=size;++i) {
                            log(false,xmlSb, "%s%s%s=\"%s\""," ",
                                getNamespacePrefix(parser.getAttributePrefix(i)),
                                parser.getAttributeName(i),
                                getAttributeValue(parser,i));
                        }
//                      log("%s>",sb);
                        log(xmlSb,">");
                        break;
                    }
                    case XmlPullParser.END_TAG:
                    {
                        sb.setLength(sb.length()-indentStep.length());
                        log(xmlSb,"%s</%s%s>",sb,
                            getNamespacePrefix(parser.getPrefix()),
                            parser.getName());
                        break;
                    }
                    case XmlPullParser.TEXT:
                    {
                        log(xmlSb,"%s%s",sb,parser.getText());
                        break;
                    }
                }
            }
            parser.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return xmlSb.toString();
    }
项目:Android-GetAPKInfo    文件:AXMLPrinter.java   
public static String getManifestXMLFromAPK(String apkPath) {
        ZipFile file = null;
        StringBuilder xmlSb = new StringBuilder(100);
        try {
            File apkFile = new File(apkPath);
            file = new ZipFile(apkFile, ZipFile.OPEN_READ);
            ZipEntry entry = file.getEntry(DEFAULT_XML);

            AXmlResourceParser parser=new AXmlResourceParser();
            parser.open(file.getInputStream(entry));

            StringBuilder sb=new StringBuilder(10);
            final String indentStep="   ";

            int type;
            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT) {
                switch (type) {
                    case XmlPullParser.START_DOCUMENT:
                    {
                        log(xmlSb,"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        break;
                    }
                    case XmlPullParser.START_TAG:
                    {
                        log(false,xmlSb,"%s<%s%s",sb,
                            getNamespacePrefix(parser.getPrefix()),parser.getName());
                        sb.append(indentStep);

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

                        for (int i=namespaceCountBefore;i!=namespaceCount;++i) {
                            log(xmlSb,"%sxmlns:%s=\"%s\"",
                                i==namespaceCountBefore?"  ":sb,
                                parser.getNamespacePrefix(i),
                                parser.getNamespaceUri(i));
                        }

                        for (int i=0,size=parser.getAttributeCount();i!=size;++i) {
                            log(false,xmlSb, "%s%s%s=\"%s\""," ",
                                getNamespacePrefix(parser.getAttributePrefix(i)),
                                parser.getAttributeName(i),
                                getAttributeValue(parser,i));
                        }
//                      log("%s>",sb);
                        log(xmlSb,">");
                        break;
                    }
                    case XmlPullParser.END_TAG:
                    {
                        sb.setLength(sb.length()-indentStep.length());
                        log(xmlSb,"%s</%s%s>",sb,
                            getNamespacePrefix(parser.getPrefix()),
                            parser.getName());
                        break;
                    }
                    case XmlPullParser.TEXT:
                    {
                        log(xmlSb,"%s%s",sb,parser.getText());
                        break;
                    }
                }
            }
            parser.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
//      System.out.println(xmlSb.toString());
        return xmlSb.toString();
    }
项目:apkanalysis    文件:AXmlNode.java   
public static AXmlNode createNodeTree(InputStream in) {

        AXmlNode root = new AXmlNode("root", 0);
        try {
            Stack<AXmlNode> stack = new Stack<AXmlNode>();
            stack.push(root);

            AXmlResourceParser parser = new AXmlResourceParser();
            parser.open(in);
            while (true) {
                int type = parser.next();
                if (type == XmlPullParser.END_DOCUMENT)
                    break;

                switch (type) {
                case XmlPullParser.START_TAG: {
                    AXmlNode parent = stack.peek();
                    AXmlNode node =
                        new AXmlNode(parser.getName(), parser.getDepth());
                    int count = parser.getAttributeCount();
                    for (int i = 0; i < count; ++i) {
                        node.mAttributes.put(
                            parser.getAttributeName(i),
                            getAttributeValue(parser, i));
                    }
                    parent.mChildNodes.add(node);
                    stack.push(node);
                    break;
                }
                case XmlPullParser.END_TAG: {
                    stack.pop();
                    break;
                }
                }
            }
        } catch (Exception e) {
            root = null;
            e.printStackTrace();
        }
        return root;
    }
项目:apkReSign    文件:ResignerLogic.java   
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();
}
项目:semdroid    文件:AXMLPrinter.java   
public static void main(String[] arguments) {
    if (arguments.length<1) {
        log("Usage: AXMLPrinter <binary xml file>");
        return;
    }
    try {
        AXmlResourceParser parser=new AXmlResourceParser();
        parser.open(new FileInputStream(arguments[0]));
        StringBuilder indent=new StringBuilder(10);
        final String indentStep="   ";
        while (true) {
            int type=parser.next();
            if (type==XmlPullParser.END_DOCUMENT) {
                break;
            }
            switch (type) {
                case XmlPullParser.START_DOCUMENT:
                {
                    log("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                    break;
                }
                case XmlPullParser.START_TAG:
                {
                    log("%s<%s%s",indent,
                        getNamespacePrefix(parser.getPrefix()),parser.getName());
                    indent.append(indentStep);

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

                    for (int i=0;i!=parser.getAttributeCount();++i) {
                        log("%s%s%s=\"%s\"",indent,
                            getNamespacePrefix(parser.getAttributePrefix(i)),
                            parser.getAttributeName(i),
                            getAttributeValue(parser,i));
                    }
                    log("%s>",indent);
                    break;
                }
                case XmlPullParser.END_TAG:
                {
                    indent.setLength(indent.length()-indentStep.length());
                    log("%s</%s%s>",indent,
                        getNamespacePrefix(parser.getPrefix()),
                        parser.getName());
                    break;
                }
                case XmlPullParser.TEXT:
                {
                    log("%s%s",indent,parser.getText());
                    break;
                }
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}