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
7bd17522
Commit
7bd17522
authored
Feb 26, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: add correct type propagation for check-cast and move instructions (#401)
parent
ab7b6fc2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
11 deletions
+73
-11
TypeUpdate.java
...java/jadx/core/dex/visitors/typeinference/TypeUpdate.java
+24
-11
TestTypeResolver7.java
.../java/jadx/tests/integration/types/TestTypeResolver7.java
+49
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeUpdate.java
View file @
7bd17522
...
...
@@ -252,6 +252,7 @@ public final class TypeUpdate {
registry
.
put
(
InsnType
.
ARITH
,
this
::
suggestAllSameListener
);
registry
.
put
(
InsnType
.
NEG
,
this
::
suggestAllSameListener
);
registry
.
put
(
InsnType
.
NOT
,
this
::
suggestAllSameListener
);
registry
.
put
(
InsnType
.
CHECK_CAST
,
this
::
checkCastListener
);
return
registry
;
}
...
...
@@ -263,20 +264,23 @@ public final class TypeUpdate {
private
TypeUpdateResult
moveListener
(
TypeUpdateInfo
updateInfo
,
InsnNode
insn
,
InsnArg
arg
,
ArgType
candidateType
)
{
boolean
assignChanged
=
isAssign
(
insn
,
arg
);
InsnArg
changeArg
=
assignChanged
?
insn
.
getArg
(
0
)
:
insn
.
getResult
();
TypeUpdateResult
result
=
updateTypeChecked
(
updateInfo
,
changeArg
,
candidateType
)
;
if
(
result
==
REJECT
&&
changeArg
.
getType
().
isTypeKnown
())
{
boolean
allowReject
;
if
(
changeArg
.
getType
().
isTypeKnown
())
{
// allow result to be wider
if
(
assignChanged
)
{
TypeCompareEnum
compareTypes
=
comparator
.
compareTypes
(
candidateType
,
changeArg
.
getType
());
if
(
compareTypes
.
isWider
()
&&
inBounds
(
changeArg
,
candidateType
))
{
return
CHANGED
;
}
TypeCompareEnum
compareTypes
=
comparator
.
compareTypes
(
candidateType
,
changeArg
.
getType
());
boolean
correctType
=
assignChanged
?
compareTypes
.
isWider
()
:
compareTypes
.
isNarrow
();
if
(
correctType
&&
inBounds
(
changeArg
,
candidateType
))
{
allowReject
=
true
;
}
else
{
TypeCompareEnum
compareTypes
=
comparator
.
compareTypes
(
changeArg
.
getType
(),
candidateType
);
if
(
compareTypes
.
isWider
()
&&
inBounds
(
changeArg
,
candidateType
))
{
return
CHANGED
;
}
return
REJECT
;
}
}
else
{
allowReject
=
false
;
}
TypeUpdateResult
result
=
updateTypeChecked
(
updateInfo
,
changeArg
,
candidateType
);
if
(
result
==
REJECT
&&
allowReject
)
{
return
CHANGED
;
}
return
result
;
}
...
...
@@ -324,6 +328,15 @@ public final class TypeUpdate {
return
allSame
?
SAME
:
CHANGED
;
}
private
TypeUpdateResult
checkCastListener
(
TypeUpdateInfo
updateInfo
,
InsnNode
insn
,
InsnArg
arg
,
ArgType
candidateType
)
{
if
(!
isAssign
(
insn
,
arg
))
{
return
SAME
;
}
InsnArg
insnArg
=
insn
.
getArg
(
0
);
TypeUpdateResult
result
=
updateTypeChecked
(
updateInfo
,
insnArg
,
candidateType
);
return
result
==
REJECT
?
SAME
:
result
;
}
private
TypeUpdateResult
arrayGetListener
(
TypeUpdateInfo
updateInfo
,
InsnNode
insn
,
InsnArg
arg
,
ArgType
candidateType
)
{
if
(
isAssign
(
insn
,
arg
))
{
return
updateTypeChecked
(
updateInfo
,
insn
.
getArg
(
0
),
ArgType
.
array
(
candidateType
));
...
...
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver7.java
0 → 100644
View file @
7bd17522
package
jadx
.
tests
.
integration
.
types
;
import
org.junit.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestTypeResolver7
extends
IntegrationTest
{
public
static
class
TestCls
{
public
void
test
(
boolean
a
,
boolean
b
)
{
Object
obj
=
null
;
if
(
a
)
{
use
(
b
?
(
Exception
)
getObj
()
:
(
Exception
)
obj
);
}
else
{
Runnable
r
=
(
Runnable
)
obj
;
if
(
b
)
{
r
=
(
Runnable
)
getObj
();
}
use
(
r
);
}
}
private
Object
getObj
()
{
return
null
;
}
private
void
use
(
Exception
e
)
{}
private
void
use
(
Runnable
r
)
{}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"use(b ? (Exception) getObj() : null);"
));
}
@Test
public
void
testNoDebug
()
{
noDebugInfo
();
getClassNode
(
TestCls
.
class
);
}
}
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