Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
05e5c82c
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,发现更多精彩内容 >>
提交
05e5c82c
编写于
4月 24, 2019
作者:
A
Ahmed Ashour
提交者:
skylot
4月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: remove redundant cast over similar conditions (PR #612)
上级
30fbf4bc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
12 deletion
+42
-12
jadx-core/src/main/java/jadx/core/codegen/ConditionGen.java
jadx-core/src/main/java/jadx/core/codegen/ConditionGen.java
+2
-1
jadx-core/src/main/java/jadx/core/dex/regions/conditions/IfCondition.java
...in/java/jadx/core/dex/regions/conditions/IfCondition.java
+24
-0
jadx-core/src/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
...c/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
+16
-1
jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions16.java
...a/jadx/tests/integration/conditions/TestConditions16.java
+0
-10
未找到文件。
jadx-core/src/main/java/jadx/core/codegen/ConditionGen.java
浏览文件 @
05e5c82c
...
@@ -4,6 +4,7 @@ import java.util.Iterator;
...
@@ -4,6 +4,7 @@ import java.util.Iterator;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.Queue
;
import
java.util.Queue
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.IfOp
;
import
jadx.core.dex.instructions.IfOp
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.InsnType
;
...
@@ -155,7 +156,7 @@ public class ConditionGen extends InsnGen {
...
@@ -155,7 +156,7 @@ public class ConditionGen extends InsnGen {
}
}
private
boolean
isWrapNeeded
(
IfCondition
condition
)
{
private
boolean
isWrapNeeded
(
IfCondition
condition
)
{
if
(
condition
.
isCompare
())
{
if
(
condition
.
isCompare
()
||
condition
.
contains
(
AFlag
.
DONT_WRAP
)
)
{
return
false
;
return
false
;
}
}
return
condition
.
getMode
()
!=
Mode
.
NOT
;
return
condition
.
getMode
()
!=
Mode
.
NOT
;
...
...
jadx-core/src/main/java/jadx/core/dex/regions/conditions/IfCondition.java
浏览文件 @
05e5c82c
...
@@ -8,6 +8,9 @@ import java.util.LinkedList;
...
@@ -8,6 +8,9 @@ import java.util.LinkedList;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AttributeStorage
;
import
jadx.core.dex.attributes.EmptyAttrStorage
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithOp
;
import
jadx.core.dex.instructions.ArithOp
;
import
jadx.core.dex.instructions.IfNode
;
import
jadx.core.dex.instructions.IfNode
;
...
@@ -31,6 +34,10 @@ public final class IfCondition {
...
@@ -31,6 +34,10 @@ public final class IfCondition {
OR
OR
}
}
private
static
final
AttributeStorage
EMPTY_ATTR_STORAGE
=
new
EmptyAttrStorage
();
private
AttributeStorage
storage
=
EMPTY_ATTR_STORAGE
;
private
final
Mode
mode
;
private
final
Mode
mode
;
private
final
List
<
IfCondition
>
args
;
private
final
List
<
IfCondition
>
args
;
private
final
Compare
compare
;
private
final
Compare
compare
;
...
@@ -262,6 +269,23 @@ public final class IfCondition {
...
@@ -262,6 +269,23 @@ public final class IfCondition {
return
list
;
return
list
;
}
}
public
void
add
(
AFlag
flag
)
{
initStorage
().
add
(
flag
);
}
public
boolean
contains
(
AFlag
flag
)
{
return
storage
.
contains
(
flag
);
}
private
AttributeStorage
initStorage
()
{
AttributeStorage
store
=
storage
;
if
(
store
==
EMPTY_ATTR_STORAGE
)
{
store
=
new
AttributeStorage
();
storage
=
store
;
}
return
store
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
switch
(
mode
)
{
switch
(
mode
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
浏览文件 @
05e5c82c
...
@@ -11,9 +11,12 @@ import jadx.core.dex.instructions.args.InsnArg;
...
@@ -11,9 +11,12 @@ import jadx.core.dex.instructions.args.InsnArg;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.instructions.mods.TernaryInsn
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.regions.conditions.IfCondition
;
import
jadx.core.dex.regions.conditions.IfCondition.Mode
;
import
jadx.core.dex.visitors.regions.variables.ProcessVariables
;
import
jadx.core.dex.visitors.regions.variables.ProcessVariables
;
import
jadx.core.dex.visitors.shrink.CodeShrinkVisitor
;
import
jadx.core.dex.visitors.shrink.CodeShrinkVisitor
;
import
jadx.core.utils.exceptions.JadxException
;
import
jadx.core.utils.exceptions.JadxException
;
...
@@ -104,7 +107,7 @@ public class PrepareForCodeGen extends AbstractVisitor {
...
@@ -104,7 +107,7 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
}
/**
/**
* Remove parenthesis for wrapped insn
in arith '+' or '-'
* Remove parenthesis for wrapped insn in arith '+' or '-'
* ('(a + b) +c' => 'a + b + c')
* ('(a + b) +c' => 'a + b + c')
*/
*/
private
static
void
removeParenthesis
(
InsnNode
insn
)
{
private
static
void
removeParenthesis
(
InsnNode
insn
)
{
...
@@ -124,6 +127,9 @@ public class PrepareForCodeGen extends AbstractVisitor {
...
@@ -124,6 +127,9 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
}
}
}
}
else
{
}
else
{
if
(
insn
.
getType
()
==
InsnType
.
TERNARY
)
{
removeParenthesis
(((
TernaryInsn
)
insn
).
getCondition
());
}
for
(
InsnArg
arg
:
insn
.
getArguments
())
{
for
(
InsnArg
arg
:
insn
.
getArguments
())
{
if
(
arg
.
isInsnWrap
())
{
if
(
arg
.
isInsnWrap
())
{
InsnNode
wrapInsn
=
((
InsnWrapArg
)
arg
).
getWrapInsn
();
InsnNode
wrapInsn
=
((
InsnWrapArg
)
arg
).
getWrapInsn
();
...
@@ -133,6 +139,15 @@ public class PrepareForCodeGen extends AbstractVisitor {
...
@@ -133,6 +139,15 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
}
}
}
private
static
void
removeParenthesis
(
IfCondition
cond
)
{
Mode
mode
=
cond
.
getMode
();
for
(
IfCondition
c
:
cond
.
getArgs
())
{
if
(
c
.
getMode
()
==
mode
)
{
c
.
add
(
AFlag
.
DONT_WRAP
);
}
}
}
/**
/**
* Replace arithmetic operation with short form
* Replace arithmetic operation with short form
* ('a = a + 2' => 'a += 2')
* ('a = a + 2' => 'a += 2')
...
...
jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions16.java
浏览文件 @
05e5c82c
...
@@ -2,7 +2,6 @@ package jadx.tests.integration.conditions;
...
@@ -2,7 +2,6 @@ package jadx.tests.integration.conditions;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
jadx.tests.api.IntegrationTest
;
...
@@ -27,19 +26,10 @@ public class TestConditions16 extends IntegrationTest {
...
@@ -27,19 +26,10 @@ public class TestConditions16 extends IntegrationTest {
}
}
@Test
@Test
@NotYetImplemented
public
void
test
()
{
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"return a < 0 || (b % 2 != 0 && a > 28) || b < 0;"
));
assertThat
(
code
,
containsOne
(
"return a < 0 || (b % 2 != 0 && a > 28) || b < 0;"
));
}
}
@Test
public
void
test2
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"return a < 0 || ((b % 2 != 0 && a > 28) || b < 0);"
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录