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
343bddc6
Commit
343bddc6
authored
May 04, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix 'break' detection in loop
parent
632a742e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
8 deletions
+66
-8
Decompiler.java
jadx-core/src/main/java/jadx/api/Decompiler.java
+0
-1
ClassNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
+2
-1
RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+8
-6
BlockUtils.java
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
+12
-0
TestLoopDetection3.java
...st/java/jadx/tests/internal/loops/TestLoopDetection3.java
+44
-0
No files found.
jadx-core/src/main/java/jadx/api/Decompiler.java
View file @
343bddc6
...
...
@@ -181,7 +181,6 @@ public final class Decompiler {
}
void
processClass
(
ClassNode
cls
)
{
LOG
.
debug
(
"processing class {} ..."
,
cls
);
ProcessClass
.
process
(
cls
,
passes
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
View file @
343bddc6
...
...
@@ -104,7 +104,8 @@ public class ClassNode extends LineAttrNode implements ILoadable {
int
sfIdx
=
cls
.
getSourceFileIndex
();
if
(
sfIdx
!=
DexNode
.
NO_INDEX
)
{
String
fileName
=
dex
.
getString
(
sfIdx
);
if
(!
this
.
getFullName
().
contains
(
fileName
.
replace
(
".java"
,
""
)))
{
if
(!
this
.
getFullName
().
contains
(
fileName
.
replace
(
".java"
,
""
))
&&
!
fileName
.
equals
(
"SourceFile"
))
{
this
.
getAttributes
().
add
(
new
SourceFileAttr
(
fileName
));
LOG
.
debug
(
"Class '{}' compiled from '{}'"
,
this
,
fileName
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
View file @
343bddc6
...
...
@@ -238,13 +238,15 @@ public class RegionMaker {
exitBlocks
.
remove
(
condBlock
);
if
(
exitBlocks
.
size
()
>
0
)
{
// add 'break' instruction before path cross between main loop exit and subexit
BlockNode
loopExit
=
BlockUtils
.
selectOther
(
loopBody
,
condBlock
.
getCleanSuccessors
());
for
(
Edge
exitEdge
:
loop
.
getExitEdges
())
{
if
(!
exitBlocks
.
contains
(
exitEdge
.
getSource
()))
{
continue
;
BlockNode
loopExit
=
BlockUtils
.
selectOtherSafe
(
loopBody
,
condBlock
.
getCleanSuccessors
());
if
(
loopExit
!=
null
)
{
// add 'break' instruction before path cross between main loop exit and subexit
for
(
Edge
exitEdge
:
loop
.
getExitEdges
())
{
if
(!
exitBlocks
.
contains
(
exitEdge
.
getSource
()))
{
continue
;
}
insertBreak
(
stack
,
loopExit
,
exitEdge
);
}
insertBreak
(
stack
,
loopExit
,
exitEdge
);
}
}
...
...
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
View file @
343bddc6
...
...
@@ -45,6 +45,18 @@ public class BlockUtils {
}
}
public
static
BlockNode
selectOtherSafe
(
BlockNode
node
,
List
<
BlockNode
>
blocks
)
{
int
size
=
blocks
.
size
();
if
(
size
==
1
)
{
BlockNode
first
=
blocks
.
get
(
0
);
return
first
!=
node
?
first
:
null
;
}
else
if
(
size
==
2
)
{
BlockNode
first
=
blocks
.
get
(
0
);
return
first
!=
node
?
first
:
blocks
.
get
(
1
);
}
return
null
;
}
private
static
List
<
BlockNode
>
cleanBlockList
(
List
<
BlockNode
>
list
)
{
List
<
BlockNode
>
ret
=
new
ArrayList
<
BlockNode
>(
list
.
size
());
for
(
BlockNode
block
:
list
)
{
...
...
jadx-core/src/test/java/jadx/tests/internal/loops/TestLoopDetection3.java
0 → 100644
View file @
343bddc6
package
jadx
.
tests
.
internal
.
loops
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestLoopDetection3
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
void
test
(
TestCls
parent
,
int
pos
)
{
Object
item
;
while
(--
pos
>=
0
)
{
item
=
parent
.
get
(
pos
);
if
(
item
instanceof
String
)
{
func
((
String
)
item
);
return
;
}
}
}
private
Object
get
(
int
pos
)
{
return
null
;
}
private
void
func
(
String
item
)
{
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"while"
));
// TODO
// assertThat(code, containsString("while (--pos >= 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