Search in sources :

Example 6 with ResourceEntry

use of jadx.core.xmlgen.entry.ResourceEntry 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 7 with ResourceEntry

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

the class ResourceStorage method getByRef.

public ResourceEntry getByRef(int refId) {
    ResourceEntry key = new ResourceEntry(refId);
    int index = Collections.binarySearch(list, key, COMPARATOR);
    if (index < 0) {
        return null;
    }
    return list.get(index);
}
Also used : ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry)

Example 8 with ResourceEntry

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

the class RootNode method updateObfuscatedFiles.

private void updateObfuscatedFiles(ResTableParser parser, List<ResourceFile> resources) {
    if (args.isSkipResources()) {
        return;
    }
    long start = System.currentTimeMillis();
    int renamedCount = 0;
    ResourceStorage resStorage = parser.getResStorage();
    ValuesParser valuesParser = new ValuesParser(parser.getStrings(), resStorage.getResourcesNames());
    Map<String, ResourceEntry> entryNames = new HashMap<>();
    for (ResourceEntry resEntry : resStorage.getResources()) {
        String val = valuesParser.getSimpleValueString(resEntry);
        if (val != null) {
            entryNames.put(val, resEntry);
        }
    }
    for (ResourceFile resource : resources) {
        ResourceEntry resEntry = entryNames.get(resource.getOriginalName());
        if (resEntry != null) {
            resource.setAlias(resEntry);
            renamedCount++;
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Renamed obfuscated resources: {}, duration: {}ms", renamedCount, System.currentTimeMillis() - start);
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) HashMap(java.util.HashMap) ResourceStorage(jadx.core.xmlgen.ResourceStorage) ValuesParser(jadx.core.xmlgen.entry.ValuesParser)

Example 9 with ResourceEntry

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

the class IntegrationTest method insertResources.

private void insertResources(RootNode root) {
    if (resMap.isEmpty()) {
        return;
    }
    ResourceStorage resStorage = new ResourceStorage();
    for (Map.Entry<Integer, String> entry : resMap.entrySet()) {
        Integer id = entry.getKey();
        String name = entry.getValue();
        String[] parts = name.split("\\.");
        resStorage.add(new ResourceEntry(id, "", parts[0], parts[1], ""));
    }
    root.processResources(resStorage);
}
Also used : ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) ResourceStorage(jadx.core.xmlgen.ResourceStorage) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map)

Example 10 with ResourceEntry

use of jadx.core.xmlgen.entry.ResourceEntry 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

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