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
e1dfb4ee
Commit
e1dfb4ee
authored
Apr 29, 2019
by
Ahmed Ashour
Committed by
skylot
Apr 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: byte to number without cast (#596) (PR #638)
parent
031582dd
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
88 additions
and
8 deletions
+88
-8
InvokeNode.java
.../src/main/java/jadx/core/dex/instructions/InvokeNode.java
+1
-0
RegisterArg.java
...ain/java/jadx/core/dex/instructions/args/RegisterArg.java
+2
-0
ITypeBound.java
...java/jadx/core/dex/visitors/typeinference/ITypeBound.java
+6
-0
TypeBoundConst.java
.../jadx/core/dex/visitors/typeinference/TypeBoundConst.java
+13
-0
TypeInferenceVisitor.java
...core/dex/visitors/typeinference/TypeInferenceVisitor.java
+42
-2
TestBooleanToInt.java
...a/jadx/tests/integration/conditions/TestBooleanToInt.java
+4
-6
TestBooleanToInt.smali
jadx-core/src/test/smali/conditions/TestBooleanToInt.smali
+20
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/instructions/InvokeNode.java
View file @
e1dfb4ee
...
...
@@ -46,6 +46,7 @@ public class InvokeNode extends InsnNode implements CallMthInterface {
return
type
;
}
@Override
public
MethodInfo
getCallMth
()
{
return
mth
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/RegisterArg.java
View file @
e1dfb4ee
...
...
@@ -81,6 +81,7 @@ public class RegisterArg extends InsnArg implements Named {
}
}
@Override
public
String
getName
()
{
if
(
isThis
())
{
return
THIS_ARG_NAME
;
...
...
@@ -91,6 +92,7 @@ public class RegisterArg extends InsnArg implements Named {
return
sVar
.
getName
();
}
@Override
public
void
setName
(
String
name
)
{
if
(
sVar
!=
null
&&
name
!=
null
)
{
sVar
.
setName
(
name
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/ITypeBound.java
View file @
e1dfb4ee
package
jadx
.
core
.
dex
.
visitors
.
typeinference
;
import
org.jetbrains.annotations.Nullable
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.RegisterArg
;
public
interface
ITypeBound
{
BoundEnum
getBound
();
ArgType
getType
();
@Nullable
RegisterArg
getArg
();
}
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeBoundConst.java
View file @
e1dfb4ee
...
...
@@ -3,14 +3,22 @@ package jadx.core.dex.visitors.typeinference;
import
java.util.Objects
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.RegisterArg
;
public
final
class
TypeBoundConst
implements
ITypeBound
{
private
final
BoundEnum
bound
;
private
final
ArgType
type
;
private
final
RegisterArg
arg
;
public
TypeBoundConst
(
BoundEnum
bound
,
ArgType
type
)
{
this
(
bound
,
type
,
null
);
}
public
TypeBoundConst
(
BoundEnum
bound
,
ArgType
type
,
RegisterArg
arg
)
{
this
.
bound
=
bound
;
this
.
type
=
type
;
this
.
arg
=
arg
;
}
@Override
...
...
@@ -24,6 +32,11 @@ public final class TypeBoundConst implements ITypeBound {
}
@Override
public
RegisterArg
getArg
()
{
return
arg
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java
View file @
e1dfb4ee
...
...
@@ -21,6 +21,7 @@ import jadx.core.dex.instructions.IndexInsnNode;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.PhiInsn
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.CodeVar
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.LiteralArg
;
import
jadx.core.dex.instructions.args.PrimitiveType
;
...
...
@@ -81,7 +82,11 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
resolved
=
false
;
}
}
if
(!
resolved
)
{
if
(
resolved
)
{
for
(
SSAVar
var
:
new
ArrayList
<>(
mth
.
getSVars
()))
{
processIncompatiblePrimitives
(
mth
,
var
);
}
}
else
{
for
(
SSAVar
var
:
new
ArrayList
<>(
mth
.
getSVars
()))
{
tryInsertAdditionalInsn
(
mth
,
var
);
}
...
...
@@ -249,7 +254,7 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
if
(
insn
==
null
)
{
return
null
;
}
return
new
TypeBoundConst
(
BoundEnum
.
USE
,
regArg
.
getInitType
());
return
new
TypeBoundConst
(
BoundEnum
.
USE
,
regArg
.
getInitType
()
,
regArg
);
}
private
boolean
tryPossibleTypes
(
SSAVar
var
,
ArgType
type
)
{
...
...
@@ -375,4 +380,39 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
}
return
false
;
}
private
void
processIncompatiblePrimitives
(
MethodNode
mth
,
SSAVar
var
)
{
if
(
var
.
getAssign
().
getType
()
==
ArgType
.
BOOLEAN
)
{
for
(
ITypeBound
bound
:
var
.
getTypeInfo
().
getBounds
())
{
if
(
bound
.
getBound
()
==
BoundEnum
.
USE
&&
bound
.
getType
().
isPrimitive
()
&&
bound
.
getType
()
!=
ArgType
.
BOOLEAN
)
{
InsnNode
insn
=
bound
.
getArg
().
getParentInsn
();
if
(
insn
.
getType
()
==
InsnType
.
CAST
)
{
continue
;
};
IndexInsnNode
castNode
=
new
IndexInsnNode
(
InsnType
.
CAST
,
bound
.
getType
(),
1
);
castNode
.
addArg
(
bound
.
getArg
());
castNode
.
setResult
(
InsnArg
.
reg
(
bound
.
getArg
().
getRegNum
(),
bound
.
getType
()));
SSAVar
newVar
=
mth
.
makeNewSVar
(
castNode
.
getResult
().
getRegNum
(),
castNode
.
getResult
());
CodeVar
codeVar
=
new
CodeVar
();
codeVar
.
setType
(
bound
.
getType
());
newVar
.
setCodeVar
(
codeVar
);
newVar
.
getTypeInfo
().
setType
(
bound
.
getType
());
for
(
int
i
=
insn
.
getArgsCount
()
-
1
;
i
>=
0
;
i
--)
{
if
(
insn
.
getArg
(
i
)
==
bound
.
getArg
())
{
insn
.
setArg
(
i
,
castNode
.
getResult
().
duplicate
());
break
;
}
}
BlockNode
blockNode
=
BlockUtils
.
getBlockByInsn
(
mth
,
insn
);
List
<
InsnNode
>
insnList
=
blockNode
.
getInstructions
();
insnList
.
add
(
insnList
.
indexOf
(
insn
),
castNode
);
}
}
}
}
}
jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt
2
.java
→
jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt.java
View file @
e1dfb4ee
...
...
@@ -5,11 +5,10 @@ import static org.hamcrest.Matchers.containsString;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
public
class
TestBooleanToInt
2
extends
SmaliTest
{
public
class
TestBooleanToInt
extends
SmaliTest
{
/**
private boolean showConsent;
...
...
@@ -17,14 +16,13 @@ public class TestBooleanToInt2 extends SmaliTest {
public void write(int b) {
}
public void writeToParcel(TestBooleanToInt
2 testBooleanToInt2
) {
testBooleanToInt
2
.write(this.showConsent ? 1 : 0);
public void writeToParcel(TestBooleanToInt
testBooleanToInt
) {
testBooleanToInt.write(this.showConsent ? 1 : 0);
}
*/
@Test
@NotYetImplemented
public
void
test
()
{
ClassNode
cls
=
getClassNodeFromSmaliWithPath
(
"conditions"
,
"TestBooleanToInt
2
"
);
ClassNode
cls
=
getClassNodeFromSmaliWithPath
(
"conditions"
,
"TestBooleanToInt"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"write(this.showConsent ? 1 : 0);"
));
...
...
jadx-core/src/test/smali/conditions/TestBooleanToInt
2
.smali
→
jadx-core/src/test/smali/conditions/TestBooleanToInt.smali
View file @
e1dfb4ee
.class public LTestBooleanToInt
2
;
.class public LTestBooleanToInt;
.super Ljava/lang/Object;
.field private showConsent:Z
.method public writeToParcel(LTestBooleanToInt
2
;)V
.method public writeToParcel(LTestBooleanToInt;)V
.locals 0
iget-boolean p1, p0, LTestBooleanToInt
2
;->showConsent:Z
iget-boolean p1, p0, LTestBooleanToInt;->showConsent:Z
invoke-virtual {p0, p1}, LTestBooleanToInt
2
;->write(I)V
invoke-virtual {p0, p1}, LTestBooleanToInt;->write(I)V
return-void
.end method
...
...
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