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
f366eac7
Commit
f366eac7
authored
Mar 01, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix switch in loop (fix #52)
parent
46d3992b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
6 deletions
+55
-6
RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+11
-6
TestSwitchInLoop.java
...ava/jadx/tests/integration/switches/TestSwitchInLoop.java
+44
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
View file @
f366eac7
...
...
@@ -663,7 +663,8 @@ public class RegionMaker {
Map
<
BlockNode
,
BlockNode
>
fallThroughCases
=
new
LinkedHashMap
<
BlockNode
,
BlockNode
>();
BitSet
outs
=
new
BitSet
(
mth
.
getBasicBlocks
().
size
());
List
<
BlockNode
>
basicBlocks
=
mth
.
getBasicBlocks
();
BitSet
outs
=
new
BitSet
(
basicBlocks
.
size
());
outs
.
or
(
block
.
getDomFrontier
());
for
(
BlockNode
s
:
block
.
getCleanSuccessors
())
{
BitSet
df
=
s
.
getDomFrontier
();
...
...
@@ -672,8 +673,8 @@ public class RegionMaker {
if
(
df
.
cardinality
()
>
2
)
{
LOG
.
debug
(
"Unexpected case pattern, block: {}, mth: {}"
,
s
,
mth
);
}
else
{
BlockNode
first
=
mth
.
getBasicBlocks
()
.
get
(
df
.
nextSetBit
(
0
));
BlockNode
second
=
mth
.
getBasicBlocks
()
.
get
(
df
.
nextSetBit
(
first
.
getId
()
+
1
));
BlockNode
first
=
basicBlocks
.
get
(
df
.
nextSetBit
(
0
));
BlockNode
second
=
basicBlocks
.
get
(
df
.
nextSetBit
(
first
.
getId
()
+
1
));
if
(
second
.
getDomFrontier
().
get
(
first
.
getId
()))
{
fallThroughCases
.
put
(
s
,
second
);
df
=
new
BitSet
(
df
.
size
());
...
...
@@ -687,6 +688,11 @@ public class RegionMaker {
}
outs
.
or
(
df
);
}
outs
.
clear
(
block
.
getId
());
if
(
loop
!=
null
)
{
outs
.
clear
(
loop
.
getStart
().
getId
());
}
stack
.
push
(
sw
);
stack
.
addExits
(
BlockUtils
.
bitSetToBlocks
(
mth
,
outs
));
...
...
@@ -709,9 +715,8 @@ public class RegionMaker {
}
if
(
outs
.
cardinality
()
>
1
)
{
// filter loop start and successors of other blocks
List
<
BlockNode
>
blocks
=
mth
.
getBasicBlocks
();
for
(
int
i
=
outs
.
nextSetBit
(
0
);
i
>=
0
;
i
=
outs
.
nextSetBit
(
i
+
1
))
{
BlockNode
b
=
blocks
.
get
(
i
);
BlockNode
b
=
b
asicB
locks
.
get
(
i
);
outs
.
andNot
(
b
.
getDomFrontier
());
if
(
b
.
contains
(
AFlag
.
LOOP_START
))
{
outs
.
clear
(
b
.
getId
());
...
...
@@ -745,7 +750,7 @@ public class RegionMaker {
}
BlockNode
out
=
null
;
if
(
outs
.
cardinality
()
==
1
)
{
out
=
mth
.
getBasicBlocks
()
.
get
(
outs
.
nextSetBit
(
0
));
out
=
basicBlocks
.
get
(
outs
.
nextSetBit
(
0
));
stack
.
addExit
(
out
);
}
else
if
(
loop
==
null
&&
outs
.
cardinality
()
>
1
)
{
LOG
.
warn
(
"Can't detect out node for switch block: {} in {}"
,
block
,
mth
);
...
...
jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchInLoop.java
0 → 100644
View file @
f366eac7
package
jadx
.
tests
.
integration
.
switches
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestSwitchInLoop
extends
IntegrationTest
{
public
static
class
TestCls
{
public
int
test
(
int
k
)
{
int
a
=
0
;
while
(
true
)
{
switch
(
k
)
{
case
0
:
return
a
;
default
:
a
++;
k
>>=
1
;
}
}
}
public
void
check
()
{
assertEquals
(
1
,
test
(
1
));
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"switch (k) {"
));
assertThat
(
code
,
containsOne
(
"case 0:"
));
assertThat
(
code
,
containsOne
(
"return a;"
));
assertThat
(
code
,
containsOne
(
"default:"
));
assertThat
(
code
,
containsOne
(
"a++;"
));
assertThat
(
code
,
containsOne
(
"k >>= 1;"
));
}
}
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