Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
24d22aaa
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,发现更多精彩内容 >>
提交
24d22aaa
编写于
5月 01, 2014
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: fix 'if' detection
上级
ebf78226
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
63 addition
and
56 deletion
+63
-56
jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java
+6
-6
jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java
...c/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java
+7
-5
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+42
-41
jadx-core/src/test/java/jadx/tests/internal/conditions/TestTernary2.java
...est/java/jadx/tests/internal/conditions/TestTernary2.java
+8
-4
未找到文件。
jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java
浏览文件 @
24d22aaa
...
...
@@ -72,20 +72,20 @@ public class BlockNode extends AttrNode implements IBlock {
private
static
List
<
BlockNode
>
cleanSuccessors
(
BlockNode
block
)
{
List
<
BlockNode
>
sucList
=
block
.
getSuccessors
();
List
<
BlockNode
>
nodes
=
new
ArrayList
<
BlockNode
>(
sucList
.
size
());
LoopAttr
loop
=
(
LoopAttr
)
block
.
getAttributes
().
get
(
AttributeType
.
LOOP
);
if
(
loop
==
null
)
{
if
(
block
.
getAttributes
().
contains
(
AttributeFlag
.
LOOP_END
))
{
LoopAttr
loop
=
(
LoopAttr
)
block
.
getAttributes
().
get
(
AttributeType
.
LOOP
);
for
(
BlockNode
b
:
sucList
)
{
if
(!
b
.
getAttributes
().
contains
(
AttributeType
.
EXC_HANDLER
))
{
// don't follow back edge
if
(
loop
.
getStart
()
==
b
)
{
continue
;
}
nodes
.
add
(
b
);
}
}
}
else
{
for
(
BlockNode
b
:
sucList
)
{
if
(!
b
.
getAttributes
().
contains
(
AttributeType
.
EXC_HANDLER
))
{
// don't follow back edge
if
(
loop
.
getStart
()
==
b
&&
loop
.
getEnd
()
==
block
)
{
continue
;
}
nodes
.
add
(
b
);
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java
浏览文件 @
24d22aaa
...
...
@@ -458,12 +458,14 @@ public class BlockMakerVisitor extends AbstractVisitor {
if
(
exitBlock
!=
otherExitBlock
&&
otherExitBlock
.
isDominator
(
pred
)
&&
otherExitBlock
.
getPredecessors
().
size
()
==
1
)
{
// merge
BlockNode
otherPred
=
otherExitBlock
.
getPredecessors
().
get
(
0
);
removeConnection
(
otherPred
,
otherExitBlock
);
connect
(
otherPred
,
exitBlock
);
cleanExitNodes
(
mth
);
return
true
;
if
(
pred
!=
otherPred
)
{
// merge
removeConnection
(
otherPred
,
otherExitBlock
);
connect
(
otherPred
,
exitBlock
);
cleanExitNodes
(
mth
);
return
true
;
}
}
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
浏览文件 @
24d22aaa
...
...
@@ -201,8 +201,7 @@ public class RegionMaker {
}
List
<
BlockNode
>
merged
=
new
ArrayList
<
BlockNode
>(
2
);
IfInfo
mergedIf
=
mergeNestedIfNodes
(
condBlock
,
ifnode
.
getThenBlock
(),
ifnode
.
getElseBlock
(),
merged
);
IfInfo
mergedIf
=
mergeNestedIfNodes
(
condBlock
,
ifnode
,
merged
);
if
(
mergedIf
!=
null
)
{
condBlock
=
mergedIf
.
getIfnode
();
if
(!
loop
.
getLoopBlocks
().
contains
(
mergedIf
.
getThenBlock
()))
{
...
...
@@ -398,54 +397,56 @@ public class RegionMaker {
}
private
BlockNode
processIf
(
IRegion
currentRegion
,
BlockNode
block
,
IfNode
ifnode
,
RegionStack
stack
)
{
BlockNode
bThen
=
ifnode
.
getThenBlock
();
BlockNode
bElse
=
ifnode
.
getElseBlock
();
if
(
block
.
getAttributes
().
contains
(
AttributeFlag
.
SKIP
))
{
// block already included in other
if
region
return
bThen
;
// block already included in other
'if'
region
return
ifnode
.
getThenBlock
()
;
}
final
BlockNode
thenBlock
;
final
BlockNode
elseBlock
;
BlockNode
out
=
null
;
BlockNode
thenBlock
=
null
;
BlockNode
elseBlock
=
null
;
IfRegion
ifRegion
=
new
IfRegion
(
currentRegion
,
block
);
currentRegion
.
getSubBlocks
().
add
(
ifRegion
);
IfInfo
mergedIf
=
mergeNestedIfNodes
(
block
,
bThen
,
bEls
e
,
null
);
IfInfo
mergedIf
=
mergeNestedIfNodes
(
block
,
ifnod
e
,
null
);
if
(
mergedIf
!=
null
)
{
ifRegion
.
setCondition
(
mergedIf
.
getCondition
());
thenBlock
=
mergedIf
.
getThenBlock
();
elseBlock
=
mergedIf
.
getElseBlock
();
out
=
BlockUtils
.
getPathCrossBlockFor
(
mth
,
thenBlock
,
elseBlock
);
}
else
{
for
(
BlockNode
d
:
block
.
getDominatesOn
())
{
if
(
d
!=
bThen
&&
d
!=
bElse
)
{
out
=
d
;
break
;
}
}
// invert condition (compiler often do it)
ifnode
.
invertCondition
();
bThen
=
ifnode
.
getThenBlock
();
bElse
=
ifnode
.
getElseBlock
();
thenBlock
=
bThen
;
// select else and exit blocks
if
(
block
.
getDominatesOn
().
size
()
==
2
&&
!
BlockUtils
.
isPathExists
(
bThen
,
bElse
))
{
final
BlockNode
bThen
=
ifnode
.
getThenBlock
();
final
BlockNode
bElse
=
ifnode
.
getElseBlock
();
// select 'then', 'else' and 'exit' blocks
if
(
bElse
.
getPredecessors
().
size
()
!=
1
&&
BlockUtils
.
isPathExists
(
bThen
,
bElse
))
{
thenBlock
=
bThen
;
elseBlock
=
null
;
out
=
bElse
;
}
else
if
(
bThen
.
getPredecessors
().
size
()
!=
1
&&
BlockUtils
.
isPathExists
(
bElse
,
bThen
))
{
ifnode
.
invertCondition
();
thenBlock
=
ifnode
.
getThenBlock
();
elseBlock
=
null
;
out
=
ifnode
.
getElseBlock
();
}
else
if
(
block
.
getDominatesOn
().
size
()
==
2
)
{
thenBlock
=
bThen
;
elseBlock
=
bElse
;
out
=
BlockUtils
.
getPathCrossBlockFor
(
mth
,
bThen
,
bElse
);
}
else
if
(
bElse
.
getPredecessors
().
size
()
!=
1
)
{
thenBlock
=
bThen
;
elseBlock
=
null
;
out
=
bElse
;
}
else
{
if
(
bElse
.
getPredecessors
().
size
()
!=
1
)
{
out
=
bElse
;
}
else
{
elseBlock
=
bElse
;
for
(
BlockNode
d
:
block
.
getDominatesOn
())
{
if
(
d
!=
bThen
&&
d
!=
bElse
)
{
out
=
d
;
break
;
}
thenBlock
=
bThen
;
elseBlock
=
bElse
;
for
(
BlockNode
d
:
block
.
getDominatesOn
())
{
if
(
d
!=
bThen
&&
d
!=
bElse
)
{
out
=
d
;
break
;
}
}
}
...
...
@@ -454,26 +455,26 @@ public class RegionMaker {
}
}
if
(
elseBlock
!=
null
&&
stack
.
containsExit
(
elseBlock
))
{
elseBlock
=
null
;
}
stack
.
push
(
ifRegion
);
stack
.
addExit
(
out
);
ifRegion
.
setThenRegion
(
makeRegion
(
thenBlock
,
stack
));
ifRegion
.
setElseRegion
(
elseBlock
==
null
?
null
:
makeRegion
(
elseBlock
,
stack
));
if
(
elseBlock
==
null
||
stack
.
containsExit
(
elseBlock
))
{
ifRegion
.
setElseRegion
(
null
);
}
else
{
ifRegion
.
setElseRegion
(
makeRegion
(
elseBlock
,
stack
));
}
stack
.
pop
();
return
out
;
}
private
IfInfo
mergeNestedIfNodes
(
BlockNode
block
,
BlockNode
bThen
,
BlockNode
bEls
e
,
List
<
BlockNode
>
merged
)
{
private
IfInfo
mergeNestedIfNodes
(
BlockNode
block
,
IfNode
ifnod
e
,
List
<
BlockNode
>
merged
)
{
IfInfo
info
=
new
IfInfo
();
info
.
setIfnode
(
block
);
info
.
setCondition
(
IfCondition
.
fromIfBlock
(
block
));
info
.
setThenBlock
(
bThen
);
info
.
setElseBlock
(
bElse
);
info
.
setThenBlock
(
ifnode
.
getThenBlock
()
);
info
.
setElseBlock
(
ifnode
.
getElseBlock
()
);
return
mergeNestedIfNodes
(
info
,
merged
);
}
...
...
jadx-core/src/test/java/jadx/tests/internal/conditions/TestTernary2.java
浏览文件 @
24d22aaa
...
...
@@ -3,8 +3,9 @@ package jadx.tests.internal.conditions;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
TestTernary2
extends
InternalJadxTest
{
...
...
@@ -20,12 +21,15 @@ public class TestTernary2 extends InternalJadxTest {
}
}
//
@Test
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"assertTrue(f(1, 0) == 0);"
));
assertEquals
(
1
,
count
(
code
,
"assertTrue"
));
assertEquals
(
1
,
count
(
code
,
"f(1, 0)"
));
// TODO:
// assertThat(code, containsString("assertTrue(f(1, 0) == 0);"));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录