提交 07d7e68d 编写于 作者: S Skylot

fix: format Android resources ids as hex (#1171)

上级 8785c33d
......@@ -43,6 +43,7 @@ import jadx.core.dex.nodes.RootNode;
import jadx.core.utils.CodeGenUtils;
import jadx.core.utils.ErrorsCounter;
import jadx.core.utils.Utils;
import jadx.core.utils.android.AndroidResourcesUtils;
import jadx.core.utils.exceptions.CodegenException;
import jadx.core.utils.exceptions.JadxRuntimeException;
......@@ -402,7 +403,9 @@ public class ClassGen {
if (encodedValue.getType() == EncodedType.ENCODED_NULL) {
code.add(TypeGen.literalToString(0, f.getType(), cls, fallback));
} else {
annotationGen.encodeValue(cls.root(), code, encodedValue);
if (!AndroidResourcesUtils.handleResourceFieldValue(cls, code, encodedValue)) {
annotationGen.encodeValue(cls.root(), code, encodedValue);
}
}
} else if (fv.isInsn()) {
InsnGen insnGen = makeInsnGen(fv.getInsnMth());
......
......@@ -74,6 +74,23 @@ public class AndroidResourcesUtils {
return false;
}
/**
* Force hex format for Android resources ids
*/
@SuppressWarnings("RedundantCast")
public static boolean handleResourceFieldValue(ClassNode cls, ICodeWriter code, EncodedValue encodedValue) {
if (encodedValue.getType() == EncodedType.ENCODED_INT && isResourceClass(cls)) {
code.add(String.format("0x%X", ((Integer) encodedValue.getValue())));
return true;
}
return false;
}
public static boolean isResourceClass(ClassNode cls) {
ClassNode parentClass = cls.getParentClass();
return parentClass != null && parentClass.getShortName().equals("R");
}
private static ClassNode makeClass(RootNode root, String clsName, ResourceStorage resStorage) {
ClassNode rCls = ClassNode.addSyntheticClass(root, clsName, AccessFlags.PUBLIC | AccessFlags.FINAL);
rCls.addAttr(AType.COMMENTS, "This class is generated by JADX");
......
......@@ -35,7 +35,7 @@ public class XmlGenUtils {
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=\"%s\" />",
String format = String.format("<public type=\"%s\" name=\"%s\" id=\"0x%X\" />",
ri.getTypeName(), ri.getKeyName(), ri.getId());
writer.startLine(format);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册