Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
af2f14f8
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,发现更多精彩内容 >>
未验证
提交
af2f14f8
编写于
2月 14, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: prevent endless loop in anonymous class analysis (#1382)
上级
fe248d70
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
63 addition
and
11 deletion
+63
-11
jadx-core/src/main/java/jadx/core/dex/visitors/ProcessAnonymous.java
...rc/main/java/jadx/core/dex/visitors/ProcessAnonymous.java
+63
-11
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/ProcessAnonymous.java
浏览文件 @
af2f14f8
package
jadx.core.dex.visitors
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.jetbrains.annotations.Nullable
;
...
...
@@ -88,6 +91,22 @@ public class ProcessAnonymous extends AbstractVisitor {
}
}
private
static
void
undoAnonymousMark
(
ClassNode
cls
)
{
AnonymousClassAttr
attr
=
cls
.
get
(
AType
.
ANONYMOUS_CLASS
);
ClassNode
outerCls
=
attr
.
getOuterCls
();
cls
.
setDependencies
(
ListUtils
.
safeAdd
(
cls
.
getDependencies
(),
outerCls
.
getTopParentClass
()));
outerCls
.
setUseIn
(
ListUtils
.
safeAdd
(
outerCls
.
getUseIn
(),
cls
));
cls
.
remove
(
AType
.
ANONYMOUS_CLASS
);
cls
.
remove
(
AFlag
.
DONT_GENERATE
);
for
(
MethodNode
mth
:
cls
.
getMethods
())
{
if
(
mth
.
isConstructor
())
{
mth
.
remove
(
AFlag
.
ANONYMOUS_CONSTRUCTOR
);
}
}
cls
.
addDebugComment
(
"Anonymous mark cleared"
);
}
private
void
mergeAnonymousDeps
(
RootNode
root
)
{
// Collect edges to build bidirectional tree:
// inline edge: anonymous -> outer (one-to-one)
...
...
@@ -98,8 +117,13 @@ public class ProcessAnonymous extends AbstractVisitor {
AnonymousClassAttr
attr
=
anonymousCls
.
get
(
AType
.
ANONYMOUS_CLASS
);
if
(
attr
!=
null
)
{
ClassNode
outerCls
=
attr
.
getOuterCls
();
useMap
.
computeIfAbsent
(
outerCls
,
k
->
new
ArrayList
<>()).
add
(
anonymousCls
);
useMap
.
putIfAbsent
(
anonymousCls
,
new
ArrayList
<>());
// put leaf explicitly
List
<
ClassNode
>
list
=
useMap
.
get
(
outerCls
);
if
(
list
==
null
||
list
.
isEmpty
())
{
list
=
new
ArrayList
<>(
2
);
useMap
.
put
(
outerCls
,
list
);
}
list
.
add
(
anonymousCls
);
useMap
.
putIfAbsent
(
anonymousCls
,
Collections
.
emptyList
());
// put leaf explicitly
inlineMap
.
put
(
anonymousCls
,
outerCls
);
}
}
...
...
@@ -107,26 +131,54 @@ public class ProcessAnonymous extends AbstractVisitor {
return
;
}
// starting from leaf process deps in nodes up to root
Set
<
ClassNode
>
added
=
new
HashSet
<>();
useMap
.
forEach
((
key
,
list
)
->
{
if
(
list
.
isEmpty
())
{
updateDeps
(
key
,
inlineMap
);
added
.
clear
();
updateDeps
(
key
,
inlineMap
,
added
);
}
});
for
(
ClassNode
cls
:
root
.
getClasses
())
{
List
<
ClassNode
>
deps
=
cls
.
getCodegenDeps
();
if
(
deps
.
size
()
>
1
)
{
// distinct sorted dep, reusing collections to reduce memory allocations :)
added
.
clear
();
added
.
addAll
(
deps
);
deps
.
clear
();
deps
.
addAll
(
added
);
Collections
.
sort
(
deps
);
}
}
}
private
void
updateDeps
(
ClassNode
leafCls
,
Map
<
ClassNode
,
ClassNode
>
inlineMap
)
{
List
<
ClassNode
>
list
=
new
ArrayList
<>()
;
private
void
updateDeps
(
ClassNode
leafCls
,
Map
<
ClassNode
,
ClassNode
>
inlineMap
,
Set
<
ClassNode
>
added
)
{
ClassNode
topNode
;
ClassNode
current
=
leafCls
;
while
(
current
!=
null
)
{
list
.
add
(
current
.
getTopParentClass
());
current
=
inlineMap
.
get
(
current
);
while
(
true
)
{
if
(!
added
.
add
(
current
))
{
current
.
addWarnComment
(
"Loop in anonymous inline: "
+
current
+
", path: "
+
added
);
added
.
forEach
(
ProcessAnonymous:
:
undoAnonymousMark
);
return
;
}
ClassNode
next
=
inlineMap
.
get
(
current
);
if
(
next
==
null
)
{
topNode
=
current
.
getTopParentClass
();
break
;
}
current
=
next
;
}
if
(
list
.
size
()
<=
2
)
{
if
(
added
.
size
()
<=
2
)
{
// first level deps already processed
return
;
}
ClassNode
topNode
=
list
.
remove
(
list
.
size
()
-
1
);
topNode
.
setCodegenDeps
(
ListUtils
.
distinctMergeSortedLists
(
topNode
.
getCodegenDeps
(),
list
));
List
<
ClassNode
>
deps
=
topNode
.
getCodegenDeps
();
if
(
deps
.
isEmpty
())
{
deps
=
new
ArrayList
<>(
added
.
size
());
topNode
.
setCodegenDeps
(
deps
);
}
for
(
ClassNode
add
:
added
)
{
deps
.
add
(
add
.
getTopParentClass
());
}
}
private
static
boolean
canBeAnonymous
(
ClassNode
cls
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录