From b6155afd32522ed278eaac8a76d864134c2806b0 Mon Sep 17 00:00:00 2001 From: LanBaiCode <72244576+LanBaiCode@users.noreply.github.com> Date: Tue, 12 Dec 2023 01:14:10 +0800 Subject: [PATCH] fix(gui): use correct type for generic params in Xposed snippet (PR #2057) * Fix: Resolved an issue with incorrectly generated xposedMethodSnippet when the parameter type is generic. Add: Introduced xposedGenerateFieldSnippet. * fix code format * Fixed: Resolved the issue where Xposed code generation was incorrect when dealing with generic parameters and alias fields. --------- Co-authored-by: skylot <118523+skylot@users.noreply.github.com> --- .../java/jadx/gui/ui/codearea/XposedAction.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jadx-gui/src/main/java/jadx/gui/ui/codearea/XposedAction.java b/jadx-gui/src/main/java/jadx/gui/ui/codearea/XposedAction.java index 956dcaef2..e8e51414c 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/codearea/XposedAction.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/codearea/XposedAction.java @@ -101,11 +101,20 @@ public class XposedAction extends JNodeAction { return String.format(xposedFormatStr, xposedMethod, rawClassName, methodName); } String params = mthArgs.stream() - .map(type -> (type.isGeneric() ? type.getObject() : type) + ".class, ") + .map(type -> fixTypeContent(type) + ".class, ") .collect(Collectors.joining()); return String.format(xposedFormatStr, xposedMethod, rawClassName, methodName + params); } + private String fixTypeContent(ArgType type) { + if (type.isGeneric()) { + return type.getObject(); + } else if (type.isGenericType() && type.isObject() && type.isTypeKnown()) { + return "Object"; + } + return type.toString(); + } + private String generateClassSnippet(JClass jc) { JavaClass javaClass = jc.getCls(); String rawClassName = javaClass.getRawName(); @@ -120,6 +129,6 @@ public class XposedAction extends JNodeAction { String isStatic = javaField.getAccessFlags().isStatic() ? "Static" : ""; String type = PRIMITIVE_TYPE_MAPPING.getOrDefault(javaField.getFieldNode().getType().toString(), "Object"); String xposedMethod = "XposedHelpers.get" + isStatic + type + "Field"; - return String.format("%s(/*runtimeObject*/, \"%s\");", xposedMethod, javaField.getName()); + return String.format("%s(/*runtimeObject*/, \"%s\");", xposedMethod, javaField.getFieldNode().getFieldInfo().getName()); } }