Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
519a74e8
J
jadx
项目概览
Quincy379
/
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,体验更适合开发者的 AI 搜索 >>
提交
519a74e8
编写于
2月 16, 2020
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: improve type inference for arrays (#837)
上级
dea7714e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
15 deletion
+32
-15
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeUpdate.java
...java/jadx/core/dex/visitors/typeinference/TypeUpdate.java
+7
-7
jadx-core/src/test/java/jadx/core/dex/visitors/typeinference/TypeCompareTest.java
...jadx/core/dex/visitors/typeinference/TypeCompareTest.java
+4
-0
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver11.java
...java/jadx/tests/integration/types/TestTypeResolver11.java
+21
-8
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeUpdate.java
浏览文件 @
519a74e8
...
...
@@ -96,13 +96,13 @@ public final class TypeUpdate {
TypeCompareEnum
compareResult
=
comparator
.
compareTypes
(
candidateType
,
currentType
);
if
(
arg
.
isTypeImmutable
()
&&
currentType
!=
ArgType
.
UNKNOWN
)
{
// don't changed type
if
(
compareResult
==
TypeCompareEnum
.
CONFLICT
)
{
if
(
Consts
.
DEBUG
)
{
LOG
.
debug
(
"Type rejected for {} due to conflict: candidate={}, current={}"
,
arg
,
candidateType
,
currentType
);
}
return
REJECT
;
if
(
compareResult
==
TypeCompareEnum
.
EQUAL
)
{
return
SAME
;
}
return
SAME
;
if
(
Consts
.
DEBUG
)
{
LOG
.
debug
(
"Type rejected for {} due to conflict: candidate={}, current={}"
,
arg
,
candidateType
,
currentType
);
}
return
REJECT
;
}
if
(
compareResult
.
isWider
()
&&
!
updateInfo
.
getFlags
().
isAllowWider
())
{
if
(
Consts
.
DEBUG
)
{
...
...
@@ -412,7 +412,7 @@ public final class TypeUpdate {
TypeUpdateResult
result
=
updateTypeChecked
(
updateInfo
,
putArg
,
arrayElement
);
if
(
result
==
REJECT
)
{
ArgType
putType
=
putArg
.
getType
();
if
(
putType
.
isTypeKnown
()
&&
putType
.
isObject
())
{
if
(
putType
.
isTypeKnown
()
&&
!
putType
.
isPrimitive
())
{
TypeCompareEnum
compResult
=
comparator
.
compareTypes
(
arrayElement
,
putType
);
if
(
compResult
==
TypeCompareEnum
.
WIDER
||
compResult
==
TypeCompareEnum
.
WIDER_BY_GENERIC
)
{
// allow wider result (i.e allow put in Object[] any objects)
...
...
jadx-core/src/test/java/jadx/core/dex/visitors/typeinference/TypeCompareTest.java
浏览文件 @
519a74e8
...
...
@@ -15,6 +15,7 @@ import jadx.core.dex.instructions.args.ArgType;
import
jadx.core.dex.nodes.RootNode
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
BOOLEAN
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
BYTE
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
CHAR
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
CLASS
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
INT
;
...
...
@@ -77,6 +78,9 @@ public class TypeCompareTest {
firstIsNarrow
(
UNKNOWN_ARRAY
,
OBJECT
);
firstIsNarrow
(
array
(
BYTE
),
OBJECT
);
firstIsNarrow
(
array
(
array
(
BYTE
)),
array
(
OBJECT
));
check
(
array
(
OBJECT
),
array
(
INT
),
TypeCompareEnum
.
CONFLICT
);
ArgType
integerType
=
ArgType
.
object
(
"java.lang.Integer"
);
...
...
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver11.java
浏览文件 @
519a74e8
package
jadx.tests.integration.types
;
import
java.util.Arrays
;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestTypeResolver11
extends
IntegrationTest
{
public
static
class
TestCls
{
public
Void
test
(
Object
...
obj
Arr
)
{
int
val
=
(
Integer
)
obj
Arr
[
0
];
String
str
=
(
String
)
obj
Arr
[
1
];
public
Void
test
(
Object
...
obj
ects
)
{
int
val
=
(
Integer
)
obj
ects
[
0
];
String
str
=
(
String
)
obj
ects
[
1
];
call
(
str
,
str
,
val
,
val
);
return
null
;
}
...
...
@@ -18,21 +21,31 @@ public class TestTypeResolver11 extends IntegrationTest {
private
void
call
(
String
a
,
String
b
,
int
...
val
)
{
}
private
boolean
test2
(
String
s1
,
String
...
args
)
{
String
str
=
Arrays
.
toString
(
args
);
return
s1
.
length
()
+
str
.
length
()
>
0
;
}
public
void
check
()
{
test
(
1
,
"str"
);
assertThat
(
test2
(
"1"
,
"2"
,
"34"
)).
isTrue
();
}
}
@NotYetImplemented
(
"Missing cast"
)
@Test
public
void
test
()
{
getClassNode
(
TestCls
.
class
);
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
containsOne
(
"(Integer) objects[0]"
)
.
containsOne
(
"String str = (String) objects[1];"
);
}
@NotYetImplemented
(
"Missing cast"
)
@Test
public
void
testNoDebug
()
{
noDebugInfo
();
getClassNode
(
TestCls
.
class
);
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
containsOne
(
"(Integer) objArr[0]"
)
.
containsOne
(
"String str = (String) objArr[1];"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录