Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
a85d382e
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,发现更多精彩内容 >>
提交
a85d382e
编写于
12月 24, 2013
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: reformat TryCatchBlock class
上级
4caa58f5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
66 addition
and
33 deletion
+66
-33
jadx-core/src/main/java/jadx/core/dex/nodes/InsnContainer.java
...core/src/main/java/jadx/core/dex/nodes/InsnContainer.java
+1
-1
jadx-core/src/main/java/jadx/core/dex/trycatch/TryCatchBlock.java
...e/src/main/java/jadx/core/dex/trycatch/TryCatchBlock.java
+33
-32
jadx-core/src/test/java/jadx/tests/internal/TestTryCatch.java
...-core/src/test/java/jadx/tests/internal/TestTryCatch.java
+32
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/nodes/InsnContainer.java
浏览文件 @
a85d382e
...
...
@@ -8,7 +8,7 @@ public class InsnContainer extends AttrNode implements IBlock {
private
List
<
InsnNode
>
insns
;
public
void
setInstructions
(
List
<
InsnNode
>
insns
)
{
public
InsnContainer
(
List
<
InsnNode
>
insns
)
{
this
.
insns
=
insns
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/trycatch/TryCatchBlock.java
浏览文件 @
a85d382e
...
...
@@ -15,6 +15,8 @@ import jadx.core.utils.Utils;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
TryCatchBlock
{
...
...
@@ -27,7 +29,7 @@ public class TryCatchBlock {
private
final
CatchAttr
attr
;
public
TryCatchBlock
()
{
handlers
=
new
ArrayList
<
ExceptionHandler
>(
2
);
handlers
=
new
LinkedList
<
ExceptionHandler
>(
);
insns
=
new
ArrayList
<
InsnNode
>();
attr
=
new
CatchAttr
(
this
);
}
...
...
@@ -45,9 +47,10 @@ public class TryCatchBlock {
}
public
void
removeHandler
(
MethodNode
mth
,
ExceptionHandler
handler
)
{
for
(
int
i
=
0
;
i
<
handlers
.
size
();
i
++)
{
if
(
handlers
.
get
(
i
)
==
handler
)
{
handlers
.
remove
(
i
);
for
(
Iterator
<
ExceptionHandler
>
it
=
handlers
.
iterator
();
it
.
hasNext
();
)
{
ExceptionHandler
h
=
it
.
next
();
if
(
h
==
handler
)
{
it
.
remove
();
break
;
}
}
...
...
@@ -70,16 +73,16 @@ public class TryCatchBlock {
}
}
}
return
;
}
else
{
// self destruction
for
(
InsnNode
insn
:
insns
)
{
insn
.
getAttributes
().
remove
(
attr
);
}
insns
.
clear
();
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
block
.
getAttributes
().
remove
(
attr
);
}
}
// self destruction
for
(
InsnNode
insn
:
insns
)
insn
.
getAttributes
().
remove
(
attr
);
insns
.
clear
();
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
block
.
getAttributes
().
remove
(
attr
);
}
public
void
addInsn
(
InsnNode
insn
)
{
...
...
@@ -113,34 +116,34 @@ public class TryCatchBlock {
}
public
void
setFinalBlockFromInsns
(
MethodNode
mth
,
List
<
InsnNode
>
insns
)
{
InsnContainer
cont
=
new
InsnContainer
();
List
<
InsnNode
>
finalBlockInsns
=
new
ArrayList
<
InsnNode
>(
insns
);
cont
.
setInstructions
(
finalBlockInsns
);
setFinalBlock
(
cont
);
setFinalBlock
(
new
InsnContainer
(
finalBlockInsns
));
InstructionRemover
.
unbindInsnList
(
finalBlockInsns
);
// remove these instructions from other handlers
for
(
ExceptionHandler
h
:
getHandlers
())
{
for
(
BlockNode
ehb
:
h
.
getBlocks
())
for
(
BlockNode
ehb
:
h
.
getBlocks
())
{
ehb
.
getInstructions
().
removeAll
(
finalBlockInsns
);
}
}
// remove from blocks with this catch
for
(
BlockNode
b
:
mth
.
getBasicBlocks
())
{
IAttribute
ca
=
b
.
getAttributes
().
get
(
AttributeType
.
CATCH_BLOCK
);
if
(
attr
==
ca
)
if
(
attr
==
ca
)
{
b
.
getInstructions
().
removeAll
(
finalBlockInsns
);
}
}
}
public
void
merge
(
MethodNode
mth
,
TryCatchBlock
tryBlock
)
{
for
(
InsnNode
insn
:
tryBlock
.
getInsns
())
for
(
InsnNode
insn
:
tryBlock
.
getInsns
())
{
this
.
addInsn
(
insn
);
}
this
.
handlers
.
addAll
(
tryBlock
.
getHandlers
());
for
(
ExceptionHandler
eh
:
handlers
)
for
(
ExceptionHandler
eh
:
handlers
)
{
eh
.
setTryBlock
(
this
);
}
// clear
tryBlock
.
handlers
.
clear
();
tryBlock
.
removeWholeBlock
(
mth
);
...
...
@@ -148,25 +151,23 @@ public class TryCatchBlock {
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
handlers
==
null
)
?
0
:
handlers
.
hashCode
());
return
result
;
return
handlers
.
hashCode
();
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
||
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
TryCatchBlock
other
=
(
TryCatchBlock
)
obj
;
if
(!
handlers
.
equals
(
other
.
handlers
))
return
false
;
return
true
;
return
handlers
.
equals
(
other
.
handlers
);
}
@Override
public
String
toString
()
{
return
"Catch:{ "
+
Utils
.
listToString
(
handlers
)
+
" }"
;
}
}
jadx-core/src/test/java/jadx/tests/internal/TestTryCatch.java
0 → 100644
浏览文件 @
a85d382e
package
jadx.tests.internal
;
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
TestTryCatch
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
void
f
()
{
try
{
Thread
.
sleep
(
50
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"try {"
));
assertThat
(
code
,
containsString
(
"Thread.sleep(50);"
));
assertThat
(
code
,
containsString
(
"} catch (InterruptedException e) {"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录