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
e4dde3f4
Commit
e4dde3f4
authored
Jun 15, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix class cast exception
parent
9c90699c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
22 deletions
+69
-22
JadxDecompiler.java
jadx-core/src/main/java/jadx/api/JadxDecompiler.java
+1
-1
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+1
-1
FieldArg.java
...c/main/java/jadx/core/dex/instructions/args/FieldArg.java
+9
-9
SimplifyVisitor.java
...src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
+2
-3
InstructionRemover.java
...ore/src/main/java/jadx/core/utils/InstructionRemover.java
+15
-7
TestFieldIncrement.java
...st/java/jadx/tests/internal/arith/TestFieldIncrement.java
+1
-1
TestFieldIncrement2.java
...t/java/jadx/tests/internal/arith/TestFieldIncrement2.java
+40
-0
No files found.
jadx-core/src/main/java/jadx/api/JadxDecompiler.java
View file @
e4dde3f4
...
...
@@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory;
/**
* Jadx API usage example:
* <pre><code>
*
Decompiler jadx = new
Decompiler();
*
JadxDecompiler jadx = new Jadx
Decompiler();
* jadx.loadFile(new File("classes.dex"));
* jadx.setOutputDir(new File("out"));
* jadx.save();
...
...
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
e4dde3f4
...
...
@@ -101,7 +101,7 @@ public class InsnGen {
if
(
f
.
isStatic
())
{
staticField
(
code
,
f
.
getField
());
}
else
{
instanceField
(
code
,
f
.
getField
(),
f
.
get
Register
Arg
());
instanceField
(
code
,
f
.
getField
(),
f
.
get
Instance
Arg
());
}
}
else
{
throw
new
CodegenException
(
"Unknown arg type "
+
arg
);
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/FieldArg.java
View file @
e4dde3f4
...
...
@@ -6,12 +6,12 @@ import jadx.core.dex.info.FieldInfo;
public
final
class
FieldArg
extends
RegisterArg
{
private
final
FieldInfo
field
;
//
reg
Arg equal 'null' for static fields
private
final
RegisterArg
reg
Arg
;
//
inst
Arg equal 'null' for static fields
private
final
InsnArg
inst
Arg
;
public
FieldArg
(
FieldInfo
field
,
Register
Arg
reg
)
{
public
FieldArg
(
FieldInfo
field
,
Insn
Arg
reg
)
{
super
(-
1
);
this
.
reg
Arg
=
reg
;
this
.
inst
Arg
=
reg
;
this
.
field
=
field
;
}
...
...
@@ -19,12 +19,12 @@ public final class FieldArg extends RegisterArg {
return
field
;
}
public
RegisterArg
getRegister
Arg
()
{
return
reg
Arg
;
public
InsnArg
getInstance
Arg
()
{
return
inst
Arg
;
}
public
boolean
isStatic
()
{
return
reg
Arg
==
null
;
return
inst
Arg
==
null
;
}
@Override
...
...
@@ -54,7 +54,7 @@ public final class FieldArg extends RegisterArg {
if
(!
field
.
equals
(
fieldArg
.
field
))
{
return
false
;
}
if
(
regArg
!=
null
?
!
regArg
.
equals
(
fieldArg
.
regArg
)
:
fieldArg
.
reg
Arg
!=
null
)
{
if
(
instArg
!=
null
?
!
instArg
.
equals
(
fieldArg
.
instArg
)
:
fieldArg
.
inst
Arg
!=
null
)
{
return
false
;
}
return
true
;
...
...
@@ -64,7 +64,7 @@ public final class FieldArg extends RegisterArg {
public
int
hashCode
()
{
int
result
=
super
.
hashCode
();
result
=
31
*
result
+
field
.
hashCode
();
result
=
31
*
result
+
(
regArg
!=
null
?
reg
Arg
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
instArg
!=
null
?
inst
Arg
.
hashCode
()
:
0
);
return
result
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
View file @
e4dde3f4
...
...
@@ -14,7 +14,6 @@ import jadx.core.dex.instructions.args.FieldArg;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.LiteralArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.InsnNode
;
...
...
@@ -186,9 +185,9 @@ public class SimplifyVisitor extends AbstractVisitor {
return
null
;
}
try
{
Register
Arg
reg
=
null
;
Insn
Arg
reg
=
null
;
if
(
getType
==
InsnType
.
IGET
)
{
reg
=
((
RegisterArg
)
get
.
getArg
(
0
)
);
reg
=
get
.
getArg
(
0
);
}
FieldArg
fArg
=
new
FieldArg
(
field
,
reg
);
if
(
reg
!=
null
)
{
...
...
jadx-core/src/main/java/jadx/core/utils/InstructionRemover.java
View file @
e4dde3f4
...
...
@@ -3,6 +3,7 @@ package jadx.core.utils;
import
jadx.core.Consts
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.SSAVar
;
import
jadx.core.dex.nodes.BlockNode
;
...
...
@@ -65,17 +66,24 @@ public class InstructionRemover {
mth
.
removeSVar
(
r
.
getSVar
());
}
for
(
InsnArg
arg
:
insn
.
getArguments
())
{
if
(
arg
instanceof
RegisterArg
)
{
RegisterArg
reg
=
(
RegisterArg
)
arg
;
SSAVar
sVar
=
reg
.
getSVar
();
if
(
sVar
!=
null
)
{
sVar
.
removeUse
(
reg
);
}
}
unbindArgUsage
(
mth
,
arg
);
}
insn
.
add
(
AFlag
.
INCONSISTENT_CODE
);
}
public
static
void
unbindArgUsage
(
MethodNode
mth
,
InsnArg
arg
)
{
if
(
arg
instanceof
RegisterArg
)
{
RegisterArg
reg
=
(
RegisterArg
)
arg
;
SSAVar
sVar
=
reg
.
getSVar
();
if
(
sVar
!=
null
)
{
sVar
.
removeUse
(
reg
);
}
}
else
if
(
arg
instanceof
InsnWrapArg
)
{
InsnWrapArg
wrap
=
(
InsnWrapArg
)
arg
;
unbindInsn
(
mth
,
wrap
.
getWrapInsn
());
}
}
// Don't use 'insns.removeAll(toRemove)' because it will remove instructions by content
// and here can be several instructions with same content
private
void
removeAll
(
List
<
InsnNode
>
insns
,
List
<
InsnNode
>
toRemove
)
{
...
...
jadx-core/src/test/java/jadx/tests/internal/TestFieldIncrement.java
→
jadx-core/src/test/java/jadx/tests/internal/
arith/
TestFieldIncrement.java
View file @
e4dde3f4
package
jadx
.
tests
.
internal
;
package
jadx
.
tests
.
internal
.
arith
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
...
...
jadx-core/src/test/java/jadx/tests/internal/arith/TestFieldIncrement2.java
0 → 100644
View file @
e4dde3f4
package
jadx
.
tests
.
internal
.
arith
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestFieldIncrement2
extends
InternalJadxTest
{
class
A
{
int
f
=
5
;
}
public
static
class
TestCls
{
public
A
a
;
public
void
test1
(
int
n
)
{
this
.
a
.
f
=
this
.
a
.
f
+
n
;
}
public
void
test2
(
int
n
)
{
this
.
a
.
f
*=
n
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"this.a.f += n;"
));
assertThat
(
code
,
containsString
(
"a.f *= n;"
));
// TODO
// assertThat(code, containsString("this.a.f *= n;"));
}
}
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