Commit 2cfc208a authored by Skylot's avatar Skylot

core: fix constant fields values retrieval

parent 5dc4c28d
...@@ -402,7 +402,7 @@ public class InsnGen { ...@@ -402,7 +402,7 @@ public class InsnGen {
/* fallback mode instructions */ /* fallback mode instructions */
case IF: case IF:
assert isFallback(); assert isFallback() : "if insn in not fallback mode";
IfNode ifInsn = (IfNode) insn; IfNode ifInsn = (IfNode) insn;
String cond = arg(insn.getArg(0)) + " " + ifInsn.getOp().getSymbol() + " " String cond = arg(insn.getArg(0)) + " " + ifInsn.getOp().getSymbol() + " "
+ (ifInsn.isZeroCmp() ? "0" : arg(insn.getArg(1))); + (ifInsn.isZeroCmp() ? "0" : arg(insn.getArg(1)));
......
...@@ -13,6 +13,7 @@ import jadx.core.dex.info.FieldInfo; ...@@ -13,6 +13,7 @@ import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.info.MethodInfo; import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.LiteralArg; import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.PrimitiveType;
import jadx.core.dex.nodes.parser.AnnotationsParser; import jadx.core.dex.nodes.parser.AnnotationsParser;
import jadx.core.dex.nodes.parser.FieldValueAttr; import jadx.core.dex.nodes.parser.FieldValueAttr;
import jadx.core.dex.nodes.parser.StaticValuesParser; import jadx.core.dex.nodes.parser.StaticValuesParser;
...@@ -140,9 +141,9 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -140,9 +141,9 @@ public class ClassNode extends LineAttrNode implements ILoadable {
if (accFlags.isStatic() && accFlags.isFinal()) { if (accFlags.isStatic() && accFlags.isFinal()) {
FieldValueAttr fv = (FieldValueAttr) f.getAttributes().get(AttributeType.FIELD_VALUE); FieldValueAttr fv = (FieldValueAttr) f.getAttributes().get(AttributeType.FIELD_VALUE);
if (fv != null && fv.getValue() != null) { if (fv != null && fv.getValue() != null) {
if (accFlags.isPublic()) if (accFlags.isPublic()) {
dex.getConstFields().put(fv.getValue(), f); dex.getConstFields().put(fv.getValue(), f);
else }
constFields.put(fv.getValue(), f); constFields.put(fv.getValue(), f);
} }
} }
...@@ -237,34 +238,49 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -237,34 +238,49 @@ public class ClassNode extends LineAttrNode implements ILoadable {
return fields; return fields;
} }
public FieldNode getConstField(Object o) { public FieldNode getConstField(Object obj) {
return getConstField(obj, true);
}
public FieldNode getConstField(Object obj, boolean searchGlobal) {
ClassNode cn = this; ClassNode cn = this;
FieldNode field; FieldNode field;
do { do {
field = cn.constFields.get(o); field = cn.constFields.get(obj);
} }
while (field == null while (field == null
&& (cn.clsInfo.getParentClass() != null) && (cn.clsInfo.getParentClass() != null)
&& (cn = dex.resolveClass(cn.clsInfo.getParentClass())) != null); && (cn = dex.resolveClass(cn.clsInfo.getParentClass())) != null);
if (field == null) if (field == null && searchGlobal) {
field = dex.getConstFields().get(o); field = dex.getConstFields().get(obj);
}
return field; return field;
} }
public FieldNode getConstFieldByLiteralArg(LiteralArg arg) { public FieldNode getConstFieldByLiteralArg(LiteralArg arg) {
ArgType type = arg.getType(); PrimitiveType type = arg.getType().getPrimitiveType();
if (type == null) {
return null;
}
long literal = arg.getLiteral(); long literal = arg.getLiteral();
switch (type) {
if (type.equals(ArgType.DOUBLE)) case BOOLEAN:
return getConstField(Double.longBitsToDouble(literal)); return getConstField(literal == 1, false);
else if (type.equals(ArgType.FLOAT)) case CHAR:
return getConstField(Float.intBitsToFloat((int) literal)); return getConstField((char) literal, Math.abs(literal) > 1);
else if (Math.abs(literal) > 0x1) { case BYTE:
if (type.equals(ArgType.INT)) return getConstField((byte) literal, Math.abs(literal) > 1);
return getConstField((int) literal); case SHORT:
else if (type.equals(ArgType.LONG)) return getConstField((short) literal, Math.abs(literal) > 1);
return getConstField(literal); case INT:
return getConstField((int) literal, Math.abs(literal) > 1);
case LONG:
return getConstField(literal, Math.abs(literal) > 1);
case FLOAT:
return getConstField(Float.intBitsToFloat((int) literal), true);
case DOUBLE:
return getConstField(Double.longBitsToDouble(literal), true);
} }
return null; return null;
} }
......
...@@ -13,9 +13,9 @@ import jadx.core.utils.RegionUtils; ...@@ -13,9 +13,9 @@ import jadx.core.utils.RegionUtils;
import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -65,7 +65,7 @@ public class ProcessVariables extends AbstractVisitor { ...@@ -65,7 +65,7 @@ public class ProcessVariables extends AbstractVisitor {
@Override @Override
public void visit(MethodNode mth) throws JadxException { public void visit(MethodNode mth) throws JadxException {
final Map<RegisterArg, Usage> usageMap = new HashMap<RegisterArg, Usage>(); final Map<RegisterArg, Usage> usageMap = new LinkedHashMap<RegisterArg, Usage>();
// collect all variables usage // collect all variables usage
IRegionVisitor collect = new TracedRegionVisitor() { IRegionVisitor collect = new TracedRegionVisitor() {
......
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