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
3782aa7d
Commit
3782aa7d
authored
Apr 07, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix wildcard type in iterable loop
parent
d5740c1b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
7 deletions
+65
-7
LoopRegionVisitor.java
...ava/jadx/core/dex/visitors/regions/LoopRegionVisitor.java
+18
-7
TestGenerics6.java
...t/java/jadx/tests/integration/generics/TestGenerics6.java
+47
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/regions/LoopRegionVisitor.java
View file @
3782aa7d
...
...
@@ -16,7 +16,6 @@ import jadx.core.dex.instructions.args.LiteralArg;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.SSAVar
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.DexNode
;
import
jadx.core.dex.nodes.IBlock
;
import
jadx.core.dex.nodes.IRegion
;
import
jadx.core.dex.nodes.InsnNode
;
...
...
@@ -232,14 +231,23 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
}
List
<
InsnNode
>
toSkip
=
new
LinkedList
<
InsnNode
>();
RegisterArg
iterVar
=
nextCall
.
getResult
();
if
(
iterVar
==
null
)
{
return
false
;
}
if
(
nextCall
.
contains
(
AFlag
.
WRAPPED
))
{
InsnArg
wrapArg
=
BlockUtils
.
searchWrappedInsnParent
(
mth
,
nextCall
);
if
(
wrapArg
!=
null
&&
wrapArg
.
getParentInsn
()
!=
null
)
{
InsnNode
parentInsn
=
wrapArg
.
getParentInsn
();
if
(
parentInsn
.
getType
()
!=
InsnType
.
CHECK_CAST
)
{
if
(!
fixIterableType
(
mth
,
iterableArg
,
iterVar
))
{
return
false
;
}
parentInsn
.
replaceArg
(
wrapArg
,
iterVar
);
}
else
{
iterVar
=
parentInsn
.
getResult
();
if
(
iterVar
==
null
||
!
fixIterableType
(
mth
,
iterableArg
,
iterVar
))
{
return
false
;
}
InsnArg
castArg
=
BlockUtils
.
searchWrappedInsnParent
(
mth
,
parentInsn
);
if
(
castArg
!=
null
&&
castArg
.
getParentInsn
()
!=
null
)
{
castArg
.
getParentInsn
().
replaceArg
(
castArg
,
iterVar
);
...
...
@@ -255,9 +263,6 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
}
else
{
toSkip
.
add
(
nextCall
);
}
if
(
iterVar
==
null
||
!
fixIterableType
(
mth
.
dex
(),
iterableArg
,
iterVar
))
{
return
false
;
}
assignInsn
.
add
(
AFlag
.
SKIP
);
for
(
InsnNode
insnNode
:
toSkip
)
{
...
...
@@ -267,7 +272,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
return
true
;
}
private
static
boolean
fixIterableType
(
DexNode
dex
,
InsnArg
iterableArg
,
RegisterArg
iterVar
)
{
private
static
boolean
fixIterableType
(
MethodNode
mth
,
InsnArg
iterableArg
,
RegisterArg
iterVar
)
{
ArgType
iterableType
=
iterableArg
.
getType
();
ArgType
varType
=
iterVar
.
getType
();
if
(
iterableType
.
isGeneric
())
{
...
...
@@ -283,10 +288,16 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
iterVar
.
setType
(
gType
);
return
true
;
}
if
(
ArgType
.
isInstanceOf
(
dex
,
gType
,
varType
))
{
if
(
ArgType
.
isInstanceOf
(
mth
.
dex
(),
gType
,
varType
))
{
return
true
;
}
ArgType
wildcardType
=
gType
.
getWildcardType
();
if
(
wildcardType
!=
null
&&
gType
.
getWildcardBounds
()
==
1
&&
ArgType
.
isInstanceOf
(
mth
.
dex
(),
wildcardType
,
varType
))
{
return
true
;
}
LOG
.
warn
(
"Generic type differs:
{} and {}"
,
gType
,
varType
);
LOG
.
warn
(
"Generic type differs:
'{}' and '{}' in {}"
,
gType
,
varType
,
mth
);
return
false
;
}
if
(!
iterableArg
.
isRegister
())
{
...
...
jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics6.java
0 → 100644
View file @
3782aa7d
package
jadx
.
tests
.
integration
.
generics
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
java.util.Collection
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestGenerics6
extends
IntegrationTest
{
public
static
class
TestCls
{
public
void
test1
(
Collection
<?
extends
A
>
as
)
{
for
(
A
a
:
as
)
{
a
.
f
();
}
}
public
void
test2
(
Collection
<?
extends
A
>
is
)
{
for
(
I
i
:
is
)
{
i
.
f
();
}
}
private
interface
I
{
void
f
();
}
private
class
A
implements
I
{
public
void
f
()
{
}
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"for (A a : as) {"
));
// TODO: fix iterable arg type (unexpected cast to A in bytecode)
// assertThat(code, containsOne("for (I i : is) {"));
}
}
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