Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colcode
jadx
提交
cbbb7335
J
jadx
项目概览
colcode
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
cbbb7335
编写于
7月 04, 2013
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unneeded 'return' instructions
上级
f51d6337
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
15 deletion
+61
-15
src/main/java/jadx/dex/nodes/MethodNode.java
src/main/java/jadx/dex/nodes/MethodNode.java
+17
-0
src/main/java/jadx/dex/visitors/BlockMakerVisitor.java
src/main/java/jadx/dex/visitors/BlockMakerVisitor.java
+12
-0
src/main/java/jadx/dex/visitors/regions/FinishRegions.java
src/main/java/jadx/dex/visitors/regions/FinishRegions.java
+29
-12
src/main/java/jadx/dex/visitors/regions/TracedRegionVisitor.java
...n/java/jadx/dex/visitors/regions/TracedRegionVisitor.java
+3
-3
未找到文件。
src/main/java/jadx/dex/nodes/MethodNode.java
浏览文件 @
cbbb7335
...
...
@@ -4,6 +4,7 @@ import jadx.Consts;
import
jadx.dex.attributes.AttrNode
;
import
jadx.dex.attributes.AttributeFlag
;
import
jadx.dex.attributes.JumpAttribute
;
import
jadx.dex.attributes.LoopAttr
;
import
jadx.dex.attributes.annotations.Annotation
;
import
jadx.dex.info.AccessInfo
;
import
jadx.dex.info.AccessInfo.AFType
;
...
...
@@ -64,6 +65,7 @@ public class MethodNode extends AttrNode implements ILoadable {
private
IContainer
region
;
private
List
<
ExceptionHandler
>
exceptionHandlers
;
private
List
<
LoopAttr
>
loops
=
Collections
.
emptyList
();
public
MethodNode
(
ClassNode
classNode
,
Method
mthData
)
{
this
.
mthInfo
=
MethodInfo
.
fromDex
(
classNode
.
dex
(),
mthData
.
getMethodIndex
());
...
...
@@ -411,6 +413,21 @@ public class MethodNode extends AttrNode implements ILoadable {
this
.
exitBlocks
.
add
(
exitBlock
);
}
public
void
registerLoop
(
LoopAttr
loop
)
{
if
(
loops
.
isEmpty
())
{
loops
=
new
ArrayList
<
LoopAttr
>(
5
);
}
loops
.
add
(
loop
);
}
public
LoopAttr
getLoopForBlock
(
BlockNode
block
)
{
for
(
LoopAttr
loop
:
loops
)
{
if
(
loop
.
getLoopBlocks
().
contains
(
block
))
return
loop
;
}
return
null
;
}
public
ExceptionHandler
addExceptionHandler
(
ExceptionHandler
handler
)
{
if
(
exceptionHandlers
==
null
)
{
exceptionHandlers
=
new
ArrayList
<
ExceptionHandler
>(
2
);
...
...
src/main/java/jadx/dex/visitors/BlockMakerVisitor.java
浏览文件 @
cbbb7335
...
...
@@ -180,6 +180,8 @@ public class BlockMakerVisitor extends AbstractVisitor {
if
(
i
>
100
)
throw
new
AssertionError
(
"Can't fix method cfg: "
+
mth
);
}
registerLoops
(
mth
);
}
private
static
BlockNode
getBlock
(
int
offset
,
Map
<
Integer
,
BlockNode
>
blocksMap
)
{
...
...
@@ -307,6 +309,16 @@ public class BlockMakerVisitor extends AbstractVisitor {
}
}
private
static
void
registerLoops
(
MethodNode
mth
)
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
AttributesList
attributes
=
block
.
getAttributes
();
IAttribute
loop
=
attributes
.
get
(
AttributeType
.
LOOP
);
if
(
loop
!=
null
&&
attributes
.
contains
(
AttributeFlag
.
LOOP_START
))
{
mth
.
registerLoop
((
LoopAttr
)
loop
);
}
}
}
private
static
boolean
modifyBlocksTree
(
MethodNode
mth
)
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
if
(
block
.
getPredecessors
().
isEmpty
()
&&
block
!=
mth
.
getEnterBlock
())
{
...
...
src/main/java/jadx/dex/visitors/regions/FinishRegions.java
浏览文件 @
cbbb7335
package
jadx.dex.visitors.regions
;
import
jadx.dex.instructions.InsnType
;
import
jadx.dex.instructions.args.ArgType
;
import
jadx.dex.nodes.BlockNode
;
import
jadx.dex.nodes.IBlock
;
import
jadx.dex.nodes.IRegion
;
import
jadx.dex.nodes.InsnNode
;
import
jadx.dex.nodes.MethodNode
;
import
jadx.dex.regions.LoopRegion
;
import
java.util.Iterator
;
import
java.util.List
;
public
class
FinishRegions
implements
IRegionVisitor
{
public
class
FinishRegions
extends
TracedRegionVisitor
{
@Override
public
void
processBlock
(
MethodNode
mth
,
IBlock
block
)
{
public
void
processBlockTraced
(
MethodNode
mth
,
IBlock
container
,
IRegion
currentRegion
)
{
if
(
container
.
getClass
()
!=
BlockNode
.
class
)
return
;
BlockNode
block
=
(
BlockNode
)
container
;
// remove return from class init method
if
(
mth
.
getMethodInfo
().
isClassInit
())
{
// remove last return in void functions
if
(
block
.
getCleanSuccessors
().
isEmpty
()
&&
mth
.
getReturnType
().
equals
(
ArgType
.
VOID
))
{
List
<
InsnNode
>
insns
=
block
.
getInstructions
();
if
(
insns
.
size
()
!=
0
)
{
InsnNode
last
=
insns
.
get
(
insns
.
size
()
-
1
);
if
(
last
.
getType
()
==
InsnType
.
RETURN
)
{
insns
.
remove
(
insns
.
size
()
-
1
);
int
lastIndex
=
insns
.
size
()
-
1
;
if
(
lastIndex
!=
-
1
)
{
InsnNode
last
=
insns
.
get
(
lastIndex
);
if
(
last
.
getType
()
==
InsnType
.
RETURN
&&
blockNotInLoop
(
mth
,
block
))
{
insns
.
remove
(
lastIndex
);
}
}
}
}
@Override
public
void
enterRegion
(
MethodNode
mth
,
IRegion
region
)
{
private
boolean
blockNotInLoop
(
MethodNode
mth
,
BlockNode
block
)
{
if
(
mth
.
getLoopForBlock
(
block
)
!=
null
)
return
false
;
for
(
Iterator
<
IRegion
>
it
=
regionStack
.
descendingIterator
();
it
.
hasNext
();
)
{
IRegion
region
=
it
.
next
();
if
(
region
.
getClass
()
==
LoopRegion
.
class
)
return
false
;
}
return
true
;
}
@Override
...
...
@@ -36,6 +53,6 @@ public class FinishRegions implements IRegionVisitor {
LoopRegion
loop
=
(
LoopRegion
)
region
;
loop
.
mergePreCondition
();
}
super
.
leaveRegion
(
mth
,
region
);
}
}
src/main/java/jadx/dex/visitors/regions/TracedRegionVisitor.java
浏览文件 @
cbbb7335
...
...
@@ -4,11 +4,12 @@ import jadx.dex.nodes.IBlock;
import
jadx.dex.nodes.IRegion
;
import
jadx.dex.nodes.MethodNode
;
import
java.util.Stack
;
import
java.util.ArrayDeque
;
import
java.util.Deque
;
public
abstract
class
TracedRegionVisitor
implements
IRegionVisitor
{
pr
ivate
final
Stack
<
IRegion
>
regionStack
=
new
Stack
<
IRegion
>();
pr
otected
final
Deque
<
IRegion
>
regionStack
=
new
ArrayDeque
<
IRegion
>();
@Override
public
void
enterRegion
(
MethodNode
mth
,
IRegion
region
)
{
...
...
@@ -27,5 +28,4 @@ public abstract class TracedRegionVisitor implements IRegionVisitor {
public
void
leaveRegion
(
MethodNode
mth
,
IRegion
region
)
{
regionStack
.
pop
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录