Search in sources :

Example 1 with RawNamedValue

use of jadx.core.xmlgen.entry.RawNamedValue in project jadx by skylot.

the class ResTableParser method parseEntry.

private void parseEntry(PackageChunk pkg, int typeId, int entryId, EntryConfig config) throws IOException {
    /* int size = */
    is.readInt16();
    int flags = is.readInt16();
    int key = is.readInt32();
    int resRef = pkg.getId() << 24 | typeId << 16 | entryId;
    String typeName = pkg.getTypeStrings()[typeId - 1];
    String keyName = pkg.getKeyStrings()[key];
    ResourceEntry ri = new ResourceEntry(resRef, pkg.getName(), typeName, keyName);
    ri.setConfig(config);
    if ((flags & FLAG_COMPLEX) == 0) {
        ri.setSimpleValue(parseValue());
    } else {
        int parentRef = is.readInt32();
        ri.setParentRef(parentRef);
        int count = is.readInt32();
        List<RawNamedValue> values = new ArrayList<RawNamedValue>(count);
        for (int i = 0; i < count; i++) {
            values.add(parseValueMap());
        }
        ri.setNamedValues(values);
    }
    resStorage.add(ri);
}
Also used : ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) ArrayList(java.util.ArrayList) RawNamedValue(jadx.core.xmlgen.entry.RawNamedValue)

Example 2 with RawNamedValue

use of jadx.core.xmlgen.entry.RawNamedValue in project jadx by skylot.

the class ResXmlGen method addValue.

private void addValue(CodeWriter cw, ResourceEntry ri) {
    if (ri.getSimpleValue() != null) {
        String valueStr = vp.decodeValue(ri.getSimpleValue());
        addSimpleValue(cw, ri.getTypeName(), "name", ri.getKeyName(), valueStr);
    } else {
        cw.startLine();
        cw.add('<').add(ri.getTypeName()).add(' ');
        cw.add("name=\"").add(ri.getKeyName()).add("\">");
        cw.incIndent();
        for (RawNamedValue value : ri.getNamedValues()) {
            addItem(cw, value);
        }
        cw.decIndent();
        cw.startLine().add("</").add(ri.getTypeName()).add('>');
    }
}
Also used : RawNamedValue(jadx.core.xmlgen.entry.RawNamedValue)

Example 3 with RawNamedValue

use of jadx.core.xmlgen.entry.RawNamedValue in project jadx by skylot.

the class ResXmlGen method addValue.

private void addValue(ICodeWriter cw, ResourceEntry ri) {
    if (ri.getProtoValue() != null) {
        ProtoValue protoValue = ri.getProtoValue();
        if (protoValue.getValue() != null && protoValue.getNamedValues() == null) {
            addSimpleValue(cw, ri.getTypeName(), ri.getTypeName(), "name", ri.getKeyName(), protoValue.getValue());
        } else {
            cw.startLine();
            cw.add('<').add(ri.getTypeName()).add(' ');
            String itemTag = "item";
            cw.add("name=\"").add(ri.getKeyName()).add('\"');
            if (ri.getTypeName().equals("attr") && protoValue.getValue() != null) {
                cw.add(" format=\"").add(protoValue.getValue()).add('\"');
            }
            if (protoValue.getParent() != null) {
                cw.add(" parent=\"").add(protoValue.getParent()).add('\"');
            }
            cw.add(">");
            cw.incIndent();
            for (ProtoValue value : protoValue.getNamedValues()) {
                addProtoItem(cw, itemTag, ri.getTypeName(), value);
            }
            cw.decIndent();
            cw.startLine().add("</").add(ri.getTypeName()).add('>');
        }
    } else if (ri.getSimpleValue() != null) {
        String valueStr = vp.decodeValue(ri.getSimpleValue());
        addSimpleValue(cw, ri.getTypeName(), ri.getTypeName(), "name", ri.getKeyName(), valueStr);
    } else {
        cw.startLine();
        cw.add('<').add(ri.getTypeName()).add(' ');
        String itemTag = "item";
        if (ri.getTypeName().equals("attr") && !ri.getNamedValues().isEmpty()) {
            cw.add("name=\"").add(ri.getKeyName());
            int type = ri.getNamedValues().get(0).getRawValue().getData();
            if ((type & ValuesParser.ATTR_TYPE_ENUM) != 0) {
                itemTag = "enum";
            } else if ((type & ValuesParser.ATTR_TYPE_FLAGS) != 0) {
                itemTag = "flag";
            }
            String formatValue = XmlGenUtils.getAttrTypeAsString(type);
            if (formatValue != null) {
                cw.add("\" format=\"").add(formatValue);
            }
            cw.add("\"");
        } else {
            cw.add("name=\"").add(ri.getKeyName()).add('\"');
        }
        if (ri.getParentRef() != 0) {
            String parent = vp.decodeValue(TYPE_REFERENCE, ri.getParentRef());
            cw.add(" parent=\"").add(parent).add('\"');
        }
        cw.add(">");
        cw.incIndent();
        for (RawNamedValue value : ri.getNamedValues()) {
            addItem(cw, itemTag, ri.getTypeName(), value);
        }
        cw.decIndent();
        cw.startLine().add("</").add(ri.getTypeName()).add('>');
    }
}
Also used : RawNamedValue(jadx.core.xmlgen.entry.RawNamedValue) ProtoValue(jadx.core.xmlgen.entry.ProtoValue)

Example 4 with RawNamedValue

use of jadx.core.xmlgen.entry.RawNamedValue in project jadx by skylot.

the class ResTableParser method parseEntry.

private void parseEntry(PackageChunk pkg, int typeId, int entryId, String config) throws IOException {
    int size = is.readInt16();
    int flags = is.readInt16();
    int key = is.readInt32();
    if (key == -1) {
        return;
    }
    int resRef = pkg.getId() << 24 | typeId << 16 | entryId;
    String typeName = pkg.getTypeStrings()[typeId - 1];
    String origKeyName = pkg.getKeyStrings()[key];
    ResourceEntry newResEntry = new ResourceEntry(resRef, pkg.getName(), typeName, getResName(typeName, resRef, origKeyName), config);
    ResourceEntry prevResEntry = resStorage.searchEntryWithSameName(newResEntry);
    if (prevResEntry != null) {
        newResEntry = newResEntry.copyWithId();
        // rename also previous entry for consistency
        ResourceEntry replaceForPrevEntry = prevResEntry.copyWithId();
        resStorage.replace(prevResEntry, replaceForPrevEntry);
        resStorage.addRename(replaceForPrevEntry);
    }
    if (!Objects.equals(origKeyName, newResEntry.getKeyName())) {
        resStorage.addRename(newResEntry);
    }
    if ((flags & FLAG_COMPLEX) != 0 || size == 16) {
        int parentRef = is.readInt32();
        int count = is.readInt32();
        newResEntry.setParentRef(parentRef);
        List<RawNamedValue> values = new ArrayList<>(count);
        for (int i = 0; i < count; i++) {
            values.add(parseValueMap());
        }
        newResEntry.setNamedValues(values);
    } else {
        newResEntry.setSimpleValue(parseValue());
    }
    resStorage.add(newResEntry);
}
Also used : ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) ArrayList(java.util.ArrayList) RawNamedValue(jadx.core.xmlgen.entry.RawNamedValue)

Aggregations

RawNamedValue (jadx.core.xmlgen.entry.RawNamedValue)4 ResourceEntry (jadx.core.xmlgen.entry.ResourceEntry)2 ArrayList (java.util.ArrayList)2 ProtoValue (jadx.core.xmlgen.entry.ProtoValue)1