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
f0a73b32
Commit
f0a73b32
authored
Aug 06, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix processing conditions in loop
parent
c97678a4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
2 deletions
+94
-2
BlockNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java
+5
-0
IfMakerHelper.java
...in/java/jadx/core/dex/visitors/regions/IfMakerHelper.java
+12
-1
RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+2
-1
BlockUtils.java
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
+21
-0
TestLoopInTry.java
...c/test/java/jadx/tests/internal/others/TestLoopInTry.java
+54
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java
View file @
f0a73b32
...
...
@@ -86,6 +86,11 @@ public class BlockNode extends AttrNode implements IBlock {
for
(
BlockNode
b
:
sucList
)
{
if
(
b
.
contains
(
AType
.
EXC_HANDLER
))
{
toRemove
.
add
(
b
);
}
else
if
(
b
.
contains
(
AFlag
.
SYNTHETIC
))
{
List
<
BlockNode
>
s
=
b
.
getSuccessors
();
if
(
s
.
size
()
==
1
&&
s
.
get
(
0
).
contains
(
AType
.
EXC_HANDLER
))
{
toRemove
.
add
(
b
);
}
}
}
if
(
block
.
contains
(
AFlag
.
LOOP_END
))
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/IfMakerHelper.java
View file @
f0a73b32
...
...
@@ -18,9 +18,13 @@ import java.util.Collection;
import
java.util.List
;
import
java.util.Set
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
static
jadx
.
core
.
utils
.
BlockUtils
.
isPathExists
;
public
class
IfMakerHelper
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
IfMakerHelper
.
class
);
private
IfMakerHelper
()
{
}
...
...
@@ -59,10 +63,12 @@ public class IfMakerHelper {
}
else
if
(
badElse
)
{
info
=
new
IfInfo
(
info
.
getCondition
(),
thenBlock
,
null
);
info
.
setOutBlock
(
null
);
LOG
.
debug
(
"Stop processing blocks after bad 'else' in 'if': {}, method: {}"
,
info
,
mth
);
}
else
{
info
=
IfInfo
.
invert
(
info
);
info
=
new
IfInfo
(
info
.
getCondition
(),
info
.
getThenBlock
(),
null
);
info
.
setOutBlock
(
null
);
LOG
.
debug
(
"Stop processing blocks after bad 'then' in 'if': {}, method: {}"
,
info
,
mth
);
}
}
else
{
List
<
BlockNode
>
thenSC
=
thenBlock
.
getCleanSuccessors
();
...
...
@@ -93,7 +99,12 @@ public class IfMakerHelper {
private
static
boolean
allPathsFromIf
(
BlockNode
block
,
IfInfo
info
)
{
List
<
BlockNode
>
preds
=
block
.
getPredecessors
();
Set
<
BlockNode
>
ifBlocks
=
info
.
getMergedBlocks
();
return
ifBlocks
.
containsAll
(
preds
);
for
(
BlockNode
pred
:
preds
)
{
if
(!
ifBlocks
.
contains
(
pred
)
&&
!
pred
.
contains
(
AFlag
.
LOOP_END
))
{
return
false
;
}
}
return
true
;
}
private
static
boolean
sameElements
(
Collection
<
BlockNode
>
c1
,
Collection
<
BlockNode
>
c2
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
View file @
f0a73b32
...
...
@@ -231,7 +231,8 @@ public class RegionMaker {
}
LoopRegion
loopRegion
=
new
LoopRegion
(
curRegion
,
block
,
block
==
loop
.
getEnd
());
boolean
found
;
if
(
block
==
loop
.
getStart
()
||
block
==
loop
.
getEnd
())
{
if
(
block
==
loop
.
getStart
()
||
block
==
loop
.
getEnd
()
||
BlockUtils
.
isEmptySimplePath
(
loop
.
getStart
(),
block
))
{
found
=
true
;
}
else
if
(
block
.
getPredecessors
().
contains
(
loop
.
getStart
()))
{
loopRegion
.
setPreCondition
(
loop
.
getStart
());
...
...
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
View file @
f0a73b32
...
...
@@ -301,4 +301,25 @@ public class BlockUtils {
}
return
list
.
isEmpty
()
?
Collections
.<
BlockNode
>
emptyList
()
:
list
;
}
/**
* Return true if on path from start to end no instructions and no branches.
*/
public
static
boolean
isEmptySimplePath
(
BlockNode
start
,
BlockNode
end
)
{
if
(
start
==
end
&&
start
.
getInstructions
().
isEmpty
())
{
return
true
;
}
if
(!
start
.
getInstructions
().
isEmpty
()
||
start
.
getCleanSuccessors
().
size
()
!=
1
)
{
return
false
;
}
BlockNode
block
=
getNextBlock
(
start
);
while
(
block
!=
null
&&
block
!=
end
&&
block
.
getCleanSuccessors
().
size
()
<
2
&&
block
.
getPredecessors
().
size
()
==
1
&&
block
.
getInstructions
().
isEmpty
())
{
block
=
getNextBlock
(
block
);
}
return
block
==
end
;
}
}
jadx-core/src/test/java/jadx/tests/internal/others/TestLoopInTry.java
0 → 100644
View file @
f0a73b32
package
jadx
.
tests
.
internal
.
others
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestLoopInTry
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
static
boolean
b
=
true
;
public
int
test
()
{
try
{
if
(
b
)
{
throw
new
Exception
();
}
while
(
f
())
{
s
();
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"exception"
);
return
1
;
}
return
0
;
}
private
static
void
s
()
{
}
private
static
boolean
f
()
{
return
false
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsOne
(
"try {"
));
assertThat
(
code
,
containsOne
(
"if (b) {"
));
assertThat
(
code
,
containsOne
(
"throw new Exception();"
));
assertThat
(
code
,
containsOne
(
"while (f()) {"
));
assertThat
(
code
,
containsOne
(
"s();"
));
assertThat
(
code
,
containsOne
(
"} catch (Exception e) {"
));
assertThat
(
code
,
containsOne
(
"return 1;"
));
assertThat
(
code
,
containsOne
(
"return 0;"
));
}
}
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