use of jadx.core.dex.attributes.nodes.RenameReasonAttr in project jadx by skylot.
the class RenameVisitor method checkClassName.
private static void checkClassName(Deobfuscator deobfuscator, ClassNode cls, JadxArgs args) {
ClassInfo classInfo = cls.getClassInfo();
String clsName = classInfo.getAliasShortName();
String newShortName = fixClsShortName(args, clsName);
if (newShortName == null) {
// rename failed, use deobfuscator
String deobfName = deobfuscator.getClsAlias(cls);
classInfo.changeShortName(deobfName);
cls.addAttr(new RenameReasonAttr(cls).notPrintable());
return;
}
if (!newShortName.equals(clsName)) {
classInfo.changeShortName(newShortName);
cls.addAttr(new RenameReasonAttr(cls).append("invalid class name"));
}
if (classInfo.isInner() && args.isRenameValid()) {
// check inner classes names
ClassInfo parentClass = classInfo.getParentClass();
while (parentClass != null) {
if (parentClass.getAliasShortName().equals(newShortName)) {
String clsAlias = deobfuscator.getClsAlias(cls);
classInfo.changeShortName(clsAlias);
cls.addAttr(new RenameReasonAttr(cls).append("collision with other inner class name"));
break;
}
parentClass = parentClass.getParentClass();
}
}
checkPackage(deobfuscator, cls, classInfo, args);
}
use of jadx.core.dex.attributes.nodes.RenameReasonAttr in project jadx by skylot.
the class RenameVisitor method checkMethods.
private static void checkMethods(Deobfuscator deobfuscator, ClassNode cls, JadxArgs args) {
List<MethodNode> methods = new ArrayList<>(cls.getMethods().size());
for (MethodNode method : cls.getMethods()) {
if (!method.getAccessFlags().isConstructor()) {
methods.add(method);
}
}
for (MethodNode mth : methods) {
String alias = mth.getAlias();
boolean notValid = args.isRenameValid() && !NameMapper.isValidIdentifier(alias);
boolean notPrintable = args.isRenamePrintable() && !NameMapper.isAllCharsPrintable(alias);
if (notValid || notPrintable) {
deobfuscator.forceRenameMethod(mth);
mth.addAttr(new RenameReasonAttr(mth, notValid, notPrintable));
}
}
// Rename methods with same signature
if (args.isRenameValid()) {
Set<String> names = new HashSet<>(methods.size());
for (MethodNode mth : methods) {
AccessInfo accessFlags = mth.getAccessFlags();
if (accessFlags.isBridge() || accessFlags.isSynthetic() || mth.contains(AFlag.DONT_GENERATE)) /* this flag not set yet */
{
continue;
}
String signature = mth.getMethodInfo().makeSignature(true, false);
if (!names.add(signature)) {
deobfuscator.forceRenameMethod(mth);
mth.addAttr(new RenameReasonAttr("collision with other method in class"));
}
}
}
}
use of jadx.core.dex.attributes.nodes.RenameReasonAttr in project jadx by skylot.
the class OverrideMethodVisitor method checkMethodSignatureCollisions.
private void checkMethodSignatureCollisions(MethodNode mth, boolean rename) {
String mthName = mth.getMethodInfo().getAlias();
String newSignature = MethodInfo.makeShortId(mthName, mth.getArgTypes(), null);
for (MethodNode otherMth : mth.getParentClass().getMethods()) {
String otherMthName = otherMth.getAlias();
if (otherMthName.equals(mthName) && otherMth != mth) {
String otherSignature = otherMth.getMethodInfo().makeSignature(true, false);
if (otherSignature.equals(newSignature)) {
if (rename) {
if (otherMth.contains(AFlag.DONT_RENAME) || otherMth.contains(AType.METHOD_OVERRIDE)) {
otherMth.addWarnComment("Can't rename method to resolve collision");
} else {
otherMth.getMethodInfo().setAlias(makeNewAlias(otherMth));
otherMth.addAttr(new RenameReasonAttr("avoid collision after fix types in other method"));
}
}
otherMth.addAttr(new MethodBridgeAttr(mth));
return;
}
}
}
}
use of jadx.core.dex.attributes.nodes.RenameReasonAttr in project jadx by skylot.
the class CodeGenUtils method addRenamedComment.
public static void addRenamedComment(ICodeWriter code, NotificationAttrNode node, String origName) {
if (!node.checkCommentsLevel(CommentsLevel.INFO)) {
return;
}
code.startLine("/* renamed from: ").add(origName);
RenameReasonAttr renameReasonAttr = node.get(AType.RENAME_REASON);
if (renameReasonAttr != null) {
code.add(" reason: ");
code.add(renameReasonAttr.getDescription());
}
code.add(" */");
}
use of jadx.core.dex.attributes.nodes.RenameReasonAttr in project jadx by skylot.
the class RenameVisitor method checkFields.
private static void checkFields(Deobfuscator deobfuscator, ClassNode cls, JadxArgs args) {
Set<String> names = new HashSet<>();
for (FieldNode field : cls.getFields()) {
FieldInfo fieldInfo = field.getFieldInfo();
String fieldName = fieldInfo.getAlias();
boolean notUnique = !names.add(fieldName);
boolean notValid = args.isRenameValid() && !NameMapper.isValidIdentifier(fieldName);
boolean notPrintable = args.isRenamePrintable() && !NameMapper.isAllCharsPrintable(fieldName);
if (notUnique || notValid || notPrintable) {
deobfuscator.forceRenameField(field);
field.addAttr(new RenameReasonAttr(field, notValid, notPrintable));
if (notUnique) {
field.addAttr(new RenameReasonAttr(field).append("collision with other field name"));
}
}
}
}
Aggregations