Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
058e4c9f
Commit
058e4c9f
authored
Apr 04, 2019
by
Ahmed Ashour
Committed by
skylot
Apr 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove redundant wrapping for same arith operations (PR #559)
parent
9d257cd1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
8 deletions
+42
-8
ArithOp.java
...ore/src/main/java/jadx/core/dex/instructions/ArithOp.java
+6
-0
InsnArg.java
...rc/main/java/jadx/core/dex/instructions/args/InsnArg.java
+8
-0
TestArith2.java
...rc/test/java/jadx/tests/integration/arith/TestArith2.java
+28
-8
No files found.
jadx-core/src/main/java/jadx/core/dex/instructions/ArithOp.java
View file @
058e4c9f
...
...
@@ -25,4 +25,10 @@ public enum ArithOp {
return
this
.
symbol
;
}
public
boolean
noWrapWith
(
ArithOp
other
)
{
return
(
this
==
ADD
&&
other
==
ADD
)
||
(
this
==
MUL
&&
other
==
MUL
)
||
(
this
==
AND
&&
other
==
AND
)
||
(
this
==
OR
&&
other
==
OR
);
}
}
jadx-core/src/main/java/jadx/core/dex/instructions/args/InsnArg.java
View file @
058e4c9f
...
...
@@ -9,6 +9,8 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.utils.InsnUtils
;
...
...
@@ -111,6 +113,12 @@ public abstract class InsnArg extends Typed {
insn
.
add
(
AFlag
.
WRAPPED
);
InsnArg
arg
=
wrapArg
(
insn
);
parent
.
setArg
(
i
,
arg
);
if
(
insn
.
getType
()
==
InsnType
.
ARITH
&&
parent
.
getType
()
==
InsnType
.
ARITH
&&
((
ArithNode
)
insn
).
getOp
().
noWrapWith
(((
ArithNode
)
parent
).
getOp
()))
{
insn
.
add
(
AFlag
.
DONT_WRAP
);
}
return
arg
;
}
...
...
jadx-core/src/test/java/jadx/tests/integration/arith/TestArith2.java
View file @
058e4c9f
...
...
@@ -6,7 +6,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
...
...
@@ -21,6 +20,22 @@ public class TestArith2 extends IntegrationTest {
public
int
test2
(
int
a
,
int
b
,
int
c
)
{
return
a
+
b
+
c
;
}
public
boolean
test3
(
boolean
a
,
boolean
b
,
boolean
c
)
{
return
a
|
b
|
c
;
}
public
boolean
test4
(
boolean
a
,
boolean
b
,
boolean
c
)
{
return
a
&
b
&
c
;
}
public
int
substract
(
int
a
,
int
b
,
int
c
)
{
return
a
-
(
b
-
c
);
}
public
int
divide
(
int
a
,
int
b
,
int
c
)
{
return
a
/
(
b
/
c
);
}
}
@Test
...
...
@@ -30,15 +45,20 @@ public class TestArith2 extends IntegrationTest {
assertThat
(
code
,
containsString
(
"return (a + 2) * 3;"
));
assertThat
(
code
,
not
(
containsString
(
"a + 2 * 3"
)));
}
@Test
@NotYetImplemented
public
void
test2
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"return a + b + c;"
));
assertThat
(
code
,
not
(
containsString
(
"return (a + b) + c;"
)));
assertThat
(
code
,
containsString
(
"return a | b | c;"
));
assertThat
(
code
,
not
(
containsString
(
"return (a | b) | c;"
)));
assertThat
(
code
,
containsString
(
"return a & b & c;"
));
assertThat
(
code
,
not
(
containsString
(
"return (a & b) & c;"
)));
assertThat
(
code
,
containsString
(
"return a - (b - c);"
));
assertThat
(
code
,
not
(
containsString
(
"return a - b - c;"
)));
assertThat
(
code
,
containsString
(
"return a / (b / c);"
));
assertThat
(
code
,
not
(
containsString
(
"return a / b / c;"
)));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment