Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colcode
jadx
提交
e1b7d361
J
jadx
项目概览
colcode
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
e1b7d361
编写于
12月 09, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: check full signature for search method override (#1743)
上级
12ef29be
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
116 addition
and
3 deletion
+116
-3
jadx-core/src/main/java/jadx/core/dex/visitors/OverrideMethodVisitor.java
...in/java/jadx/core/dex/visitors/OverrideMethodVisitor.java
+23
-3
jadx-core/src/test/java/jadx/tests/integration/others/TestOverrideWithSameName.java
...dx/tests/integration/others/TestOverrideWithSameName.java
+67
-0
jadx-core/src/test/smali/others/TestOverrideWithSameName/A.smali
...re/src/test/smali/others/TestOverrideWithSameName/A.smali
+8
-0
jadx-core/src/test/smali/others/TestOverrideWithSameName/B.smali
...re/src/test/smali/others/TestOverrideWithSameName/B.smali
+10
-0
jadx-core/src/test/smali/others/TestOverrideWithSameName/C.smali
...re/src/test/smali/others/TestOverrideWithSameName/C.smali
+8
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/OverrideMethodVisitor.java
浏览文件 @
e1b7d361
...
...
@@ -90,7 +90,7 @@ public class OverrideMethodVisitor extends AbstractVisitor {
for
(
ArgType
superType
:
superData
.
getSuperTypes
())
{
ClassNode
classNode
=
mth
.
root
().
resolveClass
(
superType
);
if
(
classNode
!=
null
)
{
MethodNode
ovrdMth
=
searchOverriddenMethod
(
classNode
,
signature
);
MethodNode
ovrdMth
=
searchOverriddenMethod
(
classNode
,
mth
,
signature
);
if
(
ovrdMth
!=
null
)
{
if
(
isMethodVisibleInCls
(
ovrdMth
,
cls
))
{
overrideList
.
add
(
ovrdMth
);
...
...
@@ -107,6 +107,8 @@ public class OverrideMethodVisitor extends AbstractVisitor {
Map
<
String
,
ClspMethod
>
methodsMap
=
clsDetails
.
getMethodsMap
();
for
(
Map
.
Entry
<
String
,
ClspMethod
>
entry
:
methodsMap
.
entrySet
())
{
String
mthShortId
=
entry
.
getKey
();
// do not check full signature, classpath methods can be trusted
// i.e. doesn't contain methods with same signature in one class
if
(
mthShortId
.
startsWith
(
signature
))
{
overrideList
.
add
(
entry
.
getValue
());
break
;
...
...
@@ -130,12 +132,30 @@ public class OverrideMethodVisitor extends AbstractVisitor {
}
@Nullable
private
MethodNode
searchOverriddenMethod
(
ClassNode
cls
,
String
signature
)
{
private
MethodNode
searchOverriddenMethod
(
ClassNode
cls
,
MethodNode
mth
,
String
signature
)
{
// search by exact full signature (with return value) to fight obfuscation (see test
// 'TestOverrideWithSameName')
String
shortId
=
mth
.
getMethodInfo
().
getShortId
();
for
(
MethodNode
supMth
:
cls
.
getMethods
())
{
if
(
!
supMth
.
getAccessFlags
().
isStatic
()
&&
supMth
.
getMethodInfo
().
getShortId
().
startsWith
(
signature
))
{
if
(
supMth
.
getMethodInfo
().
getShortId
().
equals
(
shortId
)
&&
!
supMth
.
getAccessFlags
().
isStatic
(
))
{
return
supMth
;
}
}
// search by signature without return value and check if return value is wider type
for
(
MethodNode
supMth
:
cls
.
getMethods
())
{
if
(
supMth
.
getMethodInfo
().
getShortId
().
startsWith
(
signature
)
&&
!
supMth
.
getAccessFlags
().
isStatic
())
{
TypeCompare
typeCompare
=
cls
.
root
().
getTypeCompare
();
ArgType
supRetType
=
supMth
.
getMethodInfo
().
getReturnType
();
ArgType
mthRetType
=
mth
.
getMethodInfo
().
getReturnType
();
TypeCompareEnum
res
=
typeCompare
.
compareTypes
(
supRetType
,
mthRetType
);
if
(
res
.
isWider
())
{
return
supMth
;
}
if
(
res
==
TypeCompareEnum
.
UNKNOWN
||
res
==
TypeCompareEnum
.
CONFLICT
)
{
mth
.
addDebugComment
(
"Possible override for method "
+
supMth
.
getMethodInfo
().
getFullId
());
}
}
}
return
null
;
}
...
...
jadx-core/src/test/java/jadx/tests/integration/others/TestOverrideWithSameName.java
0 → 100644
浏览文件 @
e1b7d361
package
jadx.tests.integration.others
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
@SuppressWarnings
(
"CommentedOutCode"
)
public
class
TestOverrideWithSameName
extends
SmaliTest
{
//@formatter:off
/*
interface A {
B a();
C a();
}
abstract class B implements A {
@Override
public C a() {
return null;
}
}
public class C extends B {
@Override
public B a() {
return null;
}
}
*/
//@formatter:on
@Test
public
void
test
()
{
List
<
ClassNode
>
clsNodes
=
loadFromSmaliFiles
();
assertThat
(
searchCls
(
clsNodes
,
"test.A"
))
.
code
()
.
containsOne
(
"C mo0a();"
)
// assume second method was renamed
.
doesNotContain
(
"@Override"
);
ClassNode
bCls
=
searchCls
(
clsNodes
,
"test.B"
);
assertThat
(
bCls
)
.
code
()
.
containsOne
(
"C mo0a() {"
)
.
containsOne
(
"@Override"
);
assertThat
(
getMethod
(
bCls
,
"a"
).
get
(
AType
.
METHOD_OVERRIDE
).
getOverrideList
())
.
singleElement
()
.
satisfies
(
mth
->
assertThat
(
mth
.
getMethodInfo
().
getDeclClass
().
getShortName
()).
isEqualTo
(
"A"
));
ClassNode
cCls
=
searchCls
(
clsNodes
,
"test.C"
);
assertThat
(
cCls
)
.
code
()
.
containsOne
(
"B a() {"
)
.
containsOne
(
"@Override"
);
assertThat
(
getMethod
(
cCls
,
"a"
).
get
(
AType
.
METHOD_OVERRIDE
).
getOverrideList
())
.
singleElement
()
.
satisfies
(
mth
->
assertThat
(
mth
.
getMethodInfo
().
getDeclClass
().
getShortName
()).
isEqualTo
(
"A"
));
}
}
jadx-core/src/test/smali/others/TestOverrideWithSameName/A.smali
0 → 100644
浏览文件 @
e1b7d361
.class interface abstract Ltest/A;
.super Ljava/lang/Object;
.method public abstract a()Ltest/B;
.end method
.method public abstract a()Ltest/C;
.end method
jadx-core/src/test/smali/others/TestOverrideWithSameName/B.smali
0 → 100644
浏览文件 @
e1b7d361
.class abstract Ltest/B;
.super Ljava/lang/Object;
.implements Ltest/A;
.method public a()Ltest/C;
.registers 2
const/4 v0, 0x0
return-object v0
.end method
jadx-core/src/test/smali/others/TestOverrideWithSameName/C.smali
0 → 100644
浏览文件 @
e1b7d361
.class public Ltest/C;
.super Ltest/B;
.method public a()Ltest/B;
.registers 2
const/4 v0, 0x0
return-object v0
.end method
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录