Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_39073359
jadx
提交
08c9d122
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,发现更多精彩内容 >>
提交
08c9d122
编写于
5月 02, 2014
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: inline 'cmp' instruction
上级
11d8b28f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
123 addition
and
0 deletion
+123
-0
jadx-core/src/main/java/jadx/core/dex/regions/Compare.java
jadx-core/src/main/java/jadx/core/dex/regions/Compare.java
+4
-0
jadx-core/src/main/java/jadx/core/dex/regions/IfCondition.java
...core/src/main/java/jadx/core/dex/regions/IfCondition.java
+20
-0
jadx-core/src/test/java/jadx/tests/internal/conditions/TestCmpOp.java
...c/test/java/jadx/tests/internal/conditions/TestCmpOp.java
+67
-0
jadx-core/src/test/java/jadx/tests/internal/conditions/TestCmpOp2.java
.../test/java/jadx/tests/internal/conditions/TestCmpOp2.java
+32
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/regions/Compare.java
浏览文件 @
08c9d122
...
...
@@ -24,6 +24,10 @@ public final class Compare {
return
insn
.
getArg
(
1
);
}
public
IfNode
getInsn
()
{
return
insn
;
}
public
Compare
invert
()
{
insn
.
invertCondition
();
return
this
;
...
...
jadx-core/src/main/java/jadx/core/dex/regions/IfCondition.java
浏览文件 @
08c9d122
...
...
@@ -2,10 +2,13 @@ package jadx.core.dex.regions;
import
jadx.core.dex.instructions.IfNode
;
import
jadx.core.dex.instructions.IfOp
;
import
jadx.core.dex.instructions.InsnType
;
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.RegisterArg
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
import
java.util.ArrayList
;
...
...
@@ -132,6 +135,7 @@ public final class IfCondition {
public
static
IfCondition
simplify
(
IfCondition
cond
)
{
if
(
cond
.
isCompare
())
{
Compare
c
=
cond
.
getCompare
();
simplifyCmpOp
(
c
);
if
(
c
.
getOp
()
==
IfOp
.
EQ
&&
c
.
getB
().
isLiteral
()
&&
c
.
getB
().
equals
(
LiteralArg
.
FALSE
))
{
return
not
(
new
IfCondition
(
c
.
invert
()));
}
else
{
...
...
@@ -177,6 +181,22 @@ public final class IfCondition {
return
cond
;
}
private
static
void
simplifyCmpOp
(
Compare
c
)
{
if
(!
c
.
getA
().
isInsnWrap
())
{
return
;
}
if
(!
c
.
getB
().
isLiteral
()
||
((
LiteralArg
)
c
.
getB
()).
getLiteral
()
!=
0
)
{
return
;
}
InsnNode
wrapInsn
=
((
InsnWrapArg
)
c
.
getA
()).
getWrapInsn
();
InsnType
type
=
wrapInsn
.
getType
();
if
(
type
!=
InsnType
.
CMP_L
&&
type
!=
InsnType
.
CMP_G
)
{
return
;
}
IfNode
insn
=
c
.
getInsn
();
insn
.
changeCondition
(
insn
.
getOp
(),
wrapInsn
.
getArg
(
0
),
wrapInsn
.
getArg
(
1
));
}
public
List
<
RegisterArg
>
getRegisterArgs
()
{
List
<
RegisterArg
>
list
=
new
LinkedList
<
RegisterArg
>();
if
(
mode
==
Mode
.
COMPARE
)
{
...
...
jadx-core/src/test/java/jadx/tests/internal/conditions/TestCmpOp.java
0 → 100644
浏览文件 @
08c9d122
package
jadx.tests.internal.conditions
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestCmpOp
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
boolean
testGT
(
float
a
)
{
return
a
>
3.0f
;
}
public
boolean
testLT
(
float
b
)
{
return
b
<
2.0f
;
}
public
boolean
testEQ
(
float
c
)
{
return
c
==
1.0f
;
}
public
boolean
testNE
(
float
d
)
{
return
d
!=
0.0f
;
}
public
boolean
testGE
(
float
e
)
{
return
e
>=
-
1.0f
;
}
public
boolean
testLE
(
float
f
)
{
return
f
<=
-
2.0f
;
}
public
boolean
testGT2
(
float
g
)
{
return
4.0f
>
g
;
}
public
boolean
testLT2
(
long
h
)
{
return
5
<
h
;
}
public
boolean
testGE2
(
double
i
)
{
return
6.5d
<
i
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"return a > 3.0f;"
));
assertThat
(
code
,
containsString
(
"return b < 2.0f;"
));
assertThat
(
code
,
containsString
(
"return c == 1.0f;"
));
assertThat
(
code
,
containsString
(
"return d != 0.0f;"
));
assertThat
(
code
,
containsString
(
"return e >= -1.0f;"
));
assertThat
(
code
,
containsString
(
"return f <= -2.0f;"
));
assertThat
(
code
,
containsString
(
"return 4.0f > g;"
));
assertThat
(
code
,
containsString
(
"return 5 < h;"
));
assertThat
(
code
,
containsString
(
"return 6.5d < i;"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/conditions/TestCmpOp2.java
0 → 100644
浏览文件 @
08c9d122
package
jadx.tests.internal.conditions
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestCmpOp2
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
boolean
testGT
(
float
a
,
float
b
)
{
return
a
>
b
;
}
public
boolean
testLT
(
float
c
,
double
d
)
{
return
c
<
d
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"return a > b;"
));
assertThat
(
code
,
containsString
(
"return ((double) c) < d;"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录