Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
ddedb8d8
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,发现更多精彩内容 >>
提交
ddedb8d8
编写于
7月 26, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: don't override type of method parameter in const deboxing (#723)
上级
472aa527
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
127 addition
and
9 deletion
+127
-9
jadx-core/src/main/java/jadx/core/dex/visitors/DeboxingVisitor.java
...src/main/java/jadx/core/dex/visitors/DeboxingVisitor.java
+18
-9
jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing2.java
...est/java/jadx/tests/integration/others/TestDeboxing2.java
+49
-0
jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java
...est/java/jadx/tests/integration/others/TestDeboxing3.java
+60
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/DeboxingVisitor.java
浏览文件 @
ddedb8d8
...
...
@@ -14,6 +14,7 @@ import jadx.core.dex.instructions.InvokeType;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.SSAVar
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
...
...
@@ -90,14 +91,16 @@ public class DeboxingVisitor extends AbstractVisitor {
if
(
valueOfMths
.
contains
(
callMth
))
{
RegisterArg
resArg
=
insnNode
.
getResult
();
InsnArg
arg
=
insnNode
.
getArg
(
0
);
if
(
arg
.
isLiteral
()
&&
checkArgUsage
(
resArg
)
)
{
if
(
arg
.
isLiteral
())
{
ArgType
primitiveType
=
callMth
.
getArgumentsTypes
().
get
(
0
);
ArgType
boxType
=
callMth
.
getReturnType
();
if
(
isNeedExplicitCast
(
resArg
,
primitiveType
,
boxType
))
{
arg
.
add
(
AFlag
.
EXPLICIT_PRIMITIVE_TYPE
);
}
resArg
.
setType
(
primitiveType
);
arg
.
setType
(
primitiveType
);
if
(
canChangeTypeToPrimitive
(
resArg
))
{
resArg
.
setType
(
primitiveType
);
}
InsnNode
constInsn
=
new
InsnNode
(
InsnType
.
CONST
,
1
);
constInsn
.
addArg
(
arg
);
...
...
@@ -122,17 +125,23 @@ public class DeboxingVisitor extends AbstractVisitor {
return
false
;
}
private
boolean
c
heckArgUsag
e
(
RegisterArg
arg
)
{
for
(
RegisterArg
useArg
:
arg
.
getSVar
().
getUseList
())
{
InsnNode
parentInsn
=
useArg
.
getParentIns
n
();
if
(
parentInsn
==
null
)
{
private
boolean
c
anChangeTypeToPrimitiv
e
(
RegisterArg
arg
)
{
for
(
SSAVar
ssaVar
:
arg
.
getSVar
().
getCodeVar
().
getSsaVars
())
{
RegisterArg
assignArg
=
ssaVar
.
getAssig
n
();
if
(
assignArg
.
contains
(
AFlag
.
IMMUTABLE_TYPE
)
)
{
return
false
;
}
if
(
parentInsn
.
getType
()
==
InsnType
.
INVOKE
)
{
In
vokeNode
invokeNode
=
(
InvokeNode
)
parentInsn
;
if
(
useArg
.
equals
(
invokeNode
.
getInstanceArg
())
)
{
for
(
RegisterArg
useArg
:
ssaVar
.
getUseList
()
)
{
In
snNode
parentInsn
=
useArg
.
getParentInsn
()
;
if
(
parentInsn
==
null
)
{
return
false
;
}
if
(
parentInsn
.
getType
()
==
InsnType
.
INVOKE
)
{
InvokeNode
invokeNode
=
(
InvokeNode
)
parentInsn
;
if
(
useArg
.
equals
(
invokeNode
.
getInstanceArg
()))
{
return
false
;
}
}
}
}
return
true
;
...
...
jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing2.java
0 → 100644
浏览文件 @
ddedb8d8
package
jadx.tests.integration.others
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
countString
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
public
class
TestDeboxing2
extends
IntegrationTest
{
public
static
class
TestCls
{
public
long
test
(
Long
l
)
{
if
(
l
==
null
)
{
l
=
0L
;
}
return
l
;
}
public
void
check
()
{
assertThat
(
test
(
null
),
is
(
0L
));
assertThat
(
test
(
0L
),
is
(
0L
));
assertThat
(
test
(
7L
),
is
(
7L
));
}
}
@Test
public
void
test
()
{
noDebugInfo
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"long test(Long l)"
));
assertThat
(
code
,
containsOne
(
"if (l == null) {"
));
assertThat
(
code
,
containsOne
(
"l = 0L;"
));
// checks for 'check' method
assertThat
(
code
,
containsOne
(
"test(null)"
));
assertThat
(
code
,
containsOne
(
"test(0L)"
));
assertThat
(
code
,
countString
(
2
,
"is(0L)"
));
assertThat
(
code
,
containsOne
(
"test(7L)"
));
assertThat
(
code
,
containsOne
(
"is(7L)"
));
}
}
jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java
0 → 100644
浏览文件 @
ddedb8d8
package
jadx.tests.integration.others
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
public
class
TestDeboxing3
extends
IntegrationTest
{
public
static
class
TestCls
{
public
static
class
Pair
<
F
,
S
>
{
public
F
first
;
public
S
second
;
}
private
Map
<
String
,
Pair
<
Long
,
String
>>
cache
=
new
HashMap
<>();
public
boolean
test
(
String
id
,
Long
l
)
{
if
(
l
==
null
)
{
l
=
900000L
;
}
Pair
<
Long
,
String
>
pair
=
this
.
cache
.
get
(
id
);
if
(
pair
==
null
)
{
return
false
;
}
return
pair
.
first
+
l
>
System
.
currentTimeMillis
();
}
}
@Test
public
void
test
()
{
noDebugInfo
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"l = 900000L;"
));
}
@Test
@NotYetImplemented
(
"Full deboxing and generics propagation"
)
public
void
testFull
()
{
noDebugInfo
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"Pair<Long, String> pair = this.cache.get(id);"
));
assertThat
(
code
,
containsOne
(
"return pair.first + l > System.currentTimeMillis();"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录