Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
2cf28eb2
J
jadx
项目概览
2301_76393173
/
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,发现更多精彩内容 >>
提交
2cf28eb2
编写于
2月 25, 2014
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: fix loop detection
上级
2b300341
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
117 addition
and
4 deletion
+117
-4
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+9
-3
jadx-core/src/test/java/jadx/tests/internal/loops/TestLoopCondition.java
...est/java/jadx/tests/internal/loops/TestLoopCondition.java
+1
-1
jadx-core/src/test/java/jadx/tests/internal/loops/TestLoopDetection.java
...est/java/jadx/tests/internal/loops/TestLoopDetection.java
+37
-0
jadx-core/src/test/java/jadx/tests/internal/loops/TestNestedLoops.java
.../test/java/jadx/tests/internal/loops/TestNestedLoops.java
+51
-0
jadx-samples/src/main/java/jadx/samples/TestCF3.java
jadx-samples/src/main/java/jadx/samples/TestCF3.java
+19
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
浏览文件 @
2cf28eb2
...
...
@@ -244,7 +244,6 @@ public class RegionMaker {
}
}
stack
.
push
(
loopRegion
);
curRegion
.
getSubBlocks
().
add
(
loopRegion
);
exitBlocks
.
remove
(
condBlock
);
...
...
@@ -290,9 +289,12 @@ public class RegionMaker {
out
=
(
bThen
==
loopStart
?
bElse
:
bThen
);
loopStart
.
getAttributes
().
remove
(
AttributeType
.
LOOP
);
stack
.
push
(
loopRegion
);
stack
.
addExit
(
loop
.
getEnd
());
loopRegion
.
setBody
(
makeRegion
(
loopStart
,
stack
));
loopStart
.
getAttributes
().
add
(
loop
);
stack
.
pop
();
}
else
{
Set
<
BlockNode
>
loopBlocks
=
loop
.
getLoopBlocks
();
BlockNode
loopBody
=
null
;
...
...
@@ -308,14 +310,18 @@ public class RegionMaker {
out
=
selectOther
(
loopBody
,
condBlock
.
getSuccessors
());
AttributesList
outAttrs
=
out
.
getAttributes
();
if
(
outAttrs
.
contains
(
AttributeFlag
.
LOOP_START
)
&&
outAttrs
.
get
(
AttributeType
.
LOOP
)
!=
loop
)
{
&&
outAttrs
.
get
(
AttributeType
.
LOOP
)
!=
loop
&&
stack
.
peekRegion
()
instanceof
LoopRegion
&&
RegionUtils
.
isRegionContainsBlock
(
stack
.
peekRegion
(),
out
))
{
// exit to outer loop which already processed
out
=
null
;
}
stack
.
push
(
loopRegion
);
stack
.
addExit
(
out
);
loopRegion
.
setBody
(
makeRegion
(
loopBody
,
stack
));
stack
.
pop
();
}
stack
.
pop
();
return
out
;
}
...
...
jadx-core/src/test/java/jadx/tests/internal/TestLoopCondition.java
→
jadx-core/src/test/java/jadx/tests/internal/
loops/
TestLoopCondition.java
浏览文件 @
2cf28eb2
package
jadx.tests.internal
;
package
jadx.tests.internal
.loops
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
...
...
jadx-core/src/test/java/jadx/tests/internal/loops/TestLoopDetection.java
0 → 100644
浏览文件 @
2cf28eb2
package
jadx.tests.internal.loops
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestLoopDetection
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
void
test
(
int
[]
a
,
int
b
)
{
int
i
=
0
;
while
(
i
<
a
.
length
&&
i
<
b
)
{
a
[
i
]++;
i
++;
}
while
(
i
<
a
.
length
)
{
a
[
i
]--;
i
++;
}
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"while (i < a.length && i < b) {"
));
assertThat
(
code
,
containsString
(
"while (i < a.length) {"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/loops/TestNestedLoops.java
0 → 100644
浏览文件 @
2cf28eb2
package
jadx.tests.internal.loops
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
java.util.Iterator
;
import
java.util.List
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestNestedLoops
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
void
test
(
List
<
String
>
l1
,
List
<
String
>
l2
)
{
Iterator
<
String
>
it1
=
l1
.
iterator
();
while
(
it1
.
hasNext
())
{
String
s1
=
it1
.
next
();
Iterator
<
String
>
it2
=
l2
.
iterator
();
while
(
it2
.
hasNext
())
{
String
s2
=
it2
.
next
();
if
(
s1
.
equals
(
s2
))
{
if
(
s1
.
length
()
==
5
)
{
l2
.
add
(
s1
);
}
else
{
l1
.
remove
(
s2
);
}
}
}
}
if
(
l2
.
size
()
>
0
)
{
l1
.
clear
();
}
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"while (it1.hasNext()) {"
));
assertThat
(
code
,
containsString
(
"while (it2.hasNext()) {"
));
assertThat
(
code
,
containsString
(
"if (s1.equals(s2)) {"
));
assertThat
(
code
,
containsString
(
"l2.add(s1);"
));
}
}
jadx-samples/src/main/java/jadx/samples/TestCF3.java
浏览文件 @
2cf28eb2
...
...
@@ -87,6 +87,23 @@ public class TestCF3 extends AbstractTest {
return
j
>
10
;
}
private
int
testLoops
(
int
[]
a
,
int
b
)
{
int
i
=
0
;
while
(
i
<
a
.
length
&&
i
<
b
)
{
a
[
i
]++;
i
++;
}
while
(
i
<
a
.
length
)
{
a
[
i
]--;
i
++;
}
int
sum
=
0
;
for
(
int
e
:
a
)
{
sum
+=
e
;
}
return
sum
;
}
public
static
boolean
testLabeledBreakContinue
()
{
String
searchMe
=
"Look for a substring in me"
;
String
substring
=
"sub"
;
...
...
@@ -227,6 +244,8 @@ public class TestCF3 extends AbstractTest {
assertEquals
(
testComplexIfInLoop3
(
6
),
6
);
assertEquals
(
testComplexIfInLoop3
(
8
),
24
);
assertEquals
(
testLoops
(
new
int
[]{
1
,
2
,
3
,
4
,
5
,
6
},
2
),
19
);
assertTrue
(
testInline
()
>
20
);
assertTrue
(
testInline2
());
return
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录