Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
2acc14b0
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,发现更多精彩内容 >>
提交
2acc14b0
编写于
5月 30, 2021
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: resolve generic type vars for instance field get instruction (#918)
上级
1f1efb0e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
138 addition
and
0 deletion
+138
-0
jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java
...re/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java
+3
-0
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeBoundFieldGetAssign.java
...e/dex/visitors/typeinference/TypeBoundFieldGetAssign.java
+83
-0
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java
...core/dex/visitors/typeinference/TypeInferenceVisitor.java
+12
-0
jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericFields.java
...va/jadx/tests/integration/generics/TestGenericFields.java
+40
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/nodes/utils/TypeUtils.java
浏览文件 @
2acc14b0
...
...
@@ -61,6 +61,9 @@ public class TypeUtils {
}
private
void
expandTypeVar
(
NotificationAttrNode
node
,
ArgType
type
,
Collection
<
ArgType
>
typeVars
)
{
if
(
typeVars
.
isEmpty
())
{
return
;
}
boolean
allExtendsEmpty
=
true
;
for
(
ArgType
argType
:
typeVars
)
{
if
(
notEmpty
(
argType
.
getExtendTypes
()))
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeBoundFieldGetAssign.java
0 → 100644
浏览文件 @
2acc14b0
package
jadx.core.dex.visitors.typeinference
;
import
jadx.core.dex.info.FieldInfo
;
import
jadx.core.dex.instructions.IndexInsnNode
;
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.nodes.RootNode
;
/**
* Dynamic bound for instance field get of generic type.
* Bound type calculated using instance generic type.
*/
public
final
class
TypeBoundFieldGetAssign
implements
ITypeBoundDynamic
{
private
final
RootNode
root
;
private
final
IndexInsnNode
getNode
;
private
final
FieldInfo
fieldInfo
;
private
final
ArgType
initType
;
public
TypeBoundFieldGetAssign
(
RootNode
root
,
IndexInsnNode
getNode
,
ArgType
initType
)
{
this
.
root
=
root
;
this
.
getNode
=
getNode
;
this
.
fieldInfo
=
((
FieldInfo
)
getNode
.
getIndex
());
this
.
initType
=
initType
;
}
@Override
public
BoundEnum
getBound
()
{
return
BoundEnum
.
ASSIGN
;
}
@Override
public
ArgType
getType
(
TypeUpdateInfo
updateInfo
)
{
return
getResultType
(
updateInfo
.
getType
(
getInstanceArg
()));
}
@Override
public
ArgType
getType
()
{
return
getResultType
(
getInstanceArg
().
getType
());
}
private
ArgType
getResultType
(
ArgType
instanceType
)
{
ArgType
resultGeneric
=
root
.
getTypeUtils
().
replaceClassGenerics
(
instanceType
,
initType
);
if
(
resultGeneric
!=
null
&&
!
resultGeneric
.
isWildcard
())
{
return
resultGeneric
;
}
return
initType
;
// TODO: check if this type is allowed in current scope
}
private
InsnArg
getInstanceArg
()
{
return
getNode
.
getArg
(
0
);
}
@Override
public
RegisterArg
getArg
()
{
return
getNode
.
getResult
();
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
TypeBoundFieldGetAssign
that
=
(
TypeBoundFieldGetAssign
)
o
;
return
getNode
.
equals
(
that
.
getNode
);
}
@Override
public
int
hashCode
()
{
return
getNode
.
hashCode
();
}
@Override
public
String
toString
()
{
return
"FieldGetAssign{"
+
fieldInfo
+
", type="
+
getType
()
+
", instanceArg="
+
getInstanceArg
()
+
'}'
;
}
}
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java
浏览文件 @
2acc14b0
...
...
@@ -293,6 +293,10 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
addBound
(
typeInfo
,
makeAssignInvokeBound
((
InvokeNode
)
insn
));
break
;
case
IGET:
addBound
(
typeInfo
,
makeAssignFieldGetBound
((
IndexInsnNode
)
insn
));
break
;
case
CHECK_CAST:
addBound
(
typeInfo
,
new
TypeBoundCheckCastAssign
(
root
,
(
IndexInsnNode
)
insn
));
break
;
...
...
@@ -304,6 +308,14 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
}
}
private
ITypeBound
makeAssignFieldGetBound
(
IndexInsnNode
insn
)
{
ArgType
initType
=
insn
.
getResult
().
getInitType
();
if
(
initType
.
containsTypeVariable
())
{
return
new
TypeBoundFieldGetAssign
(
root
,
insn
,
initType
);
}
return
new
TypeBoundConst
(
BoundEnum
.
ASSIGN
,
initType
);
}
private
ITypeBound
makeAssignInvokeBound
(
InvokeNode
invokeNode
)
{
ArgType
boundType
=
invokeNode
.
getCallMth
().
getReturnType
();
ArgType
genericReturnType
=
root
.
getMethodUtils
().
getMethodGenericReturnType
(
invokeNode
);
...
...
jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericFields.java
0 → 100644
浏览文件 @
2acc14b0
package
jadx.tests.integration.generics
;
import
org.junit.jupiter.api.Test
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestGenericFields
extends
IntegrationTest
{
public
static
class
TestCls
{
public
static
class
Summary
{
Value
<
Amount
>
price
;
}
public
static
class
Value
<
T
>
{
T
value
;
}
public
static
class
Amount
{
String
cur
;
int
val
;
}
public
String
test
(
Summary
summary
)
{
Amount
amount
=
summary
.
price
.
value
;
return
amount
.
val
+
" "
+
amount
.
cur
;
}
}
@Test
public
void
test
()
{
noDebugInfo
();
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
doesNotContain
(
"T t = "
)
.
containsOne
(
"Amount amount ="
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录