Commit 6a99d004 authored by Skylot's avatar Skylot

core: fix enum fields name after obfuscation (fix #51)

parent f87bf3f1
......@@ -127,9 +127,9 @@ public class ClassGen {
.remove(AccessFlags.ACC_STATIC);
}
// 'static' modifier not allowed for top classes (not inner)
// 'static' and 'private' modifier not allowed for top classes (not inner)
if (!cls.getAlias().isInner()) {
af = af.remove(AccessFlags.ACC_STATIC);
af = af.remove(AccessFlags.ACC_STATIC).remove(AccessFlags.ACC_PRIVATE);
}
annotationGen.addForClass(clsCode);
......@@ -370,7 +370,7 @@ public class ClassGen {
InsnGen igen = null;
for (Iterator<EnumField> it = enumFields.getFields().iterator(); it.hasNext(); ) {
EnumField f = it.next();
code.startLine(f.getName());
code.startLine(f.getField().getAlias());
ConstructorInsn constrInsn = f.getConstrInsn();
if (constrInsn.getArgsCount() > f.getStartArg()) {
if (igen == null) {
......@@ -393,6 +393,9 @@ public class ClassGen {
code.startLine();
}
code.add(';');
if (isFieldsPresents()) {
code.startLine();
}
}
}
......
......@@ -2,6 +2,7 @@ package jadx.core.dex.attributes.nodes;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.IAttribute;
import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.instructions.mods.ConstructorInsn;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.MethodNode;
......@@ -12,19 +13,19 @@ import java.util.List;
public class EnumClassAttr implements IAttribute {
public static class EnumField {
private final String name;
private final FieldInfo field;
private final ConstructorInsn constrInsn;
private final int startArg;
private ClassNode cls;
public EnumField(String name, ConstructorInsn co, int startArg) {
this.name = name;
public EnumField(FieldInfo field, ConstructorInsn co, int startArg) {
this.field = field;
this.constrInsn = co;
this.startArg = startArg;
}
public String getName() {
return name;
public FieldInfo getField() {
return field;
}
public ConstructorInsn getConstrInsn() {
......@@ -45,7 +46,7 @@ public class EnumClassAttr implements IAttribute {
@Override
public String toString() {
return name + "(" + constrInsn + ") " + cls;
return field + "(" + constrInsn + ") " + cls;
}
}
......
package jadx.core.dex.visitors;
import jadx.core.codegen.TypeGen;
import jadx.core.deobf.NameMapper;
import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.nodes.EnumClassAttr;
import jadx.core.dex.attributes.nodes.EnumClassAttr.EnumField;
......@@ -138,12 +139,18 @@ public class EnumVisitor extends AbstractVisitor {
if (!clsInfo.equals(classInfo) && !constrCls.getAccessFlags().isEnum()) {
continue;
}
FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) putInsn).getIndex();
String name = getConstString(cls.dex(), co.getArg(0));
if (name == null) {
throw new JadxException("Unknown enum field name: " + cls);
if (name != null
&& !fieldInfo.getAlias().equals(name)
&& NameMapper.isValidIdentifier(name)) {
// LOG.debug("Rename enum field: '{}' to '{}' in {}", fieldInfo.getName(), name, cls);
fieldInfo.setAlias(name);
}
EnumField field = new EnumField(name, co, 2);
EnumField field = new EnumField(fieldInfo, co, 2);
attr.getFields().add(field);
if (!co.getClassType().equals(classInfo)) {
// enum contains additional methods
for (ClassNode innerCls : cls.getInnerClasses()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment