Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
d20cd43a
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,发现更多精彩内容 >>
提交
d20cd43a
编写于
6月 02, 2018
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: fix loop handling
上级
7b4321ec
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
94 addition
and
6 deletion
+94
-6
jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java
...va/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java
+18
-6
jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition5.java
...java/jadx/tests/integration/loops/TestLoopCondition5.java
+45
-0
jadx-core/src/test/smali/loops/TestLoopCondition5.smali
jadx-core/src/test/smali/loops/TestLoopCondition5.smali
+31
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java
浏览文件 @
d20cd43a
...
@@ -21,6 +21,7 @@ import jadx.core.dex.nodes.MethodNode;
...
@@ -21,6 +21,7 @@ import jadx.core.dex.nodes.MethodNode;
import
jadx.core.dex.trycatch.CatchAttr
;
import
jadx.core.dex.trycatch.CatchAttr
;
import
jadx.core.dex.visitors.AbstractVisitor
;
import
jadx.core.dex.visitors.AbstractVisitor
;
import
jadx.core.utils.BlockUtils
;
import
jadx.core.utils.BlockUtils
;
import
jadx.core.utils.exceptions.JadxOverflowException
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
import
static
jadx
.
core
.
dex
.
visitors
.
blocksmaker
.
BlockSplitter
.
connect
;
import
static
jadx
.
core
.
dex
.
visitors
.
blocksmaker
.
BlockSplitter
.
connect
;
...
@@ -68,11 +69,16 @@ public class BlockProcessor extends AbstractVisitor {
...
@@ -68,11 +69,16 @@ public class BlockProcessor extends AbstractVisitor {
processNestedLoops
(
mth
);
processNestedLoops
(
mth
);
}
}
private
static
boolean
removeEmptyBlock
(
MethodNode
mth
,
BlockNode
block
)
{
private
static
boolean
canRemoveBlock
(
BlockNode
block
)
{
if
(
block
.
getInstructions
().
isEmpty
()
return
block
.
getInstructions
().
isEmpty
()
&&
!
block
.
isSynthetic
()
&&
!
block
.
isSynthetic
()
&&
block
.
isAttrStorageEmpty
()
&&
block
.
isAttrStorageEmpty
()
&&
block
.
getSuccessors
().
size
()
<=
1
)
{
&&
block
.
getSuccessors
().
size
()
<=
1
&&
!
block
.
getPredecessors
().
isEmpty
();
}
private
static
boolean
removeEmptyBlock
(
BlockNode
block
)
{
if
(
canRemoveBlock
(
block
))
{
LOG
.
debug
(
"Removing empty block: {}"
,
block
);
LOG
.
debug
(
"Removing empty block: {}"
,
block
);
if
(
block
.
getSuccessors
().
size
()
==
1
)
{
if
(
block
.
getSuccessors
().
size
()
==
1
)
{
BlockNode
successor
=
block
.
getSuccessors
().
get
(
0
);
BlockNode
successor
=
block
.
getSuccessors
().
get
(
0
);
...
@@ -245,7 +251,13 @@ public class BlockProcessor extends AbstractVisitor {
...
@@ -245,7 +251,13 @@ public class BlockProcessor extends AbstractVisitor {
exit
.
setDomFrontier
(
EMPTY
);
exit
.
setDomFrontier
(
EMPTY
);
}
}
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
computeBlockDF
(
mth
,
block
);
try
{
computeBlockDF
(
mth
,
block
);
}
catch
(
StackOverflowError
e
)
{
throw
new
JadxOverflowException
(
"Failed compute block dominance frontier"
);
}
catch
(
Exception
e
)
{
throw
new
JadxRuntimeException
(
"Failed compute block dominance frontier"
,
e
);
}
}
}
}
}
...
@@ -253,7 +265,7 @@ public class BlockProcessor extends AbstractVisitor {
...
@@ -253,7 +265,7 @@ public class BlockProcessor extends AbstractVisitor {
if
(
block
.
getDomFrontier
()
!=
null
)
{
if
(
block
.
getDomFrontier
()
!=
null
)
{
return
;
return
;
}
}
block
.
getDominatesOn
().
forEach
(
c
->
computeBlockDF
(
mth
,
c
));
block
.
getDominatesOn
().
forEach
(
domBlock
->
computeBlockDF
(
mth
,
domBlock
));
List
<
BlockNode
>
blocks
=
mth
.
getBasicBlocks
();
List
<
BlockNode
>
blocks
=
mth
.
getBasicBlocks
();
BitSet
domFrontier
=
null
;
BitSet
domFrontier
=
null
;
for
(
BlockNode
s
:
block
.
getSuccessors
())
{
for
(
BlockNode
s
:
block
.
getSuccessors
())
{
...
@@ -367,7 +379,7 @@ public class BlockProcessor extends AbstractVisitor {
...
@@ -367,7 +379,7 @@ public class BlockProcessor extends AbstractVisitor {
}
}
}
}
for
(
BlockNode
basicBlock
:
basicBlocks
)
{
for
(
BlockNode
basicBlock
:
basicBlocks
)
{
if
(
removeEmptyBlock
(
mth
,
basicBlock
))
{
if
(
removeEmptyBlock
(
basicBlock
))
{
changed
=
true
;
changed
=
true
;
}
}
}
}
...
...
jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition5.java
0 → 100644
浏览文件 @
d20cd43a
package
jadx.tests.integration.loops
;
import
org.junit.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
countString
;
import
static
org
.
hamcrest
.
Matchers
.
anyOf
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestLoopCondition5
extends
SmaliTest
{
public
static
class
TestCls
{
private
static
int
lastIndexOf
(
int
[]
array
,
int
target
,
int
start
,
int
end
)
{
for
(
int
i
=
end
-
1
;
i
>=
start
;
i
--)
{
if
(
array
[
i
]
==
target
)
{
return
i
;
}
}
return
-
1
;
}
}
@Test
public
void
test0
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"for ("
));
assertThat
(
code
,
containsOne
(
"return -1;"
));
assertThat
(
code
,
countString
(
2
,
"return "
));
}
@Test
public
void
test1
()
{
ClassNode
cls
=
getClassNodeFromSmaliWithPath
(
"loops"
,
"TestLoopCondition5"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
anyOf
(
containsOne
(
"for ("
),
containsOne
(
"while (true) {"
)));
assertThat
(
code
,
containsOne
(
"return -1;"
));
assertThat
(
code
,
countString
(
2
,
"return "
));
}
}
jadx-core/src/test/smali/loops/TestLoopCondition5.smali
0 → 100644
浏览文件 @
d20cd43a
.class public LTestLoopCondition5;
.super Ljava/lang/Object;
.source "TestLoopCondition5.java"
.method private static lastIndexOf([IIII)I
.locals 1
add-int/lit8 p3, p3, -0x1
:goto_0
const/4 v0, -0x1
if-lt p3, p2, :cond_1
.line 219
aget v0, p0, p3
if-ne v0, p1, :cond_0
return p3
:cond_0
add-int/lit8 p3, p3, -0x1
goto :goto_0
:cond_1
move p3, v0
return p3
.end method
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录