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
b2f0f025
Commit
b2f0f025
authored
Jun 26, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix incorrectly removed 'return' in 'switch' block (fix #70)
parent
71f24911
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
1 deletion
+69
-1
MethodNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
+2
-0
RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+4
-1
ReturnVisitor.java
...in/java/jadx/core/dex/visitors/regions/ReturnVisitor.java
+8
-0
TestSwitch3.java
...est/java/jadx/tests/integration/switches/TestSwitch3.java
+55
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
View file @
b2f0f025
...
...
@@ -35,6 +35,7 @@ import java.util.Map;
import
java.util.Set
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -442,6 +443,7 @@ public class MethodNode extends LineAttrNode implements ILoadable {
loops
.
add
(
loop
);
}
@Nullable
public
LoopInfo
getLoopForBlock
(
BlockNode
block
)
{
if
(
loops
.
isEmpty
())
{
return
null
;
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
View file @
b2f0f025
...
...
@@ -30,6 +30,7 @@ import jadx.core.utils.ErrorsCounter;
import
jadx.core.utils.InstructionRemover
;
import
jadx.core.utils.RegionUtils
;
import
jadx.core.utils.exceptions.JadxOverflowException
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
import
java.util.ArrayList
;
import
java.util.BitSet
;
...
...
@@ -690,7 +691,9 @@ public class RegionMaker {
Map
<
BlockNode
,
List
<
Object
>>
blocksMap
=
new
LinkedHashMap
<
BlockNode
,
List
<
Object
>>(
len
);
for
(
Map
.
Entry
<
Integer
,
List
<
Object
>>
entry
:
casesMap
.
entrySet
())
{
BlockNode
c
=
getBlockByOffset
(
entry
.
getKey
(),
block
.
getSuccessors
());
assert
c
!=
null
;
if
(
c
==
null
)
{
throw
new
JadxRuntimeException
(
"Switch block not found by offset: "
+
entry
.
getKey
());
}
blocksMap
.
put
(
c
,
entry
.
getValue
());
}
BlockNode
defCase
=
getBlockByOffset
(
insn
.
getDefaultCaseOffset
(),
block
.
getSuccessors
());
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/ReturnVisitor.java
View file @
b2f0f025
...
...
@@ -9,6 +9,7 @@ import jadx.core.dex.nodes.IContainer;
import
jadx.core.dex.nodes.IRegion
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.regions.SwitchRegion
;
import
jadx.core.dex.regions.loops.LoopRegion
;
import
jadx.core.dex.visitors.AbstractVisitor
;
import
jadx.core.utils.exceptions.JadxException
;
...
...
@@ -31,6 +32,13 @@ public class ReturnVisitor extends AbstractVisitor {
}
private
static
final
class
ReturnRemoverVisitor
extends
TracedRegionVisitor
{
@Override
public
boolean
enterRegion
(
MethodNode
mth
,
IRegion
region
)
{
super
.
enterRegion
(
mth
,
region
);
return
!(
region
instanceof
SwitchRegion
);
}
@Override
public
void
processBlockTraced
(
MethodNode
mth
,
IBlock
container
,
IRegion
currentRegion
)
{
if
(
container
.
getClass
()
!=
BlockNode
.
class
)
{
...
...
jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch3.java
0 → 100644
View file @
b2f0f025
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
.
countString
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestSwitch3
extends
IntegrationTest
{
public
static
class
TestCls
{
private
int
i
;
void
test
(
int
a
)
{
switch
(
a
)
{
case
1
:
i
=
1
;
return
;
case
2
:
case
3
:
i
=
2
;
return
;
default
:
i
=
4
;
break
;
}
i
=
5
;
}
public
void
check
()
{
test
(
1
);
assertThat
(
i
,
is
(
1
));
test
(
2
);
assertThat
(
i
,
is
(
2
));
test
(
3
);
assertThat
(
i
,
is
(
2
));
test
(
4
);
assertThat
(
i
,
is
(
5
));
test
(
10
);
assertThat
(
i
,
is
(
5
));
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
countString
(
0
,
"break;"
));
assertThat
(
code
,
countString
(
3
,
"return;"
));
}
}
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