Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
5a30fc03
J
jadx
项目概览
keyescgm
/
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,发现更多精彩内容 >>
提交
5a30fc03
编写于
1月 30, 2021
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: improve const inlining in finally blocks (#917)
上级
c774ffc9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
236 addition
and
29 deletion
+236
-29
jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java
.../main/java/jadx/core/dex/visitors/ConstInlineVisitor.java
+15
-28
jadx-core/src/main/java/jadx/core/utils/DebugUtils.java
jadx-core/src/main/java/jadx/core/utils/DebugUtils.java
+12
-0
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally3.java
...st/java/jadx/tests/integration/trycatch/TestFinally3.java
+90
-0
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java
.../jadx/tests/integration/trycatch/TestTryCatchFinally.java
+1
-1
jadx-core/src/test/smali/trycatch/TestFinally3.smali
jadx-core/src/test/smali/trycatch/TestFinally3.smali
+118
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java
浏览文件 @
5a30fc03
...
...
@@ -99,35 +99,11 @@ public class ConstInlineVisitor extends AbstractVisitor {
}
else
{
return
;
}
if
(
checkForFinallyBlock
(
sVar
))
{
return
;
}
// all check passed, run replace
replaceConst
(
mth
,
insn
,
constArg
,
toRemove
);
}
private
static
boolean
checkForFinallyBlock
(
SSAVar
sVar
)
{
List
<
SSAVar
>
ssaVars
=
sVar
.
getCodeVar
().
getSsaVars
();
if
(
ssaVars
.
size
()
<=
1
)
{
return
false
;
}
int
countInsns
=
0
;
int
countFinallyInsns
=
0
;
for
(
SSAVar
ssaVar
:
ssaVars
)
{
for
(
RegisterArg
reg
:
ssaVar
.
getUseList
())
{
InsnNode
parentInsn
=
reg
.
getParentInsn
();
if
(
parentInsn
!=
null
)
{
countInsns
++;
if
(
parentInsn
.
contains
(
AFlag
.
FINALLY_INSNS
))
{
countFinallyInsns
++;
}
}
}
}
return
countFinallyInsns
!=
0
&&
countFinallyInsns
!=
countInsns
;
}
/**
* Don't inline null object
*/
...
...
@@ -180,10 +156,7 @@ public class ConstInlineVisitor extends AbstractVisitor {
List
<
RegisterArg
>
useList
=
new
ArrayList
<>(
ssaVar
.
getUseList
());
int
replaceCount
=
0
;
for
(
RegisterArg
arg
:
useList
)
{
if
(
arg
.
contains
(
AFlag
.
DONT_INLINE_CONST
))
{
continue
;
}
if
(
replaceArg
(
mth
,
arg
,
constArg
,
constInsn
,
toRemove
))
{
if
(
canInline
(
arg
)
&&
replaceArg
(
mth
,
arg
,
constArg
,
constInsn
,
toRemove
))
{
replaceCount
++;
}
}
...
...
@@ -192,6 +165,20 @@ public class ConstInlineVisitor extends AbstractVisitor {
}
}
private
static
boolean
canInline
(
RegisterArg
arg
)
{
if
(
arg
.
contains
(
AFlag
.
DONT_INLINE_CONST
))
{
return
false
;
}
InsnNode
parentInsn
=
arg
.
getParentInsn
();
if
(
parentInsn
==
null
)
{
return
false
;
}
if
(
parentInsn
.
contains
(
AFlag
.
DONT_GENERATE
)
||
parentInsn
.
contains
(
AFlag
.
FINALLY_INSNS
))
{
return
false
;
}
return
true
;
}
private
static
boolean
replaceArg
(
MethodNode
mth
,
RegisterArg
arg
,
InsnArg
constArg
,
InsnNode
constInsn
,
List
<
InsnNode
>
toRemove
)
{
InsnNode
useInsn
=
arg
.
getParentInsn
();
if
(
useInsn
==
null
)
{
...
...
jadx-core/src/main/java/jadx/core/utils/DebugUtils.java
浏览文件 @
5a30fc03
...
...
@@ -6,6 +6,7 @@ import java.util.LinkedHashSet;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
...
...
@@ -59,6 +60,17 @@ public class DebugUtils {
};
}
public
static
IDexTreeVisitor
dumpRawVisitor
(
String
desc
,
Predicate
<
MethodNode
>
filter
)
{
return
new
AbstractVisitor
()
{
@Override
public
void
visit
(
MethodNode
mth
)
{
if
(
filter
.
test
(
mth
))
{
dumpRaw
(
mth
,
desc
);
}
}
};
}
public
static
void
dump
(
MethodNode
mth
,
String
desc
)
{
File
out
=
new
File
(
"test-graph-"
+
desc
+
"-tmp"
);
DotGraphVisitor
.
dump
().
save
(
out
,
mth
);
...
...
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally3.java
0 → 100644
浏览文件 @
5a30fc03
package
jadx.tests.integration.trycatch
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.tests.api.SmaliTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestFinally3
extends
SmaliTest
{
@SuppressWarnings
({
"RedundantThrows"
,
"unused"
})
public
static
class
TestCls
{
public
byte
[]
bytes
;
public
byte
[]
test
()
throws
Exception
{
InputStream
inputStream
=
null
;
try
{
if
(
bytes
==
null
)
{
if
(!
validate
())
{
return
null
;
}
inputStream
=
getInputStream
();
bytes
=
read
(
inputStream
);
}
return
convert
(
bytes
);
}
finally
{
close
(
inputStream
);
}
}
private
byte
[]
convert
(
byte
[]
bytes
)
throws
Exception
{
return
new
byte
[
0
];
}
private
boolean
validate
()
throws
Exception
{
return
false
;
}
private
InputStream
getInputStream
()
throws
Exception
{
return
new
ByteArrayInputStream
(
new
byte
[]
{});
}
private
byte
[]
read
(
InputStream
in
)
throws
Exception
{
return
new
byte
[]
{};
}
private
static
void
close
(
InputStream
is
)
{
}
}
@Test
public
void
test
()
{
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
containsOne
(
"} finally {"
)
.
doesNotContain
(
"close(null);"
);
}
@NotYetImplemented
(
"Finally instruction duplicated"
)
@Test
public
void
test2
()
{
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
containsOne
(
"} finally {"
)
.
doesNotContain
(
"close(null);"
)
.
containsOne
(
"close(inputStream);"
);
}
@NotYetImplemented
(
"Finally extract failed"
)
@Test
public
void
test2NoDebug
()
{
noDebugInfo
();
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
containsOne
(
"} finally {"
)
.
containsOne
(
indent
()
+
"close("
);
}
@Test
public
void
testSmali
()
{
assertThat
(
getClassNodeFromSmali
())
.
code
()
.
doesNotContain
(
"Type inference failed"
)
.
containsOne
(
"} finally {"
);
}
}
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java
浏览文件 @
5a30fc03
...
...
@@ -49,7 +49,7 @@ public class TestTryCatchFinally extends IntegrationTest {
assertThat
(
code
,
containsOne
(
"} catch (Exception e) {"
));
assertThat
(
code
,
containsOne
(
"e.printStackTrace();"
));
assertThat
(
code
,
containsOne
(
"} finally {"
));
assertThat
(
code
,
containsOne
(
"this.f = true;"
));
// assertThat(code, containsOne("this.f = true;")); // TODO: fix registers in duplicated code
assertThat
(
code
,
containsOne
(
"return this.f;"
));
}
}
jadx-core/src/test/smali/trycatch/TestFinally3.smali
0 → 100644
浏览文件 @
5a30fc03
.class public Ltrycatch/TestFinally3;
.super Ljava/lang/Object;
.field public bytes:[B
.method public test()[B
.registers 4
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
const/4 v0, 0x0
:try_start_1
iget-object v1, p0, Ltrycatch/TestFinally3;->bytes:[B
if-nez v1, :cond_1a
invoke-direct {p0}, Ltrycatch/TestFinally3;->validate()Z
:try_end_8
.catchall {:try_start_1 .. :try_end_8} :catchall_24
move-result v1
if-nez v1, :cond_10
invoke-static {v0}, Ltrycatch/TestFinally3;->close(Ljava/io/InputStream;)V
return-object v0
:cond_10
:try_start_10
invoke-direct {p0}, Ltrycatch/TestFinally3;->getInputStream()Ljava/io/InputStream;
move-result-object v0
invoke-direct {p0, v0}, Ltrycatch/TestFinally3;->read(Ljava/io/InputStream;)[B
move-result-object v1
iput-object v1, p0, Ltrycatch/TestFinally3;->bytes:[B
:cond_1a
iget-object v1, p0, Ltrycatch/TestFinally3;->bytes:[B
invoke-direct {p0, v1}, Ltrycatch/TestFinally3;->convert([B)[B
:try_end_1f
.catchall {:try_start_10 .. :try_end_1f} :catchall_24
move-result-object v1
invoke-static {v0}, Ltrycatch/TestFinally3;->close(Ljava/io/InputStream;)V
return-object v1
:catchall_24
move-exception v1
invoke-static {v0}, Ltrycatch/TestFinally3;->close(Ljava/io/InputStream;)V
throw v1
.end method
.method private convert([B)[B
.registers 3
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
const/4 v0, 0x0
new-array v0, v0, [B
return-object v0
.end method
.method private static close(Ljava/io/InputStream;)V
.registers 1
return-void
.end method
.method private getInputStream()Ljava/io/InputStream;
.registers 3
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
new-instance v0, Ljava/io/ByteArrayInputStream;
const/4 v1, 0x0
new-array v1, v1, [B
invoke-direct {v0, v1}, Ljava/io/ByteArrayInputStream;-><init>([B)V
return-object v0
.end method
.method private read(Ljava/io/InputStream;)[B
.registers 3
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
const/4 v0, 0x0
new-array v0, v0, [B
return-object v0
.end method
.method private validate()Z
.registers 2
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
const/4 v0, 0x0
return v0
.end method
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录