Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
1bbcac2a
J
jadx
项目概览
2301_76393173
/
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,发现更多精彩内容 >>
提交
1bbcac2a
编写于
9月 13, 2020
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: handle xor on boolean (#921)
上级
60b2353a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
105 addition
and
9 deletion
+105
-9
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java
...core/dex/visitors/typeinference/TypeInferenceVisitor.java
+38
-9
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver15.java
...java/jadx/tests/integration/types/TestTypeResolver15.java
+40
-0
jadx-core/src/test/smali/types/TestTypeResolver15.smali
jadx-core/src/test/smali/types/TestTypeResolver15.smali
+27
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java
浏览文件 @
1bbcac2a
...
...
@@ -20,6 +20,8 @@ import jadx.core.dex.attributes.AFlag;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.nodes.PhiListAttr
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithOp
;
import
jadx.core.dex.instructions.BaseInvokeNode
;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.InsnType
;
...
...
@@ -759,7 +761,8 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
private
boolean
fixBooleanUsage
(
MethodNode
mth
,
ITypeBound
bound
)
{
ArgType
boundType
=
bound
.
getType
();
if
(!
boundType
.
isPrimitive
()
||
boundType
==
ArgType
.
BOOLEAN
)
{
if
(
boundType
==
ArgType
.
BOOLEAN
||
(
boundType
.
isTypeKnown
()
&&
!
boundType
.
isPrimitive
()))
{
return
false
;
}
RegisterArg
boundArg
=
bound
.
getArg
();
...
...
@@ -767,7 +770,7 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
return
false
;
}
InsnNode
insn
=
boundArg
.
getParentInsn
();
if
(
insn
==
null
)
{
if
(
insn
==
null
||
insn
.
getType
()
==
InsnType
.
IF
)
{
return
false
;
}
BlockNode
blockNode
=
BlockUtils
.
getBlockByInsn
(
mth
,
insn
);
...
...
@@ -779,21 +782,47 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
if
(
insnIndex
==
-
1
)
{
return
false
;
}
if
(
insn
.
getType
()
==
InsnType
.
CAST
)
{
InsnType
insnType
=
insn
.
getType
();
if
(
insnType
==
InsnType
.
CAST
)
{
// replace cast
ArgType
type
=
(
ArgType
)
((
IndexInsnNode
)
insn
).
getIndex
();
TernaryInsn
convertInsn
=
prepareBooleanConvertInsn
(
insn
.
getResult
(),
boundArg
,
type
);
BlockUtils
.
replaceInsn
(
mth
,
blockNode
,
insnIndex
,
convertInsn
);
}
else
{
// insert before insn
RegisterArg
resultArg
=
boundArg
.
duplicateWithNewSSAVar
(
mth
);
TernaryInsn
convertInsn
=
prepareBooleanConvertInsn
(
resultArg
,
boundArg
,
boundType
);
insnList
.
add
(
insnIndex
,
convertInsn
);
insn
.
replaceArg
(
bound
.
getArg
(),
convertInsn
.
getResult
().
duplicate
());
return
true
;
}
if
(
insnType
==
InsnType
.
ARITH
)
{
ArithNode
arithInsn
=
(
ArithNode
)
insn
;
if
(
arithInsn
.
getOp
()
==
ArithOp
.
XOR
&&
arithInsn
.
getArgsCount
()
==
2
)
{
// replace (boolean ^ 1) with (!boolean)
InsnArg
secondArg
=
arithInsn
.
getArg
(
1
);
if
(
secondArg
.
isLiteral
()
&&
((
LiteralArg
)
secondArg
).
getLiteral
()
==
1
)
{
InsnNode
convertInsn
=
notBooleanToInt
(
arithInsn
,
boundArg
);
BlockUtils
.
replaceInsn
(
mth
,
blockNode
,
insnIndex
,
convertInsn
);
return
true
;
}
}
}
// insert before insn
RegisterArg
resultArg
=
boundArg
.
duplicateWithNewSSAVar
(
mth
);
TernaryInsn
convertInsn
=
prepareBooleanConvertInsn
(
resultArg
,
boundArg
,
boundType
);
insnList
.
add
(
insnIndex
,
convertInsn
);
insn
.
replaceArg
(
boundArg
,
convertInsn
.
getResult
().
duplicate
());
return
true
;
}
private
InsnNode
notBooleanToInt
(
ArithNode
insn
,
RegisterArg
boundArg
)
{
InsnNode
notInsn
=
new
InsnNode
(
InsnType
.
NOT
,
1
);
notInsn
.
addArg
(
boundArg
.
duplicate
());
notInsn
.
add
(
AFlag
.
SYNTHETIC
);
InsnArg
notArg
=
InsnArg
.
wrapArg
(
notInsn
);
notArg
.
setType
(
ArgType
.
BOOLEAN
);
TernaryInsn
convertInsn
=
ModVisitor
.
makeBooleanConvertInsn
(
insn
.
getResult
(),
notArg
,
ArgType
.
INT
);
convertInsn
.
add
(
AFlag
.
SYNTHETIC
);
return
convertInsn
;
}
private
TernaryInsn
prepareBooleanConvertInsn
(
RegisterArg
resultArg
,
RegisterArg
boundArg
,
ArgType
useType
)
{
RegisterArg
useArg
=
boundArg
.
getSVar
().
getAssign
().
duplicate
();
TernaryInsn
convertInsn
=
ModVisitor
.
makeBooleanConvertInsn
(
resultArg
,
useArg
,
useType
);
...
...
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver15.java
0 → 100644
浏览文件 @
1bbcac2a
package
jadx.tests.integration.types
;
import
org.junit.jupiter.api.Test
;
import
jadx.tests.api.SmaliTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
/**
* Issue 921 (second case)
*/
public
class
TestTypeResolver15
extends
SmaliTest
{
public
static
class
TestCls
{
private
void
test
(
boolean
z
)
{
useInt
(
z
?
0
:
8
);
useInt
(!
z
?
1
:
0
);
// replaced with xor in smali test
}
private
void
useInt
(
int
i
)
{
}
}
@Test
public
void
test
()
{
noDebugInfo
();
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
// .containsOne("useInt(!z ? 1 : 0);") // TODO: convert to ternary
.
containsOne
(
"useInt(z ? 0 : 8);"
);
}
@Test
public
void
testSmali
()
{
assertThat
(
getClassNodeFromSmali
())
.
code
()
.
containsOne
(
"useInt(z ? 0 : 8);"
)
.
containsOne
(
"useInt(!z ? 1 : 0);"
);
}
}
jadx-core/src/test/smali/types/TestTypeResolver15.smali
0 → 100644
浏览文件 @
1bbcac2a
.class public Ltypes/TestTypeResolver15;
.super Ljava/lang/Object;
.method private test(Z)V
.locals 2
if-eqz p1, :cond_0
const/4 v1, 0x0
goto :goto_0
:cond_0
const/16 v1, 0x8
:goto_0
invoke-virtual {p0, v1}, Ltypes/TestTypeResolver15;->useInt(I)V
xor-int/lit8 p1, p1, 0x1
invoke-virtual {p0, p1}, Ltypes/TestTypeResolver15;->useInt(I)V
return-void
.end method
.method private useInt(I)V
.registers 2
return-void
.end method
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录