Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
ae31fee8
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,发现更多精彩内容 >>
提交
ae31fee8
编写于
5月 29, 2020
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: add cast to exact type on field access (#729)
上级
e7b00cc7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
77 addition
and
4 deletion
+77
-4
jadx-core/src/main/java/jadx/core/dex/instructions/IndexInsnNode.java
...c/main/java/jadx/core/dex/instructions/IndexInsnNode.java
+9
-4
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
+5
-0
jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
...core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
+32
-0
jadx-core/src/test/java/jadx/tests/integration/types/TestFieldAccess.java
...st/java/jadx/tests/integration/types/TestFieldAccess.java
+31
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/instructions/IndexInsnNode.java
浏览文件 @
ae31fee8
...
...
@@ -41,10 +41,15 @@ public class IndexInsnNode extends InsnNode {
switch
(
insnType
)
{
case
CAST:
case
CHECK_CAST:
return
InsnUtils
.
formatOffset
(
offset
)
+
": "
+
InsnUtils
.
insnTypeToString
(
insnType
)
+
getResult
()
+
" = ("
+
InsnUtils
.
indexToString
(
index
)
+
") "
+
Utils
.
listToString
(
getArguments
());
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
InsnUtils
.
formatOffset
(
offset
)).
append
(
": "
);
sb
.
append
(
insnType
).
append
(
' '
);
if
(
getResult
()
!=
null
)
{
sb
.
append
(
getResult
()).
append
(
" = "
);
}
sb
.
append
(
'('
).
append
(
InsnUtils
.
indexToString
(
index
)).
append
(
") "
);
sb
.
append
(
Utils
.
listToString
(
getArguments
()));
return
sb
.
toString
();
default
:
return
super
.
toString
()
+
' '
+
InsnUtils
.
indexToString
(
index
);
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
浏览文件 @
ae31fee8
...
...
@@ -30,6 +30,7 @@ import jadx.core.dex.nodes.utils.MethodUtils;
import
jadx.core.dex.nodes.utils.TypeUtils
;
import
jadx.core.dex.visitors.DepthTraversal
;
import
jadx.core.dex.visitors.IDexTreeVisitor
;
import
jadx.core.dex.visitors.typeinference.TypeCompare
;
import
jadx.core.dex.visitors.typeinference.TypeUpdate
;
import
jadx.core.utils.CacheStorage
;
import
jadx.core.utils.ErrorsCounter
;
...
...
@@ -424,6 +425,10 @@ public class RootNode {
return
typeUpdate
;
}
public
TypeCompare
getTypeCompare
()
{
return
typeUpdate
.
getTypeCompare
();
}
public
ICodeCache
getCodeCache
()
{
return
codeCache
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
浏览文件 @
ae31fee8
...
...
@@ -33,6 +33,7 @@ import jadx.core.dex.instructions.NewArrayNode;
import
jadx.core.dex.instructions.SwitchInsn
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.LiteralArg
;
import
jadx.core.dex.instructions.args.NamedArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
...
...
@@ -49,6 +50,7 @@ import jadx.core.dex.trycatch.ExcHandlerAttr;
import
jadx.core.dex.trycatch.ExceptionHandler
;
import
jadx.core.dex.visitors.regions.variables.ProcessVariables
;
import
jadx.core.dex.visitors.shrink.CodeShrinkVisitor
;
import
jadx.core.dex.visitors.typeinference.TypeCompareEnum
;
import
jadx.core.utils.InsnRemover
;
import
jadx.core.utils.InsnUtils
;
import
jadx.core.utils.exceptions.JadxException
;
...
...
@@ -144,6 +146,11 @@ public class ModVisitor extends AbstractVisitor {
fixPrimitiveCast
(
mth
,
block
,
i
,
insn
);
break
;
case
IPUT:
case
IGET:
fixTypeForFieldAccess
(
mth
,
(
IndexInsnNode
)
insn
);
break
;
default
:
break
;
}
...
...
@@ -152,6 +159,31 @@ public class ModVisitor extends AbstractVisitor {
}
}
private
static
void
fixTypeForFieldAccess
(
MethodNode
mth
,
IndexInsnNode
insn
)
{
InsnArg
instanceArg
=
insn
.
getArg
(
insn
.
getType
()
==
InsnType
.
IGET
?
0
:
1
);
if
(
instanceArg
.
contains
(
AFlag
.
SUPER
))
{
return
;
}
if
(
instanceArg
.
isInsnWrap
()
&&
((
InsnWrapArg
)
instanceArg
).
getWrapInsn
().
getType
()
==
InsnType
.
CAST
)
{
return
;
}
FieldInfo
fieldInfo
=
(
FieldInfo
)
insn
.
getIndex
();
ArgType
clsType
=
fieldInfo
.
getDeclClass
().
getType
();
ArgType
instanceType
=
instanceArg
.
getType
();
TypeCompareEnum
result
=
mth
.
root
().
getTypeCompare
().
compareTypes
(
instanceType
,
clsType
);
if
(
result
.
isEqual
()
||
(
result
==
TypeCompareEnum
.
NARROW_BY_GENERIC
&&
!
instanceType
.
isGenericType
()))
{
return
;
}
IndexInsnNode
castInsn
=
new
IndexInsnNode
(
InsnType
.
CAST
,
clsType
,
1
);
castInsn
.
addArg
(
instanceArg
.
duplicate
());
castInsn
.
add
(
AFlag
.
EXPLICIT_CAST
);
InsnArg
castArg
=
InsnArg
.
wrapInsnIntoArg
(
castInsn
);
castArg
.
setType
(
clsType
);
insn
.
replaceArg
(
instanceArg
,
castArg
);
InsnRemover
.
unbindArgUsage
(
mth
,
instanceArg
);
}
private
static
void
replaceConstKeys
(
ClassNode
parentClass
,
SwitchInsn
insn
)
{
int
[]
keys
=
insn
.
getKeys
();
int
len
=
keys
.
length
;
...
...
jadx-core/src/test/java/jadx/tests/integration/types/TestFieldAccess.java
0 → 100644
浏览文件 @
ae31fee8
package
jadx.tests.integration.types
;
import
org.junit.jupiter.api.Test
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestFieldAccess
extends
IntegrationTest
{
public
static
class
TestCls
{
private
String
field
;
static
<
T
extends
TestCls
>
T
testPut
(
T
t
)
{
((
TestCls
)
t
).
field
=
""
;
return
t
;
}
static
<
T
extends
TestCls
>
T
testGet
(
T
t
)
{
System
.
out
.
println
(((
TestCls
)
t
).
field
);
return
t
;
}
}
@Test
public
void
test
()
{
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
doesNotContain
(
"t.field"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录