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
08c9d122
Commit
08c9d122
authored
May 02, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: inline 'cmp' instruction
parent
11d8b28f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
0 deletions
+123
-0
Compare.java
jadx-core/src/main/java/jadx/core/dex/regions/Compare.java
+4
-0
IfCondition.java
...core/src/main/java/jadx/core/dex/regions/IfCondition.java
+20
-0
TestCmpOp.java
...c/test/java/jadx/tests/internal/conditions/TestCmpOp.java
+67
-0
TestCmpOp2.java
.../test/java/jadx/tests/internal/conditions/TestCmpOp2.java
+32
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/regions/Compare.java
View file @
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
View file @
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
View file @
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
View file @
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;"
));
}
}
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