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
eb77aa51
Commit
eb77aa51
authored
Apr 12, 2019
by
Ahmed Ashour
Committed by
skylot
Apr 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: conditions in ternary if (#449) (PR #558)
parent
ac1d1a58
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
217 additions
and
2 deletions
+217
-2
IfCondition.java
...in/java/jadx/core/dex/regions/conditions/IfCondition.java
+31
-1
TestTernaryInIf.java
...va/jadx/tests/integration/conditions/TestTernaryInIf.java
+1
-1
TestTernaryInIf2.java
...a/jadx/tests/integration/conditions/TestTernaryInIf2.java
+42
-0
TestTernaryInIf2.smali
jadx-core/src/test/smali/conditions/TestTernaryInIf2.smali
+143
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/regions/conditions/IfCondition.java
View file @
eb77aa51
...
...
@@ -6,6 +6,7 @@ import java.util.Collections;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Objects
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithOp
;
...
...
@@ -118,7 +119,7 @@ public final class IfCondition {
case
COMPARE:
return
new
IfCondition
(
cond
.
getCompare
().
invert
());
case
TERNARY:
return
ternary
(
not
(
cond
.
first
()),
cond
.
third
(),
cond
.
second
(
));
return
ternary
(
cond
.
first
(),
not
(
cond
.
second
()),
not
(
cond
.
third
()
));
case
NOT:
return
cond
.
first
();
case
AND:
...
...
@@ -137,6 +138,9 @@ public final class IfCondition {
if
(
cond
.
getMode
()
==
Mode
.
NOT
)
{
return
cond
.
first
();
}
if
(
cond
.
getCompare
()
!=
null
)
{
return
new
IfCondition
(
cond
.
compare
.
invert
());
}
return
new
IfCondition
(
Mode
.
NOT
,
Collections
.
singletonList
(
cond
));
}
...
...
@@ -281,4 +285,30 @@ public final class IfCondition {
}
return
"??"
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(!(
obj
instanceof
IfCondition
))
{
return
false
;
}
IfCondition
other
=
(
IfCondition
)
obj
;
if
(
mode
!=
other
.
mode
)
{
return
false
;
}
return
Objects
.
equals
(
other
.
args
,
other
.
args
)
&&
Objects
.
equals
(
compare
,
other
.
compare
);
}
@Override
public
int
hashCode
()
{
int
result
=
super
.
hashCode
();
result
=
31
*
result
+
mode
.
hashCode
();
result
=
31
*
result
+
args
.
hashCode
();
result
=
31
*
result
+
(
compare
!=
null
?
compare
.
hashCode
()
:
0
);
return
result
;
}
}
jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryInIf.java
View file @
eb77aa51
...
...
@@ -18,7 +18,7 @@ public class TestTernaryInIf extends IntegrationTest {
}
public
int
test2
(
boolean
a
,
boolean
b
,
boolean
c
)
{
return
(
a
?
b
:
c
)
?
1
:
2
;
return
(
!
a
?
c
:
b
)
?
1
:
2
;
}
}
...
...
jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryInIf2.java
0 → 100644
View file @
eb77aa51
package
jadx
.
tests
.
integration
.
conditions
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsLines
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
public
class
TestTernaryInIf2
extends
SmaliTest
{
public
static
class
TestCls
{
private
String
a
;
private
String
b
;
public
boolean
equals
(
TestCls
other
)
{
if
(
this
.
a
==
null
?
other
.
a
==
null
:
this
.
a
.
equals
(
other
.
a
))
{
if
(
this
.
b
==
null
?
other
.
b
==
null
:
this
.
b
.
equals
(
other
.
b
))
{
return
true
;
}
}
return
false
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsLines
(
2
,
"if (this.a != null ? this.a.equals(other.a) : other.a == null) {"
));
assertThat
(
code
,
containsLines
(
3
,
"if (this.b != null ? this.b.equals(other.b) : other.b == null) {"
));
assertThat
(
code
,
containsLines
(
4
,
"return true;"
));
assertThat
(
code
,
containsLines
(
2
,
"return false;"
));
}
@Test
public
void
test2
()
{
getClassNodeFromSmaliWithPath
(
"conditions"
,
"TestTernaryInIf2"
);
}
}
jadx-core/src/test/smali/conditions/TestTernaryInIf2.smali
0 → 100644
View file @
eb77aa51
.class public LTestTernaryInIf2;
.super Ljava/lang/Object;
# instance fields
.field private a:Ljava/lang/String;
.field private b:Ljava/lang/String;
.field private c:Ljava/lang/String;
# direct methods
.method public constructor <init>()V
.locals 0
.line 10
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
# virtual methods
.method public equals(Ljava/lang/Object;)Z
.locals 4
const/4 v0, 0x1
if-ne p0, p1, :cond_0
return v0
:cond_0
const/4 v1, 0x0
if-eqz p1, :cond_a
.line 110
invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;
move-result-object v2
invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;
move-result-object v3
if-eq v2, v3, :cond_1
goto :goto_4
.line 112
:cond_1
check-cast p1, LTestTernaryInIf2;
.line 114
iget-object v2, p0, LTestTernaryInIf2;->a:Ljava/lang/String;
if-eqz v2, :cond_2
iget-object v2, p0, LTestTernaryInIf2;->a:Ljava/lang/String;
iget-object v3, p1, LTestTernaryInIf2;->a:Ljava/lang/String;
invoke-virtual {v2, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v2
if-nez v2, :cond_3
goto :goto_0
:cond_2
iget-object v2, p1, LTestTernaryInIf2;->a:Ljava/lang/String;
if-eqz v2, :cond_3
:goto_0
return v1
.line 116
:cond_3
iget-object v2, p0, LTestTernaryInIf2;->b:Ljava/lang/String;
if-eqz v2, :cond_4
iget-object v2, p0, LTestTernaryInIf2;->b:Ljava/lang/String;
iget-object v3, p1, LTestTernaryInIf2;->b:Ljava/lang/String;
invoke-virtual {v2, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v2
if-nez v2, :cond_5
goto :goto_1
:cond_4
iget-object v2, p1, LTestTernaryInIf2;->b:Ljava/lang/String;
if-eqz v2, :cond_5
:goto_1
return v1
.line 118
:cond_5
iget-object v2, p0, LTestTernaryInIf2;->c:Ljava/lang/String;
if-eqz v2, :cond_6
iget-object v2, p0, LTestTernaryInIf2;->c:Ljava/lang/String;
iget-object v3, p1, LTestTernaryInIf2;->c:Ljava/lang/String;
invoke-virtual {v2, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v2
if-nez v2, :cond_7
return v1
:cond_6
iget-object v2, p1, LTestTernaryInIf2;->c:Ljava/lang/String;
if-eqz v2, :cond_7
.line 120
:cond_7
:cond_8
const/4 v0, 0x0
:goto_3
return v0
:cond_a
:goto_4
return v1
.end method
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