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);
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations