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
8de6190a
Commit
8de6190a
authored
Dec 17, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix type inference for arguments in Phi node (fix #33)
parent
d6e2c692
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
9 deletions
+63
-9
PostTypeInference.java
...dx/core/dex/visitors/typeinference/PostTypeInference.java
+25
-9
TestTypeResolver3.java
.../java/jadx/tests/integration/types/TestTypeResolver3.java
+38
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/PostTypeInference.java
View file @
8de6190a
...
...
@@ -8,7 +8,6 @@ import jadx.core.dex.instructions.args.ArgType;
import
jadx.core.dex.instructions.args.InsnArg
;
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.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
...
...
@@ -100,18 +99,26 @@ public class PostTypeInference {
case
PHI:
{
PhiInsn
phi
=
(
PhiInsn
)
insn
;
RegisterArg
result
=
phi
.
getResult
();
SSAVar
resultSVar
=
result
.
getSVar
();
if
(
resultSVar
!=
null
&&
!
result
.
getType
().
isTypeKnown
())
{
ArgType
type
=
phi
.
getResult
().
getType
();
if
(!
type
.
isTypeKnown
())
{
for
(
InsnArg
arg
:
phi
.
getArguments
())
{
ArgType
argType
=
arg
.
getType
();
if
(
argType
.
isTypeKnown
())
{
resultSVar
.
setType
(
argType
);
return
true
;
if
(
arg
.
getType
().
isTypeKnown
())
{
type
=
arg
.
getType
();
break
;
}
}
}
return
false
;
boolean
changed
=
false
;
if
(
updateType
(
phi
.
getResult
(),
type
))
{
changed
=
true
;
}
for
(
int
i
=
0
;
i
<
phi
.
getArgsCount
();
i
++)
{
RegisterArg
arg
=
phi
.
getArg
(
i
);
if
(
updateType
(
arg
,
type
))
{
changed
=
true
;
}
}
return
changed
;
}
default
:
...
...
@@ -120,6 +127,15 @@ public class PostTypeInference {
return
false
;
}
private
static
boolean
updateType
(
RegisterArg
arg
,
ArgType
type
)
{
ArgType
prevType
=
arg
.
getType
();
if
(
prevType
==
null
||
!
prevType
.
equals
(
type
))
{
arg
.
setType
(
type
);
return
true
;
}
return
false
;
}
private
static
boolean
fixArrayTypes
(
InsnArg
array
,
InsnArg
elem
)
{
boolean
change
=
false
;
if
(!
elem
.
getType
().
isTypeKnown
()
&&
elem
.
merge
(
array
.
getType
().
getArrayElement
()))
{
...
...
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver3.java
0 → 100644
View file @
8de6190a
package
jadx
.
tests
.
integration
.
types
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestTypeResolver3
extends
IntegrationTest
{
public
static
class
TestCls
{
public
int
test
(
String
s1
,
String
s2
)
{
int
cmp
=
s2
.
compareTo
(
s1
);
if
(
cmp
!=
0
)
{
return
cmp
;
}
return
s1
.
length
()
==
s2
.
length
()
?
0
:
s1
.
length
()
<
s2
.
length
()
?
-
1
:
1
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
// TODO inline into return
assertThat
(
code
,
containsOne
(
"s1.length() == s2.length() ? 0 : s1.length() < s2.length() ? -1 : 1;"
));
}
@Test
public
void
test2
()
{
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