Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inner class parent is wrong when name formatted as Class$method$xxx #2364

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void initInnerClasses() {
List<ClassNode> updated = new ArrayList<>();
for (ClassNode cls : inner) {
ClassInfo clsInfo = cls.getClassInfo();
ClassNode parent = resolveClass(clsInfo.getParentClass());
ClassNode parent = resolveParentClass(clsInfo);
if (parent == null) {
clsMap.remove(clsInfo);
clsInfo.notInner(this);
Expand Down Expand Up @@ -482,6 +482,33 @@ public ClassNode resolveRawClass(String rawFullName) {
return rawClsMap.get(rawFullName);
}

/**
* Find and correct the parent of an inner class.
* <br>
* Sometimes inner ClassInfo generated wrong parent info.
* e.g. inner is `Cls$mth$1`, current parent = `Cls$mth`, real parent = `Cls`
*/
@Nullable
public ClassNode resolveParentClass(ClassInfo clsInfo) {
ClassInfo parentInfo = clsInfo.getParentClass();
ClassNode parentNode = resolveClass(parentInfo);
if (parentNode == null && parentInfo != null) {
String parClsName = parentInfo.getFullName();
// strip last part as method name
int sep = parClsName.lastIndexOf('.');
if (sep > 0 && sep != parClsName.length() - 1) {
String mthName = parClsName.substring(sep + 1);
String upperParClsName = parClsName.substring(0, sep);
ClassNode tmpParent = resolveClass(upperParClsName);
if (tmpParent != null && tmpParent.searchMethodByShortName(mthName) != null) {
parentNode = tmpParent;
clsInfo.convertToInner(parentNode);
}
}
}
return parentNode;
}

/**
* Searches for ClassNode by its full name (original or alias name)
* <br>
Expand Down
Loading