Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
0b2e2ed0
J
jadx
项目概览
keyescgm
/
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,发现更多精彩内容 >>
未验证
提交
0b2e2ed0
编写于
6月 05, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: improve class search for super call (#1512)
上级
81231206
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
83 addition
and
35 deletion
+83
-35
jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java
jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java
+3
-0
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+37
-33
jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java
...e/src/test/java/jadx/tests/api/compiler/TestCompiler.java
+1
-2
jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvokeUnknown.java
...jadx/tests/integration/invoke/TestSuperInvokeUnknown.java
+42
-0
未找到文件。
jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java
浏览文件 @
0b2e2ed0
...
...
@@ -203,6 +203,9 @@ public class ClspGraph {
if
(
isNew
)
{
addSuperTypes
(
parentCls
,
result
);
}
}
else
{
// parent type is unknown
result
.
add
(
parentType
.
getObject
());
}
}
}
...
...
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
浏览文件 @
0b2e2ed0
...
...
@@ -807,14 +807,9 @@ public class InsnGen {
break
;
case
SUPER:
ClassInfo
superCallCls
=
getClassForSuperCall
(
code
,
callMth
);
if
(
superCallCls
!=
null
)
{
useClass
(
code
,
superCallCls
);
code
.
add
(
'.'
);
}
// use 'super' instead 'this' in 0 arg
code
.
add
(
"super"
).
add
(
'.'
);
k
++;
callSuper
(
code
,
callMth
);
k
++;
// use 'super' instead 'this' in 0 arg
code
.
add
(
'.'
);
break
;
case
STATIC:
...
...
@@ -965,34 +960,43 @@ public class InsnGen {
code
.
startLine
(
'}'
);
}
@Nullable
private
ClassInfo
getClassForSuperCall
(
ICodeWriter
code
,
MethodInfo
callMth
)
{
ClassNode
useCls
=
mth
.
getParentClass
();
ClassInfo
insnCls
=
useCls
.
getClassInfo
();
ClassInfo
declClass
=
callMth
.
getDeclClass
();
if
(
insnCls
.
equals
(
declClass
))
{
return
null
;
private
void
callSuper
(
ICodeWriter
code
,
MethodInfo
callMth
)
{
ClassInfo
superCallCls
=
getClassForSuperCall
(
callMth
);
if
(
superCallCls
==
null
)
{
// unknown class, add comment to keep that info
code
.
add
(
"super/*"
).
add
(
callMth
.
getDeclClass
().
getFullName
()).
add
(
"*/"
);
return
;
}
ClassNode
topClass
=
useCls
.
getTopParentClass
();
if
(
topClass
.
getClassInfo
().
equals
(
declClass
))
{
return
declClass
;
ClassInfo
curClass
=
mth
.
getParentClass
().
getClassInfo
();
if
(
superCallCls
.
equals
(
curClass
))
{
code
.
add
(
"super"
);
return
;
}
// search call class
ClassNode
nextParent
=
useCls
;
do
{
ClassInfo
nextClsInfo
=
nextParent
.
getClassInfo
();
if
(
nextClsInfo
.
equals
(
declClass
)
||
ArgType
.
isInstanceOf
(
mth
.
root
(),
nextClsInfo
.
getType
(),
declClass
.
getType
()))
{
if
(
nextParent
==
useCls
)
{
return
null
;
}
return
nextClsInfo
;
}
nextParent
=
nextParent
.
getParentClass
();
}
while
(
nextParent
!=
null
&&
nextParent
!=
topClass
);
// use custom class
useClass
(
code
,
superCallCls
);
code
.
add
(
".super"
);
}
// search failed, just return parent class
return
useCls
.
getParentClass
().
getClassInfo
();
/**
* Search call class in super types of this
* and all parent classes (needed for inlined synthetic calls)
*/
@Nullable
private
ClassInfo
getClassForSuperCall
(
MethodInfo
callMth
)
{
ArgType
declClsType
=
callMth
.
getDeclClass
().
getType
();
ClassNode
parentNode
=
mth
.
getParentClass
();
while
(
true
)
{
ClassInfo
parentCls
=
parentNode
.
getClassInfo
();
if
(
ArgType
.
isInstanceOf
(
root
,
parentCls
.
getType
(),
declClsType
))
{
return
parentCls
;
}
ClassNode
nextParent
=
parentNode
.
getParentClass
();
if
(
nextParent
==
parentNode
)
{
// no parent, class not found
return
null
;
}
parentNode
=
nextParent
;
}
}
void
generateMethodArguments
(
ICodeWriter
code
,
BaseInvokeNode
insn
,
int
startArgNum
,
...
...
jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java
浏览文件 @
0b2e2ed0
...
...
@@ -11,7 +11,6 @@ import java.nio.file.Path;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Locale
;
import
javax.tools.DiagnosticListener
;
import
javax.tools.JavaCompiler
;
...
...
@@ -82,7 +81,7 @@ public class TestCompiler implements Closeable {
arguments
.
addAll
(
options
.
getArguments
());
DiagnosticListener
<?
super
JavaFileObject
>
diagnostic
=
diagObj
->
System
.
out
.
println
(
"Compiler diagnostic: "
+
diagObj
.
getMessage
(
Locale
.
ROOT
)
);
diagObj
->
System
.
out
.
println
(
"Compiler diagnostic: "
+
diagObj
);
Writer
out
=
new
PrintWriter
(
System
.
out
);
CompilationTask
compilerTask
=
compiler
.
getTask
(
out
,
fileManager
,
diagnostic
,
arguments
,
null
,
jfObjects
);
if
(
Boolean
.
FALSE
.
equals
(
compilerTask
.
call
()))
{
...
...
jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvokeUnknown.java
0 → 100644
浏览文件 @
0b2e2ed0
package
jadx.tests.integration.invoke
;
import
org.junit.jupiter.api.Test
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestSuperInvokeUnknown
extends
IntegrationTest
{
public
static
class
TestCls
{
public
static
class
BaseClass
{
public
int
doSomething
()
{
return
0
;
}
}
public
static
class
NestedClass
extends
BaseClass
{
@Override
public
int
doSomething
()
{
return
super
.
doSomething
();
}
}
}
@Test
public
void
test
()
{
disableCompilation
();
noDebugInfo
();
assertThat
(
getClassNode
(
TestCls
.
NestedClass
.
class
))
// BaseClass unknown
.
code
()
.
containsOne
(
"return super.doSomething();"
);
}
@Test
public
void
testTopCls
()
{
noDebugInfo
();
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
containsOne
(
"return super.doSomething();"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录