Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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
b9fffa14
Commit
b9fffa14
authored
Dec 06, 2018
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: allow override type with wider one only from debug info (#403)
parent
37071dba
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
10 deletions
+92
-10
ArgType.java
...rc/main/java/jadx/core/dex/instructions/args/ArgType.java
+5
-0
DebugInfoApplyVisitor.java
...dx/core/dex/visitors/debuginfo/DebugInfoApplyVisitor.java
+8
-7
TypeCompare.java
...ava/jadx/core/dex/visitors/typeinference/TypeCompare.java
+0
-3
TypeUpdate.java
...java/jadx/core/dex/visitors/typeinference/TypeUpdate.java
+29
-0
TestInlineInCatch.java
...va/jadx/tests/integration/trycatch/TestInlineInCatch.java
+3
-0
TestPrimitivesInIf.java
...java/jadx/tests/integration/types/TestPrimitivesInIf.java
+47
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java
View file @
b9fffa14
...
...
@@ -526,6 +526,11 @@ public abstract class ArgType {
return
isArray
()
||
(!
isTypeKnown
()
&&
contains
(
PrimitiveType
.
ARRAY
));
}
public
boolean
canBePrimitive
(
PrimitiveType
primitiveType
)
{
return
(
isPrimitive
()
&&
getPrimitiveType
()
==
primitiveType
)
||
(!
isTypeKnown
()
&&
contains
(
primitiveType
));
}
public
static
ArgType
convertFromPrimitiveType
(
PrimitiveType
primitiveType
)
{
switch
(
primitiveType
)
{
case
BOOLEAN:
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoApplyVisitor.java
View file @
b9fffa14
...
...
@@ -9,6 +9,7 @@ import java.util.Set;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
jadx.core.Consts
;
import
jadx.core.deobf.NameMapper
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
...
...
@@ -34,8 +35,8 @@ import jadx.core.utils.ErrorsCounter;
import
jadx.core.utils.exceptions.JadxException
;
@JadxVisitor
(
name
=
"Debug Info
Parser
"
,
desc
=
"
Parse debug information (variable names and types, instruction lin
es)"
,
name
=
"Debug Info
Apply
"
,
desc
=
"
Apply debug info to registers (type and nam
es)"
,
runAfter
=
{
SSATransform
.
class
,
TypeInferenceVisitor
.
class
,
...
...
@@ -101,7 +102,7 @@ public class DebugInfoApplyVisitor extends AbstractVisitor {
int
startAddr
=
localVar
.
getStartAddr
();
int
endAddr
=
localVar
.
getEndAddr
();
if
(
isInside
(
startOffset
,
startAddr
,
endAddr
)
||
isInside
(
endOffset
,
startAddr
,
endAddr
))
{
if
(
LOG
.
isDebugEnabled
())
{
if
(
Consts
.
DEBUG
&&
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Apply debug info by offset for: {} to {}"
,
ssaVar
,
localVar
);
}
applyDebugInfo
(
mth
,
ssaVar
,
localVar
.
getType
(),
localVar
.
getName
());
...
...
@@ -126,15 +127,15 @@ public class DebugInfoApplyVisitor extends AbstractVisitor {
}
public
static
void
applyDebugInfo
(
MethodNode
mth
,
SSAVar
ssaVar
,
ArgType
type
,
String
varName
)
{
TypeUpdateResult
result
=
mth
.
root
().
getTypeUpdate
().
apply
(
ssaVar
,
type
);
if
(
NameMapper
.
isValidIdentifier
(
varName
))
{
ssaVar
.
setName
(
varName
);
}
TypeUpdateResult
result
=
mth
.
root
().
getTypeUpdate
().
applyDebug
(
ssaVar
,
type
);
if
(
result
==
TypeUpdateResult
.
REJECT
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Reject debug info of type: {} and name: '{}' for {}, mth: {}"
,
type
,
varName
,
ssaVar
,
mth
);
}
}
else
{
if
(
NameMapper
.
isValidIdentifier
(
varName
))
{
ssaVar
.
setName
(
varName
);
}
detachDebugInfo
(
ssaVar
.
getAssign
());
ssaVar
.
getUseList
().
forEach
(
DebugInfoApplyVisitor:
:
detachDebugInfo
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeCompare.java
View file @
b9fffa14
...
...
@@ -193,9 +193,6 @@ public class TypeCompare {
return
comparator
;
}
/**
*
*/
private
final
class
ArgTypeComparator
implements
Comparator
<
ArgType
>
{
@Override
public
int
compare
(
ArgType
a
,
ArgType
b
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeUpdate.java
View file @
b9fffa14
...
...
@@ -33,11 +33,22 @@ public final class TypeUpdate {
private
final
TypeUpdateRegistry
listenerRegistry
;
private
final
TypeCompare
comparator
;
private
ThreadLocal
<
Boolean
>
applyDebug
=
new
ThreadLocal
<>();
public
TypeUpdate
(
RootNode
root
)
{
this
.
listenerRegistry
=
initListenerRegistry
();
this
.
comparator
=
new
TypeCompare
(
root
);
}
public
TypeUpdateResult
applyDebug
(
SSAVar
ssaVar
,
ArgType
candidateType
)
{
try
{
applyDebug
.
set
(
true
);
return
apply
(
ssaVar
,
candidateType
);
}
finally
{
applyDebug
.
set
(
false
);
}
}
public
TypeUpdateResult
apply
(
SSAVar
ssaVar
,
ArgType
candidateType
)
{
if
(
candidateType
==
null
)
{
return
REJECT
;
...
...
@@ -71,6 +82,16 @@ public final class TypeUpdate {
if
(
arg
.
isTypeImmutable
()
&&
currentType
!=
ArgType
.
UNKNOWN
)
{
return
REJECT
;
}
TypeCompareEnum
compareResult
=
comparator
.
compareTypes
(
candidateType
,
currentType
);
if
(
compareResult
==
TypeCompareEnum
.
CONFLICT
)
{
return
REJECT
;
}
if
(
compareResult
==
TypeCompareEnum
.
WIDER
||
compareResult
==
TypeCompareEnum
.
WIDER_BY_GENERIC
)
{
// allow wider types for apply from debug info
if
(
applyDebug
.
get
()
!=
Boolean
.
TRUE
)
{
return
REJECT
;
}
}
if
(
arg
instanceof
RegisterArg
)
{
RegisterArg
reg
=
(
RegisterArg
)
arg
;
return
updateTypeForSsaVar
(
updateInfo
,
reg
.
getSVar
(),
candidateType
);
...
...
@@ -316,6 +337,14 @@ public final class TypeUpdate {
if
(
candidateType
.
isArray
()
&&
updateArgType
.
canBeArray
())
{
return
SAME
;
}
if
(
candidateType
.
isPrimitive
())
{
if
(
updateArgType
.
canBePrimitive
(
candidateType
.
getPrimitiveType
()))
{
return
SAME
;
}
if
(
updateArgType
.
isTypeKnown
()
&&
candidateType
.
getRegCount
()
==
updateArgType
.
getRegCount
())
{
return
SAME
;
}
}
}
return
result
;
}
...
...
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestInlineInCatch.java
View file @
b9fffa14
...
...
@@ -19,6 +19,9 @@ public class TestInlineInCatch extends IntegrationTest {
File
output
=
null
;
try
{
output
=
File
.
createTempFile
(
"f"
,
"a"
,
dir
);
if
(!
output
.
exists
())
{
return
1
;
}
return
0
;
}
catch
(
Exception
e
)
{
if
(
output
!=
null
)
{
...
...
jadx-core/src/test/java/jadx/tests/integration/types/TestPrimitivesInIf.java
0 → 100644
View file @
b9fffa14
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
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
TestPrimitivesInIf
extends
IntegrationTest
{
public
static
class
TestCls
{
public
boolean
test
(
String
str
)
{
short
sh
=
Short
.
parseShort
(
str
);
int
i
=
Integer
.
parseInt
(
str
);
System
.
out
.
println
(
sh
+
" vs "
+
i
);
return
sh
==
i
;
}
public
void
check
()
{
assertTrue
(
test
(
"1"
));
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"short sh = Short.parseShort(str);"
));
assertThat
(
code
,
containsOne
(
"int i = Integer.parseInt(str);"
));
assertThat
(
code
,
containsOne
(
"return sh == i;"
));
}
@Test
public
void
test2
()
{
setOutputCFG
();
noDebugInfo
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"short parseShort = Short.parseShort(str);"
));
}
}
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