use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class Deobfuscator method processClass.
private void processClass(ClassNode cls) {
if (isR(cls.getParentClass())) {
return;
}
ClassInfo clsInfo = cls.getClassInfo();
DeobfClsInfo deobfClsInfo = clsMap.get(clsInfo);
if (deobfClsInfo != null) {
clsInfo.changeShortName(deobfClsInfo.getAlias());
PackageNode pkgNode = deobfClsInfo.getPkg();
if (!clsInfo.isInner() && pkgNode.hasAnyAlias()) {
clsInfo.changePkg(pkgNode.getFullAlias());
}
} else if (!clsInfo.isInner()) {
// check if package renamed
PackageNode pkgNode = getPackageNode(clsInfo.getPackage(), false);
if (pkgNode != null && pkgNode.hasAnyAlias()) {
clsInfo.changePkg(pkgNode.getFullAlias());
}
}
for (FieldNode field : cls.getFields()) {
if (field.contains(AFlag.DONT_RENAME)) {
continue;
}
renameField(field);
}
mthProcessQueue.addAll(cls.getMethods());
for (ClassNode innerCls : cls.getInnerClasses()) {
processClass(innerCls);
}
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class JsonMappingGen method addFields.
private static void addFields(ClassNode cls, JsonClsMapping jsonCls) {
List<FieldNode> fields = cls.getFields();
if (fields.isEmpty()) {
return;
}
jsonCls.setFields(new ArrayList<>(fields.size()));
for (FieldNode field : fields) {
JsonFieldMapping jsonField = new JsonFieldMapping();
jsonField.setName(field.getName());
jsonField.setAlias(field.getAlias());
jsonCls.getFields().add(jsonField);
}
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class JavaClass method loadLists.
private synchronized void loadLists() {
if (listsLoaded) {
return;
}
listsLoaded = true;
decompile();
JadxDecompiler rootDecompiler = getRootDecompiler();
int inClsCount = cls.getInnerClasses().size();
if (inClsCount != 0) {
List<JavaClass> list = new ArrayList<>(inClsCount);
for (ClassNode inner : cls.getInnerClasses()) {
if (!inner.contains(AFlag.DONT_GENERATE)) {
JavaClass javaClass = rootDecompiler.convertClassNode(inner);
javaClass.loadLists();
list.add(javaClass);
}
}
this.innerClasses = Collections.unmodifiableList(list);
}
int inlinedClsCount = cls.getInlinedClasses().size();
if (inlinedClsCount != 0) {
List<JavaClass> list = new ArrayList<>(inlinedClsCount);
for (ClassNode inner : cls.getInlinedClasses()) {
JavaClass javaClass = rootDecompiler.convertClassNode(inner);
javaClass.loadLists();
list.add(javaClass);
}
this.inlinedClasses = Collections.unmodifiableList(list);
}
int fieldsCount = cls.getFields().size();
if (fieldsCount != 0) {
List<JavaField> flds = new ArrayList<>(fieldsCount);
for (FieldNode f : cls.getFields()) {
if (!f.contains(AFlag.DONT_GENERATE)) {
JavaField javaField = new JavaField(this, f);
flds.add(javaField);
}
}
this.fields = Collections.unmodifiableList(flds);
}
int methodsCount = cls.getMethods().size();
if (methodsCount != 0) {
List<JavaMethod> mths = new ArrayList<>(methodsCount);
for (MethodNode m : cls.getMethods()) {
if (!m.contains(AFlag.DONT_GENERATE)) {
JavaMethod javaMethod = new JavaMethod(this, m);
mths.add(javaMethod);
}
}
mths.sort(Comparator.comparing(JavaMethod::getName));
this.methods = Collections.unmodifiableList(mths);
}
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class ModVisitor method fixFieldUsage.
/**
* If field is not visible from use site => cast to origin class
*/
private static void fixFieldUsage(MethodNode mth, IndexInsnNode insn) {
InsnArg instanceArg = insn.getArg(insn.getType() == InsnType.IGET ? 0 : 1);
if (instanceArg.contains(AFlag.SUPER)) {
return;
}
if (instanceArg.isInsnWrap() && ((InsnWrapArg) instanceArg).getWrapInsn().getType() == InsnType.CAST) {
return;
}
FieldInfo fieldInfo = (FieldInfo) insn.getIndex();
ArgType clsType = fieldInfo.getDeclClass().getType();
ArgType instanceType = instanceArg.getType();
if (Objects.equals(clsType, instanceType)) {
// cast not needed
return;
}
FieldNode fieldNode = mth.root().resolveField(fieldInfo);
if (fieldNode == null) {
// unknown field
TypeCompareEnum result = mth.root().getTypeCompare().compareTypes(instanceType, clsType);
if (result.isEqual() || (result == TypeCompareEnum.NARROW_BY_GENERIC && !instanceType.isGenericType())) {
return;
}
} else if (isFieldVisibleInMethod(fieldNode, mth)) {
return;
}
// insert cast
IndexInsnNode castInsn = new IndexInsnNode(InsnType.CAST, clsType, 1);
castInsn.addArg(instanceArg.duplicate());
castInsn.add(AFlag.SYNTHETIC);
castInsn.add(AFlag.EXPLICIT_CAST);
InsnArg castArg = InsnArg.wrapInsnIntoArg(castInsn);
castArg.setType(clsType);
insn.replaceArg(instanceArg, castArg);
InsnRemover.unbindArgUsage(mth, instanceArg);
}
use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.
the class ReSugarCode method replaceConstInArg.
private static InsnArg replaceConstInArg(MethodNode mth, InsnArg valueArg) {
if (valueArg.isLiteral()) {
FieldNode f = mth.getParentClass().getConstFieldByLiteralArg((LiteralArg) valueArg);
if (f != null) {
InsnNode fGet = new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0);
InsnArg arg = InsnArg.wrapArg(fGet);
f.addUseIn(mth);
return arg;
}
}
return valueArg.duplicate();
}
Aggregations