use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class ConstStorage method getConstField.
@Nullable
public FieldNode getConstField(ClassNode cls, Object value, boolean searchGlobal) {
if (!replaceEnabled) {
return null;
}
RootNode root = cls.root();
if (value instanceof Integer) {
FieldNode rField = getResourceField((Integer) value, root);
if (rField != null) {
return rField;
}
}
boolean foundInGlobal = globalValues.contains(value);
if (foundInGlobal && !searchGlobal) {
return null;
}
ClassNode current = cls;
while (current != null) {
ValueStorage classValues = classes.get(current);
if (classValues != null) {
FieldNode field = classValues.get(value);
if (field != null) {
if (foundInGlobal) {
return null;
}
return field;
}
}
ClassInfo parentClass = current.getClassInfo().getParentClass();
if (parentClass == null) {
break;
}
current = root.resolveClass(parentClass);
}
if (searchGlobal) {
return globalValues.get(value);
}
return null;
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class ProcessKotlinInternals method getConstString.
@Nullable
private String getConstString(MethodNode mth, InsnNode insn, int arg) {
InsnArg strArg = insn.getArg(arg);
if (!strArg.isInsnWrap()) {
return null;
}
InsnNode constInsn = ((InsnWrapArg) strArg).getWrapInsn();
InsnType insnType = constInsn.getType();
if (insnType == InsnType.CONST_STR) {
return ((ConstStringNode) constInsn).getString();
}
if (insnType == InsnType.SGET) {
// revert const field inline :(
FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) constInsn).getIndex();
FieldNode fieldNode = mth.root().resolveField(fieldInfo);
if (fieldNode != null) {
String str = (String) fieldNode.get(JadxAttrType.CONSTANT_VALUE).getValue();
InsnArg newArg = InsnArg.wrapArg(new ConstStringNode(str));
insn.replaceArg(strArg, newArg);
return str;
}
}
return null;
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class TestConstReplace method testWithoutReplace.
@Test
public void testWithoutReplace() {
getArgs().setReplaceConsts(false);
ClassNode cls = getClassNode(TestCls.class);
assertThat(cls).code().containsOne("return \"string\";");
FieldNode constField = cls.searchFieldByName("CONST_VALUE");
assertThat(constField).isNotNull();
assertThat(constField.getUseIn()).isEmpty();
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class TestConstReplace method test.
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
assertThat(cls).code().containsOne("return CONST_VALUE;");
MethodNode testMth = cls.searchMethodByShortName("test");
assertThat(testMth).isNotNull();
FieldNode constField = cls.searchFieldByName("CONST_VALUE");
assertThat(constField).isNotNull();
assertThat(constField.getUseIn()).containsExactly(testMth);
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class AnonymousClassVisitor method processAnonymousConstructor.
private static void processAnonymousConstructor(MethodNode mth) {
List<InsnNode> usedInsns = new ArrayList<>();
Map<InsnArg, FieldNode> argsMap = getArgsToFieldsMapping(mth, usedInsns);
if (argsMap.isEmpty()) {
mth.add(AFlag.NO_SKIP_ARGS);
} else {
for (Map.Entry<InsnArg, FieldNode> entry : argsMap.entrySet()) {
FieldNode field = entry.getValue();
if (field == null) {
continue;
}
InsnArg arg = entry.getKey();
field.addAttr(new FieldReplaceAttr(arg));
field.add(AFlag.DONT_GENERATE);
if (arg.isRegister()) {
arg.add(AFlag.SKIP_ARG);
SkipMethodArgsAttr.skipArg(mth, ((RegisterArg) arg));
}
}
}
for (InsnNode usedInsn : usedInsns) {
usedInsn.add(AFlag.DONT_GENERATE);
}
}
Aggregations