Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
4e4c7f7d
J
jadx
项目概览
Quincy379
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
4e4c7f7d
编写于
9月 24, 2020
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: more visibility checks for @Override (#984)
Signed-off-by:
N
Skylot
<
skylot@gmail.com
>
上级
33f2c3f2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
109 addition
and
8 deletion
+109
-8
jadx-core/src/main/java/jadx/core/dex/visitors/OverrideMethodVisitor.java
...in/java/jadx/core/dex/visitors/OverrideMethodVisitor.java
+21
-8
jadx-core/src/test/java/jadx/tests/integration/others/TestOverridePackagePrivateMethod.java
.../integration/others/TestOverridePackagePrivateMethod.java
+67
-0
jadx-core/src/test/smali/others/TestOverridePackagePrivateMethod/A.smali
...est/smali/others/TestOverridePackagePrivateMethod/A.smali
+7
-0
jadx-core/src/test/smali/others/TestOverridePackagePrivateMethod/B.smali
...est/smali/others/TestOverridePackagePrivateMethod/B.smali
+7
-0
jadx-core/src/test/smali/others/TestOverridePackagePrivateMethod/C.smali
...est/smali/others/TestOverridePackagePrivateMethod/C.smali
+7
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/OverrideMethodVisitor.java
浏览文件 @
4e4c7f7d
...
...
@@ -31,14 +31,13 @@ public class OverrideMethodVisitor extends AbstractVisitor {
@Override
public
boolean
visit
(
ClassNode
cls
)
throws
JadxException
{
RootNode
root
=
cls
.
root
();
List
<
ArgType
>
superTypes
=
collectSuperTypes
(
cls
);
for
(
MethodNode
mth
:
cls
.
getMethods
())
{
if
(
mth
.
isConstructor
()
||
mth
.
getAccessFlags
().
isStatic
())
{
continue
;
}
String
signature
=
mth
.
getMethodInfo
().
makeSignature
(
false
);
List
<
IMethodDetails
>
overrideList
=
collectOverrideMethods
(
root
,
superTypes
,
signature
);
List
<
IMethodDetails
>
overrideList
=
collectOverrideMethods
(
cls
,
superTypes
,
signature
);
if
(!
overrideList
.
isEmpty
())
{
mth
.
addAttr
(
new
MethodOverrideAttr
(
overrideList
));
fixMethodReturnType
(
mth
,
overrideList
,
superTypes
);
...
...
@@ -48,15 +47,14 @@ public class OverrideMethodVisitor extends AbstractVisitor {
return
true
;
}
private
List
<
IMethodDetails
>
collectOverrideMethods
(
RootNode
root
,
List
<
ArgType
>
superTypes
,
String
signature
)
{
private
List
<
IMethodDetails
>
collectOverrideMethods
(
ClassNode
cls
,
List
<
ArgType
>
superTypes
,
String
signature
)
{
List
<
IMethodDetails
>
overrideList
=
new
ArrayList
<>();
for
(
ArgType
superType
:
superTypes
)
{
ClassNode
classNode
=
root
.
resolveClass
(
superType
);
ClassNode
classNode
=
cls
.
root
()
.
resolveClass
(
superType
);
if
(
classNode
!=
null
)
{
for
(
MethodNode
mth
:
classNode
.
getMethods
())
{
AccessInfo
accessFlags
=
mth
.
getAccessFlags
();
if
(!
accessFlags
.
isPrivate
()
&&
!
accessFlags
.
isStatic
())
{
if
(!
mth
.
getAccessFlags
().
isStatic
()
&&
isMethodVisibleInCls
(
mth
,
cls
))
{
String
mthShortId
=
mth
.
getMethodInfo
().
getShortId
();
if
(
mthShortId
.
startsWith
(
signature
))
{
overrideList
.
add
(
mth
);
...
...
@@ -64,7 +62,7 @@ public class OverrideMethodVisitor extends AbstractVisitor {
}
}
}
else
{
ClspClass
clsDetails
=
root
.
getClsp
().
getClsDetails
(
superType
);
ClspClass
clsDetails
=
cls
.
root
()
.
getClsp
().
getClsDetails
(
superType
);
if
(
clsDetails
!=
null
)
{
Map
<
String
,
ClspMethod
>
methodsMap
=
clsDetails
.
getMethodsMap
();
for
(
Map
.
Entry
<
String
,
ClspMethod
>
entry
:
methodsMap
.
entrySet
())
{
...
...
@@ -79,6 +77,21 @@ public class OverrideMethodVisitor extends AbstractVisitor {
return
overrideList
;
}
/**
* NOTE: Simplified version of method from {@link ModVisitor#isFieldVisibleInMethod}
*/
private
boolean
isMethodVisibleInCls
(
MethodNode
superMth
,
ClassNode
cls
)
{
AccessInfo
accessFlags
=
superMth
.
getAccessFlags
();
if
(
accessFlags
.
isPrivate
())
{
return
false
;
}
if
(
accessFlags
.
isPublic
()
||
accessFlags
.
isProtected
())
{
return
true
;
}
// package-private
return
Objects
.
equals
(
superMth
.
getParentClass
().
getPackage
(),
cls
.
getPackage
());
}
private
List
<
ArgType
>
collectSuperTypes
(
ClassNode
cls
)
{
Map
<
String
,
ArgType
>
superTypes
=
new
HashMap
<>();
collectSuperTypes
(
cls
,
superTypes
);
...
...
jadx-core/src/test/java/jadx/tests/integration/others/TestOverridePackagePrivateMethod.java
0 → 100644
浏览文件 @
4e4c7f7d
package
jadx.tests.integration.others
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestOverridePackagePrivateMethod
extends
SmaliTest
{
// @formatter:off
/*
-----------------------------------------------------------
package test;
public class A {
void a() { // package-private
}
}
-----------------------------------------------------------
package test;
public class B extends A {
@Override // test.A
public void a() {
}
}
-----------------------------------------------------------
package other;
import test.A;
public class C extends A {
// No @Override here
public void a() {
}
}
-----------------------------------------------------------
*/
// @formatter:on
@NotYetImplemented
(
"Don't change access modifiers if not needed"
)
@Test
public
void
test
()
{
commonChecks
();
}
@Test
public
void
testDontChangeAccFlags
()
{
getArgs
().
setRespectBytecodeAccModifiers
(
true
);
commonChecks
();
}
private
void
commonChecks
()
{
List
<
ClassNode
>
classes
=
loadFromSmaliFiles
();
assertThat
(
searchCls
(
classes
,
"test.A"
))
.
code
()
.
doesNotContain
(
"/* access modifiers changed"
)
.
containsLine
(
1
,
"void a() {"
);
assertThat
(
searchCls
(
classes
,
"test.B"
)).
code
().
containsOne
(
"@Override"
);
assertThat
(
searchCls
(
classes
,
"other.C"
)).
code
().
doesNotContain
(
"@Override"
);
}
}
jadx-core/src/test/smali/others/TestOverridePackagePrivateMethod/A.smali
0 → 100644
浏览文件 @
4e4c7f7d
.class public Ltest/A;
.super Ljava/lang/Object;
.method a()V # package-private
.locals 1
return-void
.end method
jadx-core/src/test/smali/others/TestOverridePackagePrivateMethod/B.smali
0 → 100644
浏览文件 @
4e4c7f7d
.class public Ltest/B;
.super Ltest/A;
.method public a()V
.locals 1
return-void
.end method
jadx-core/src/test/smali/others/TestOverridePackagePrivateMethod/C.smali
0 → 100644
浏览文件 @
4e4c7f7d
.class public Lother/C;
.super Ltest/A;
.method public a()V
.locals 1
return-void
.end method
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录