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
0fa19fb0
Commit
0fa19fb0
authored
Feb 21, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove unreachable blocks (#451)
parent
f8acc31b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
BlockSplitter.java
...ava/jadx/core/dex/visitors/blocksmaker/BlockSplitter.java
+37
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockSplitter.java
View file @
0fa19fb0
package
jadx
.
core
.
dex
.
visitors
.
blocksmaker
;
import
java.util.ArrayDeque
;
import
java.util.Deque
;
import
java.util.EnumSet
;
import
java.util.HashMap
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -47,6 +50,7 @@ public class BlockSplitter extends AbstractVisitor {
removeJumpAttr
(
mth
);
removeInsns
(
mth
);
removeEmptyDetachedBlocks
(
mth
);
removeUnreachableBlocks
(
mth
);
initBlocksInTargetNodes
(
mth
);
}
...
...
@@ -324,4 +328,37 @@ public class BlockSplitter extends AbstractVisitor {
&&
block
.
getSuccessors
().
isEmpty
()
);
}
private
void
removeUnreachableBlocks
(
MethodNode
mth
)
{
Set
<
BlockNode
>
toRemove
=
new
LinkedHashSet
<>();
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
if
(
block
.
getPredecessors
().
isEmpty
()
&&
block
!=
mth
.
getEnterBlock
())
{
toRemove
.
add
(
block
);
collectSuccessors
(
block
,
toRemove
);
}
}
if
(!
toRemove
.
isEmpty
())
{
mth
.
getBasicBlocks
().
removeIf
(
toRemove:
:
contains
);
int
insnsCount
=
toRemove
.
stream
().
mapToInt
(
block
->
block
.
getInstructions
().
size
()).
sum
();
mth
.
addAttr
(
AType
.
COMMENTS
,
"JADX INFO: unreachable blocks removed: "
+
toRemove
.
size
()
+
", instructions: "
+
insnsCount
);
}
}
private
void
collectSuccessors
(
BlockNode
startBlock
,
Set
<
BlockNode
>
toRemove
)
{
Deque
<
BlockNode
>
stack
=
new
ArrayDeque
<>();
stack
.
add
(
startBlock
);
while
(!
stack
.
isEmpty
())
{
BlockNode
block
=
stack
.
pop
();
if
(!
toRemove
.
contains
(
block
))
{
for
(
BlockNode
successor
:
block
.
getSuccessors
())
{
if
(
toRemove
.
containsAll
(
successor
.
getPredecessors
()))
{
stack
.
push
(
successor
);
}
}
}
toRemove
.
add
(
block
);
}
}
}
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