Search in sources :

Example 1 with ResourceEntry

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

the class ResTableParser method makeDump.

public CodeWriter makeDump() throws IOException {
    CodeWriter writer = new CodeWriter();
    writer.add("app package: ").add(resStorage.getAppPackage());
    writer.startLine();
    ValuesParser vp = new ValuesParser(strings, resStorage.getResourcesNames());
    for (ResourceEntry ri : resStorage.getResources()) {
        writer.startLine(ri + ": " + vp.getValueString(ri));
    }
    writer.finish();
    return writer;
}
Also used : ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) ValuesParser(jadx.core.xmlgen.entry.ValuesParser) CodeWriter(jadx.core.codegen.CodeWriter)

Example 2 with ResourceEntry

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

the class AndroidResourcesUtils method addResourceFields.

private static void addResourceFields(ClassNode resCls, ResourceStorage resStorage, boolean rClsExists) {
    Map<Integer, FieldNode> resFieldsMap = fillResFieldsMap(resCls);
    Map<String, ResClsInfo> innerClsMap = new TreeMap<>();
    if (rClsExists) {
        for (ClassNode innerClass : resCls.getInnerClasses()) {
            ResClsInfo innerResCls = new ResClsInfo(innerClass);
            innerClass.getFields().forEach(field -> innerResCls.getFieldsMap().put(field.getName(), field));
            innerClsMap.put(innerClass.getShortName(), innerResCls);
        }
    }
    for (ResourceEntry resource : resStorage.getResources()) {
        String resTypeName = resource.getTypeName();
        String resName = resTypeName.equals("style") ? resource.getKeyName().replace('.', '_') : resource.getKeyName();
        ResClsInfo typeClsInfo = innerClsMap.computeIfAbsent(resTypeName, name -> getClassForResType(resCls, rClsExists, name));
        typeClsInfo.getFieldsMap().computeIfAbsent(resName, name -> {
            ClassNode typeCls = typeClsInfo.getTypeCls();
            FieldInfo rFieldInfo = FieldInfo.from(typeCls.root(), typeCls.getClassInfo(), resName, ArgType.INT);
            FieldNode newResField = new FieldNode(typeCls, rFieldInfo, AccessFlags.PUBLIC | AccessFlags.STATIC | AccessFlags.FINAL);
            newResField.addAttr(new EncodedValue(EncodedType.ENCODED_INT, resource.getId()));
            typeCls.getFields().add(newResField);
            if (rClsExists) {
                newResField.addInfoComment("Added by JADX");
            }
            return newResField;
        });
        FieldNode fieldNode = resFieldsMap.get(resource.getId());
        if (fieldNode != null && !fieldNode.getName().equals(resName) && NameMapper.isValidAndPrintable(resName) && resCls.root().getArgs().isRenameValid()) {
            fieldNode.add(AFlag.DONT_RENAME);
            fieldNode.getFieldInfo().setAlias(resName);
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) FieldNode(jadx.core.dex.nodes.FieldNode) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) TreeMap(java.util.TreeMap) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 3 with ResourceEntry

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

the class ResProtoParser method parse.

private void parse(String packageName, List<Type> types) {
    for (Type type : types) {
        String typeName = type.getName();
        for (Entry entry : type.getEntryList()) {
            int id = entry.getEntryId().getId();
            String entryName = entry.getName();
            for (ConfigValue configValue : entry.getConfigValueList()) {
                String config = parse(configValue.getConfig());
                ResourceEntry resEntry = new ResourceEntry(id, packageName, typeName, entryName, config);
                resStorage.add(resEntry);
                ProtoValue protoValue;
                if (configValue.getValue().getValueCase() == Value.ValueCase.ITEM) {
                    protoValue = new ProtoValue(parse(configValue.getValue().getItem()));
                } else {
                    protoValue = parse(configValue.getValue().getCompoundValue());
                }
                resEntry.setProtoValue(protoValue);
            }
        }
    }
}
Also used : Type(com.android.aapt.Resources.Type) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) Entry(com.android.aapt.Resources.Entry) ConfigValue(com.android.aapt.Resources.ConfigValue) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) ProtoValue(jadx.core.xmlgen.entry.ProtoValue)

Example 4 with ResourceEntry

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

the class ResXmlGen method makeResourcesXml.

public List<ResContainer> makeResourcesXml() {
    Map<String, ICodeWriter> contMap = new HashMap<>();
    for (ResourceEntry ri : resStorage.getResources()) {
        if (SKIP_RES_TYPES.contains(ri.getTypeName())) {
            continue;
        }
        String fn = getFileName(ri);
        ICodeWriter cw = contMap.get(fn);
        if (cw == null) {
            cw = new SimpleCodeWriter();
            cw.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            cw.startLine("<resources>");
            cw.incIndent();
            contMap.put(fn, cw);
        }
        addValue(cw, ri);
    }
    List<ResContainer> files = new ArrayList<>(contMap.size());
    for (Map.Entry<String, ICodeWriter> entry : contMap.entrySet()) {
        String fileName = entry.getKey();
        ICodeWriter content = entry.getValue();
        content.decIndent();
        content.startLine("</resources>");
        ICodeInfo codeInfo = content.finish();
        files.add(ResContainer.textResource(fileName, codeInfo));
    }
    Collections.sort(files);
    return files;
}
Also used : HashMap(java.util.HashMap) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) ArrayList(java.util.ArrayList) ICodeInfo(jadx.api.ICodeInfo) ICodeWriter(jadx.api.ICodeWriter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ResourceEntry

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

the class XmlGenUtils method makeXmlDump.

public static ICodeInfo makeXmlDump(ICodeWriter writer, ResourceStorage resStorage) {
    writer.startLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    writer.startLine("<resources>");
    writer.incIndent();
    Set<String> addedValues = new HashSet<>();
    for (ResourceEntry ri : resStorage.getResources()) {
        if (addedValues.add(ri.getTypeName() + '.' + ri.getKeyName())) {
            String format = String.format("<public type=\"%s\" name=\"%s\" id=\"0x%08x\" />", ri.getTypeName(), ri.getKeyName(), ri.getId());
            writer.startLine(format);
        }
    }
    writer.decIndent();
    writer.startLine("</resources>");
    return writer.finish();
}
Also used : ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) HashSet(java.util.HashSet)

Aggregations

ResourceEntry (jadx.core.xmlgen.entry.ResourceEntry)10 ArrayList (java.util.ArrayList)3 ResourceStorage (jadx.core.xmlgen.ResourceStorage)2 RawNamedValue (jadx.core.xmlgen.entry.RawNamedValue)2 ValuesParser (jadx.core.xmlgen.entry.ValuesParser)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigValue (com.android.aapt.Resources.ConfigValue)1 Entry (com.android.aapt.Resources.Entry)1 Type (com.android.aapt.Resources.Type)1 ICodeInfo (jadx.api.ICodeInfo)1 ICodeWriter (jadx.api.ICodeWriter)1 ResourceFile (jadx.api.ResourceFile)1 SimpleCodeWriter (jadx.api.impl.SimpleCodeWriter)1 EncodedValue (jadx.api.plugins.input.data.annotations.EncodedValue)1 CodeWriter (jadx.core.codegen.CodeWriter)1 FieldInfo (jadx.core.dex.info.FieldInfo)1 ClassNode (jadx.core.dex.nodes.ClassNode)1 FieldNode (jadx.core.dex.nodes.FieldNode)1 ProtoValue (jadx.core.xmlgen.entry.ProtoValue)1