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
e6e8f636
Commit
e6e8f636
authored
Apr 01, 2019
by
Ahmed Ashour
Committed by
skylot
Apr 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: variable usage with enhanced for loop (#535) (PR #547)
parent
3970fce5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
14 deletions
+65
-14
LoopRegionVisitor.java
...ava/jadx/core/dex/visitors/regions/LoopRegionVisitor.java
+3
-0
CollectUsageRegionVisitor.java
...visitors/regions/variables/CollectUsageRegionVisitor.java
+5
-14
TestVariablesUsageWithLoops.java
...ts/integration/variables/TestVariablesUsageWithLoops.java
+57
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/regions/LoopRegionVisitor.java
View file @
e6e8f636
...
...
@@ -125,6 +125,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
// all checks passed
initInsn
.
add
(
AFlag
.
DONT_GENERATE
);
incrInsn
.
add
(
AFlag
.
DONT_GENERATE
);
LoopType
arrForEach
=
checkArrayForEach
(
mth
,
loopRegion
,
initInsn
,
incrInsn
,
condition
);
if
(
arrForEach
!=
null
)
{
loopRegion
.
setType
(
arrForEach
);
...
...
@@ -281,6 +282,8 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
}
assignInsn
.
add
(
AFlag
.
DONT_GENERATE
);
assignInsn
.
getResult
().
add
(
AFlag
.
DONT_GENERATE
);
for
(
InsnNode
insnNode
:
toSkip
)
{
insnNode
.
add
(
AFlag
.
DONT_GENERATE
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/variables/CollectUsageRegionVisitor.java
View file @
e6e8f636
...
...
@@ -18,13 +18,8 @@ import jadx.core.dex.regions.loops.LoopType;
import
jadx.core.dex.visitors.regions.TracedRegionVisitor
;
class
CollectUsageRegionVisitor
extends
TracedRegionVisitor
{
private
final
List
<
RegisterArg
>
args
;
private
final
Map
<
SSAVar
,
VarUsage
>
usageMap
;
public
CollectUsageRegionVisitor
()
{
this
.
usageMap
=
new
LinkedHashMap
<>();
this
.
args
=
new
ArrayList
<>();
}
private
final
List
<
RegisterArg
>
args
=
new
ArrayList
<>();
private
final
Map
<
SSAVar
,
VarUsage
>
usageMap
=
new
LinkedHashMap
<>();
public
Map
<
SSAVar
,
VarUsage
>
getUsageMap
()
{
return
usageMap
;
...
...
@@ -37,9 +32,6 @@ class CollectUsageRegionVisitor extends TracedRegionVisitor {
int
len
=
block
.
getInstructions
().
size
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
InsnNode
insn
=
block
.
getInstructions
().
get
(
i
);
if
(
insn
.
contains
(
AFlag
.
DONT_GENERATE
))
{
continue
;
}
processInsn
(
insn
,
usePlace
);
}
}
...
...
@@ -73,11 +65,10 @@ class CollectUsageRegionVisitor extends TracedRegionVisitor {
args
.
clear
();
insn
.
getRegisterArgs
(
args
);
for
(
RegisterArg
arg
:
args
)
{
if
(
arg
.
contains
(
AFlag
.
DONT_GENERATE
))
{
continue
;
if
(!
arg
.
contains
(
AFlag
.
DONT_GENERATE
))
{
VarUsage
usage
=
getUsage
(
arg
.
getSVar
());
usage
.
getUses
().
add
(
usePlace
);
}
VarUsage
usage
=
getUsage
(
arg
.
getSVar
());
usage
.
getUses
().
add
(
usePlace
);
}
}
...
...
jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables
7
.java
→
jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables
UsageWithLoops
.java
View file @
e6e8f636
...
...
@@ -8,13 +8,12 @@ import java.util.List;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
public
class
TestVariables
7
extends
IntegrationTest
{
public
class
TestVariables
UsageWithLoops
extends
IntegrationTest
{
public
static
class
Test
Cls
{
public
static
class
Test
EnhancedFor
{
public
void
test
()
{
List
list
;
...
...
@@ -28,9 +27,29 @@ public class TestVariables7 extends IntegrationTest {
}
@Test
@NotYetImplemented
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
public
void
testEnhancedFor
()
{
ClassNode
cls
=
getClassNode
(
TestEnhancedFor
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
" list = new ArrayList"
));
}
public
static
class
TestForLoop
{
public
void
test
()
{
List
list
;
synchronized
(
this
)
{
list
=
new
ArrayList
();
}
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
System
.
out
.
println
(
i
);
}
}
}
@Test
public
void
testForLoop
()
{
ClassNode
cls
=
getClassNode
(
TestForLoop
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
" list = new ArrayList"
));
...
...
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