Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
7396c759
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,发现更多精彩内容 >>
提交
7396c759
编写于
11月 22, 2020
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: resolve type variables in invoke from arg types
上级
d39849ad
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
102 addition
and
2 deletion
+102
-2
jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java
...re/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java
+24
-0
jadx-core/src/main/java/jadx/core/dex/visitors/MethodInvokeVisitor.java
...main/java/jadx/core/dex/visitors/MethodInvokeVisitor.java
+8
-2
jadx-core/src/main/java/jadx/core/utils/Utils.java
jadx-core/src/main/java/jadx/core/utils/Utils.java
+20
-0
jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums9.java
...rc/test/java/jadx/tests/integration/enums/TestEnums9.java
+50
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java
浏览文件 @
7396c759
...
...
@@ -154,6 +154,30 @@ public class TypeUtils {
return
replaceMap
;
}
public
Map
<
ArgType
,
ArgType
>
getTypeVarMappingForInvoke
(
BaseInvokeNode
invokeInsn
)
{
IMethodDetails
mthDetails
=
root
.
getMethodUtils
().
getMethodDetails
(
invokeInsn
);
if
(
mthDetails
==
null
)
{
return
Collections
.
emptyMap
();
}
Map
<
ArgType
,
ArgType
>
map
=
new
HashMap
<>(
1
+
invokeInsn
.
getArgsCount
());
addTypeVarMapping
(
map
,
mthDetails
.
getReturnType
(),
invokeInsn
.
getResult
());
int
argCount
=
Math
.
min
(
mthDetails
.
getArgTypes
().
size
(),
invokeInsn
.
getArgsCount
());
for
(
int
i
=
0
;
i
<
argCount
;
i
++)
{
addTypeVarMapping
(
map
,
mthDetails
.
getArgTypes
().
get
(
i
),
invokeInsn
.
getArg
(
i
));
}
return
map
;
}
private
static
void
addTypeVarMapping
(
Map
<
ArgType
,
ArgType
>
map
,
ArgType
typeVar
,
InsnArg
arg
)
{
if
(
arg
==
null
||
typeVar
==
null
||
!
typeVar
.
isTypeKnown
())
{
return
;
}
if
(
typeVar
.
isGenericType
())
{
map
.
put
(
typeVar
,
arg
.
getType
());
}
// TODO: resolve inner type vars: 'List<T> -> List<String>' to 'T -> String'
}
@Nullable
public
ArgType
replaceMethodGenerics
(
BaseInvokeNode
invokeInsn
,
IMethodDetails
details
,
ArgType
typeWithGeneric
)
{
if
(
typeWithGeneric
==
null
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/MethodInvokeVisitor.java
浏览文件 @
7396c759
...
...
@@ -22,6 +22,7 @@ import jadx.core.dex.nodes.IMethodDetails;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.RootNode
;
import
jadx.core.dex.nodes.utils.TypeUtils
;
import
jadx.core.dex.visitors.methods.MutableMethodDetails
;
import
jadx.core.dex.visitors.shrink.CodeShrinkVisitor
;
import
jadx.core.dex.visitors.typeinference.TypeCompare
;
...
...
@@ -156,9 +157,14 @@ public class MethodInvokeVisitor extends AbstractVisitor {
}
private
Map
<
ArgType
,
ArgType
>
getTypeVarsMapping
(
BaseInvokeNode
invokeInsn
)
{
ArgType
declClsType
=
invokeInsn
.
getCallMth
().
getDeclClass
().
getType
();
MethodInfo
callMthInfo
=
invokeInsn
.
getCallMth
();
ArgType
declClsType
=
callMthInfo
.
getDeclClass
().
getType
();
ArgType
callClsType
=
getClsCallType
(
invokeInsn
,
declClsType
);
return
root
.
getTypeUtils
().
getTypeVariablesMapping
(
callClsType
);
TypeUtils
typeUtils
=
root
.
getTypeUtils
();
Map
<
ArgType
,
ArgType
>
clsTypeVars
=
typeUtils
.
getTypeVariablesMapping
(
callClsType
);
Map
<
ArgType
,
ArgType
>
mthTypeVars
=
typeUtils
.
getTypeVarMappingForInvoke
(
invokeInsn
);
return
Utils
.
mergeMaps
(
clsTypeVars
,
mthTypeVars
);
}
private
ArgType
getClsCallType
(
BaseInvokeNode
invokeInsn
,
ArgType
declClsType
)
{
...
...
jadx-core/src/main/java/jadx/core/utils/Utils.java
浏览文件 @
7396c759
...
...
@@ -246,6 +246,22 @@ public class Utils {
return
Collections
.
unmodifiableMap
(
result
);
}
/**
* Merge two maps. Return HashMap as result. Second map will override values from first map.
*/
public
static
<
K
,
V
>
Map
<
K
,
V
>
mergeMaps
(
Map
<
K
,
V
>
first
,
Map
<
K
,
V
>
second
)
{
if
(
isEmpty
(
first
))
{
return
second
;
}
if
(
isEmpty
(
second
))
{
return
first
;
}
Map
<
K
,
V
>
result
=
new
HashMap
<>(
first
.
size
()
+
second
.
size
());
result
.
putAll
(
first
);
result
.
putAll
(
second
);
return
result
;
}
@Nullable
public
static
<
T
>
T
getOne
(
@Nullable
List
<
T
>
list
)
{
if
(
list
==
null
||
list
.
size
()
!=
1
)
{
...
...
@@ -277,6 +293,10 @@ public class Utils {
return
col
!=
null
&&
!
col
.
isEmpty
();
}
public
static
<
K
,
V
>
boolean
isEmpty
(
Map
<
K
,
V
>
map
)
{
return
map
==
null
||
map
.
isEmpty
();
}
public
static
<
T
>
boolean
isEmpty
(
T
[]
arr
)
{
return
arr
==
null
||
arr
.
length
==
0
;
}
...
...
jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums9.java
0 → 100644
浏览文件 @
7396c759
package
jadx.tests.integration.enums
;
import
java.util.ArrayList
;
import
java.util.EnumSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.junit.jupiter.api.Test
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestEnums9
extends
IntegrationTest
{
public
static
class
TestCls
{
public
enum
Types
{
INT
,
FLOAT
,
LONG
,
DOUBLE
,
OBJECT
,
ARRAY
;
private
static
Set
<
Types
>
primitives
=
EnumSet
.
of
(
INT
,
FLOAT
,
LONG
,
DOUBLE
);
public
static
List
<
Types
>
references
=
new
ArrayList
<>();
static
{
references
.
add
(
OBJECT
);
references
.
add
(
ARRAY
);
}
public
static
Set
<
Types
>
getPrimitives
()
{
return
primitives
;
}
}
public
void
check
()
{
assertThat
(
Types
.
getPrimitives
()).
contains
(
Types
.
INT
);
assertThat
(
Types
.
references
).
hasSize
(
2
);
}
}
@Test
public
void
test
()
{
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
doesNotContain
(
"EnumSet.of((Enum) INT,"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录