Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_39073359
jadx
提交
72381ad8
J
jadx
项目概览
qq_39073359
/
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,发现更多精彩内容 >>
未验证
提交
72381ad8
编写于
1月 13, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: correct literal negate for double and float (#1334)
上级
6a065c46
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
109 addition
and
26 deletion
+109
-26
jadx-core/src/main/java/jadx/core/dex/instructions/args/LiteralArg.java
...main/java/jadx/core/dex/instructions/args/LiteralArg.java
+44
-6
jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
...src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
+32
-20
jadx-core/src/test/java/jadx/tests/integration/arith/TestPrimitivesNegate.java
...va/jadx/tests/integration/arith/TestPrimitivesNegate.java
+33
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/instructions/args/LiteralArg.java
浏览文件 @
72381ad8
package
jadx.core.dex.instructions.args
;
import
org.jetbrains.annotations.Nullable
;
import
jadx.core.codegen.TypeGen
;
import
jadx.core.utils.StringUtils
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
...
...
@@ -57,12 +59,48 @@ public final class LiteralArg extends InsnArg {
}
public
boolean
isInteger
()
{
PrimitiveType
type
=
this
.
type
.
getPrimitiveType
();
return
type
==
PrimitiveType
.
INT
||
type
==
PrimitiveType
.
BYTE
||
type
==
PrimitiveType
.
CHAR
||
type
==
PrimitiveType
.
SHORT
||
type
==
PrimitiveType
.
LONG
;
switch
(
type
.
getPrimitiveType
())
{
case
INT:
case
BYTE:
case
CHAR:
case
SHORT:
case
LONG:
return
true
;
default
:
return
false
;
}
}
public
boolean
isNegative
()
{
if
(
isInteger
())
{
return
literal
<
0
;
}
if
(
type
==
ArgType
.
FLOAT
)
{
float
val
=
Float
.
intBitsToFloat
(((
int
)
literal
));
return
val
<
0
&&
Float
.
isFinite
(
val
);
}
if
(
type
==
ArgType
.
DOUBLE
)
{
double
val
=
Double
.
longBitsToDouble
(
literal
);
return
val
<
0
&&
Double
.
isFinite
(
val
);
}
return
false
;
}
@Nullable
public
LiteralArg
negate
()
{
long
neg
;
if
(
isInteger
())
{
neg
=
-
literal
;
}
else
if
(
type
==
ArgType
.
FLOAT
)
{
float
val
=
Float
.
intBitsToFloat
(((
int
)
literal
));
neg
=
Float
.
floatToIntBits
(-
val
);
}
else
if
(
type
==
ArgType
.
DOUBLE
)
{
double
val
=
Double
.
longBitsToDouble
(
literal
);
neg
=
Double
.
doubleToLongBits
(-
val
);
}
else
{
return
null
;
}
return
new
LiteralArg
(
neg
,
type
);
}
@Override
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
浏览文件 @
72381ad8
...
...
@@ -532,32 +532,44 @@ public class SimplifyVisitor extends AbstractVisitor {
if
(
arith
.
getArgsCount
()
!=
2
)
{
return
null
;
}
Insn
Arg
litArg
=
null
;
Literal
Arg
litArg
=
null
;
InsnArg
secondArg
=
arith
.
getArg
(
1
);
if
(
secondArg
.
isInsnWrap
())
{
InsnNode
wr
=
((
InsnWrapArg
)
secondArg
).
getWrapInsn
();
if
(
wr
.
getType
()
==
InsnType
.
CONST
)
{
litArg
=
wr
.
getArg
(
0
);
InsnArg
arg
=
wr
.
getArg
(
0
);
if
(
arg
.
isLiteral
())
{
litArg
=
(
LiteralArg
)
arg
;
}
}
}
else
if
(
secondArg
.
isLiteral
())
{
litArg
=
secondArg
;
}
if
(
litArg
!=
null
)
{
long
lit
=
((
LiteralArg
)
litArg
).
getLiteral
();
// fix 'c + (-1)' => 'c - (1)'
if
(
arith
.
getOp
()
==
ArithOp
.
ADD
&&
lit
<
0
)
{
return
new
ArithNode
(
ArithOp
.
SUB
,
arith
.
getResult
(),
arith
.
getArg
(
0
),
InsnArg
.
lit
(-
lit
,
litArg
.
getType
()));
}
InsnArg
firstArg
=
arith
.
getArg
(
0
);
if
(
arith
.
getOp
()
==
ArithOp
.
XOR
&&
firstArg
.
getType
()
==
ArgType
.
BOOLEAN
&&
(
lit
==
0
||
lit
==
1
))
{
InsnNode
node
=
new
InsnNode
(
lit
==
0
?
InsnType
.
MOVE
:
InsnType
.
NOT
,
1
);
node
.
setResult
(
arith
.
getResult
());
node
.
addArg
(
firstArg
);
return
node
;
}
litArg
=
(
LiteralArg
)
secondArg
;
}
if
(
litArg
==
null
)
{
return
null
;
}
switch
(
arith
.
getOp
())
{
case
ADD:
// fix 'c + (-1)' to 'c - (1)'
if
(
litArg
.
isNegative
())
{
LiteralArg
negLitArg
=
litArg
.
negate
();
if
(
negLitArg
!=
null
)
{
return
new
ArithNode
(
ArithOp
.
SUB
,
arith
.
getResult
(),
arith
.
getArg
(
0
),
negLitArg
);
}
}
break
;
case
XOR:
// simplify xor on boolean
InsnArg
firstArg
=
arith
.
getArg
(
0
);
long
lit
=
litArg
.
getLiteral
();
if
(
firstArg
.
getType
()
==
ArgType
.
BOOLEAN
&&
(
lit
==
0
||
lit
==
1
))
{
InsnNode
node
=
new
InsnNode
(
lit
==
0
?
InsnType
.
MOVE
:
InsnType
.
NOT
,
1
);
node
.
setResult
(
arith
.
getResult
());
node
.
addArg
(
firstArg
);
return
node
;
}
break
;
}
return
null
;
}
...
...
jadx-core/src/test/java/jadx/tests/integration/arith/TestPrimitivesNegate.java
0 → 100644
浏览文件 @
72381ad8
package
jadx.tests.integration.arith
;
import
jadx.tests.api.IntegrationTest
;
import
jadx.tests.api.extensions.profiles.TestProfile
;
import
jadx.tests.api.extensions.profiles.TestWithProfiles
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestPrimitivesNegate
extends
IntegrationTest
{
@SuppressWarnings
(
"UnnecessaryUnaryMinus"
)
public
static
class
TestCls
{
public
double
test
()
{
double
[]
arr
=
new
double
[
5
];
arr
[
0
]
=
-
20
;
arr
[
0
]
+=
-
79
;
return
arr
[
0
];
}
public
void
check
()
{
assertThat
(
test
()).
isEqualTo
(-
99
);
}
}
@TestWithProfiles
({
TestProfile
.
DX_J8
,
TestProfile
.
JAVA8
})
public
void
test
()
{
noDebugInfo
();
assertThat
(
getClassNode
(
TestCls
.
class
))
.
code
()
.
containsOne
(
"dArr[0] = -20.0d;"
)
.
containsOne
(
"dArr[0] = dArr[0] - 79.0d;"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录