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
eec524ad
Commit
eec524ad
authored
Oct 10, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: make methods arguments types immutable
parent
d94087b9
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
152 additions
and
117 deletions
+152
-117
ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+14
-7
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+5
-4
MethodGen.java
jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
+0
-8
BlockRegState.java
...src/main/java/jadx/core/dex/attributes/BlockRegState.java
+7
-6
ImmutableTypedVar.java
...va/jadx/core/dex/instructions/args/ImmutableTypedVar.java
+9
-5
InsnArg.java
...rc/main/java/jadx/core/dex/instructions/args/InsnArg.java
+6
-0
RegisterArg.java
...ain/java/jadx/core/dex/instructions/args/RegisterArg.java
+4
-3
Typed.java
.../src/main/java/jadx/core/dex/instructions/args/Typed.java
+42
-20
TypedVar.java
...c/main/java/jadx/core/dex/instructions/args/TypedVar.java
+16
-13
ClassNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
+4
-0
InsnNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java
+3
-2
MethodNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
+2
-16
RootNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
+1
-2
DebugInfoParser.java
...main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java
+3
-2
LocalVar.java
...re/src/main/java/jadx/core/dex/nodes/parser/LocalVar.java
+1
-1
ClassModifier.java
...e/src/main/java/jadx/core/dex/visitors/ClassModifier.java
+3
-5
CodeShrinker.java
...re/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
+8
-7
DotGraphVisitor.java
...src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java
+0
-1
EnumVisitor.java
...ore/src/main/java/jadx/core/dex/visitors/EnumVisitor.java
+1
-2
ModVisitor.java
...core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
+8
-4
TypeResolver.java
...ava/jadx/core/dex/visitors/typeresolver/TypeResolver.java
+2
-2
JadxClasspathTest.java
...rc/test/java/jadx/tests/functional/JadxClasspathTest.java
+3
-0
TestDuplicateCast.java
.../src/test/java/jadx/tests/internal/TestDuplicateCast.java
+4
-6
TestRedundantBrackets.java
.../test/java/jadx/tests/internal/TestRedundantBrackets.java
+5
-0
TestTypeResolver.java
...-samples/src/main/java/jadx/samples/TestTypeResolver.java
+1
-1
No files found.
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
View file @
eec524ad
...
@@ -340,9 +340,6 @@ public class ClassGen {
...
@@ -340,9 +340,6 @@ public class ClassGen {
}
}
private
String
useClassInternal
(
ClassInfo
useCls
,
ClassInfo
classInfo
)
{
private
String
useClassInternal
(
ClassInfo
useCls
,
ClassInfo
classInfo
)
{
if
(
parentGen
!=
null
)
{
return
parentGen
.
useClassInternal
(
useCls
,
classInfo
);
}
String
clsStr
=
classInfo
.
getFullName
();
String
clsStr
=
classInfo
.
getFullName
();
if
(
fallback
)
{
if
(
fallback
)
{
return
clsStr
;
return
clsStr
;
...
@@ -372,11 +369,19 @@ public class ClassGen {
...
@@ -372,11 +369,19 @@ public class ClassGen {
}
}
}
}
}
}
imports
.
add
(
classInfo
);
addImport
(
classInfo
);
return
shortName
;
return
shortName
;
}
}
}
}
private
void
addImport
(
ClassInfo
classInfo
)
{
if
(
parentGen
!=
null
)
{
parentGen
.
addImport
(
classInfo
);
}
else
{
imports
.
add
(
classInfo
);
}
}
private
static
boolean
isClassInnerFor
(
ClassInfo
inner
,
ClassInfo
parent
)
{
private
static
boolean
isClassInnerFor
(
ClassInfo
inner
,
ClassInfo
parent
)
{
if
(
inner
.
isInner
())
{
if
(
inner
.
isInner
())
{
ClassInfo
p
=
inner
.
getParentClass
();
ClassInfo
p
=
inner
.
getParentClass
();
...
@@ -393,11 +398,13 @@ public class ClassGen {
...
@@ -393,11 +398,13 @@ public class ClassGen {
return
true
;
return
true
;
}
}
ClassNode
classNode
=
dex
.
resolveClass
(
useCls
);
ClassNode
classNode
=
dex
.
resolveClass
(
useCls
);
if
(
classNode
!=
null
)
{
for
(
ClassNode
inner
:
classNode
.
getInnerClasses
())
{
for
(
ClassNode
inner
:
classNode
.
getInnerClasses
())
{
if
(
inner
.
getShortName
().
equals
(
shortName
))
{
if
(
inner
.
getShortName
().
equals
(
shortName
))
{
return
true
;
return
true
;
}
}
}
}
}
return
searchCollision
(
dex
,
useCls
.
getParentClass
(),
shortName
);
return
searchCollision
(
dex
,
useCls
.
getParentClass
(),
shortName
);
}
}
...
...
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
eec524ad
...
@@ -101,7 +101,7 @@ public class InsnGen {
...
@@ -101,7 +101,7 @@ public class InsnGen {
return
sfield
(
f
.
getField
());
return
sfield
(
f
.
getField
());
}
else
{
}
else
{
RegisterArg
regArg
=
new
RegisterArg
(
f
.
getRegNum
());
RegisterArg
regArg
=
new
RegisterArg
(
f
.
getRegNum
());
regArg
.
setTypedVar
(
f
.
getTypedVar
()
);
regArg
.
replaceTypedVar
(
f
);
return
ifield
(
f
.
getField
(),
regArg
);
return
ifield
(
f
.
getField
(),
regArg
);
}
}
}
else
{
}
else
{
...
@@ -281,13 +281,14 @@ public class InsnGen {
...
@@ -281,13 +281,14 @@ public class InsnGen {
case
INSTANCE_OF:
{
case
INSTANCE_OF:
{
boolean
wrap
=
state
.
contains
(
IGState
.
BODY_ONLY
);
boolean
wrap
=
state
.
contains
(
IGState
.
BODY_ONLY
);
if
(
wrap
)
if
(
wrap
)
{
code
.
add
(
"("
);
code
.
add
(
'('
);
}
code
.
add
(
arg
(
insn
,
0
));
code
.
add
(
arg
(
insn
,
0
));
code
.
add
(
" instanceof "
);
code
.
add
(
" instanceof "
);
code
.
add
(
useType
((
ArgType
)
((
IndexInsnNode
)
insn
).
getIndex
()));
code
.
add
(
useType
((
ArgType
)
((
IndexInsnNode
)
insn
).
getIndex
()));
if
(
wrap
)
{
if
(
wrap
)
{
code
.
add
(
")"
);
code
.
add
(
')'
);
}
}
break
;
break
;
}
}
...
...
jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
View file @
eec524ad
...
@@ -218,13 +218,6 @@ public class MethodGen {
...
@@ -218,13 +218,6 @@ public class MethodGen {
return
r
;
return
r
;
}
}
private
void
makeInitCode
(
CodeWriter
code
)
throws
CodegenException
{
InsnGen
igen
=
new
InsnGen
(
this
,
mth
,
fallback
);
// generate super call
if
(
mth
.
getSuperCall
()
!=
null
)
igen
.
makeInsn
(
mth
.
getSuperCall
(),
code
);
}
public
CodeWriter
makeInstructions
(
int
mthIndent
)
throws
CodegenException
{
public
CodeWriter
makeInstructions
(
int
mthIndent
)
throws
CodegenException
{
CodeWriter
code
=
new
CodeWriter
(
mthIndent
+
1
);
CodeWriter
code
=
new
CodeWriter
(
mthIndent
+
1
);
...
@@ -252,7 +245,6 @@ public class MethodGen {
...
@@ -252,7 +245,6 @@ public class MethodGen {
LOG
.
debug
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
" Inconsistent code"
));
LOG
.
debug
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
" Inconsistent code"
));
// makeMethodDump(code, mth);
// makeMethodDump(code, mth);
}
}
makeInitCode
(
code
);
code
.
add
(
insns
);
code
.
add
(
insns
);
}
else
{
}
else
{
makeFallbackMethod
(
code
,
mth
);
makeFallbackMethod
(
code
,
mth
);
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/BlockRegState.java
View file @
eec524ad
...
@@ -21,18 +21,19 @@ public final class BlockRegState {
...
@@ -21,18 +21,19 @@ public final class BlockRegState {
}
}
public
void
assignReg
(
RegisterArg
arg
)
{
public
void
assignReg
(
RegisterArg
arg
)
{
int
rn
=
arg
.
getRegNum
();
regs
[
arg
.
getRegNum
()]
=
arg
;
regs
[
rn
]
=
new
RegisterArg
(
rn
,
arg
.
getType
());
arg
.
getTypedVar
().
getUseList
().
add
(
arg
);
use
(
arg
);
}
}
public
void
use
(
RegisterArg
arg
)
{
public
void
use
(
RegisterArg
arg
)
{
TypedVar
regType
=
regs
[
arg
.
getRegNum
()].
getTypedVar
();
RegisterArg
reg
=
regs
[
arg
.
getRegNum
()];
TypedVar
regType
=
reg
.
getTypedVar
();
if
(
regType
==
null
)
{
if
(
regType
==
null
)
{
regType
=
new
TypedVar
(
arg
.
getType
());
regType
=
new
TypedVar
(
arg
.
getType
());
reg
s
[
arg
.
getRegNum
()].
s
etTypedVar
(
regType
);
reg
.
forceS
etTypedVar
(
regType
);
}
}
regType
.
use
(
arg
);
arg
.
replaceTypedVar
(
reg
);
reg
.
getTypedVar
().
getUseList
().
add
(
arg
);
}
}
public
RegisterArg
getRegister
(
int
r
)
{
public
RegisterArg
getRegister
(
int
r
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/ImmutableTypedVar.java
View file @
eec524ad
...
@@ -2,13 +2,17 @@ package jadx.core.dex.instructions.args;
...
@@ -2,13 +2,17 @@ package jadx.core.dex.instructions.args;
public
class
ImmutableTypedVar
extends
TypedVar
{
public
class
ImmutableTypedVar
extends
TypedVar
{
public
ImmutableTypedVar
(
ArgType
initT
ype
)
{
public
ImmutableTypedVar
(
ArgType
t
ype
)
{
super
(
initT
ype
);
super
(
t
ype
);
}
}
@Override
@Override
public
boolean
forceSetType
(
ArgType
newType
)
{
public
boolean
isImmutable
()
{
return
false
;
return
true
;
}
@Override
public
void
forceSetType
(
ArgType
newType
)
{
}
}
@Override
@Override
...
@@ -17,7 +21,7 @@ public class ImmutableTypedVar extends TypedVar {
...
@@ -17,7 +21,7 @@ public class ImmutableTypedVar extends TypedVar {
}
}
@Override
@Override
public
boolean
merge
(
ArgType
m
type
)
{
public
boolean
merge
(
ArgType
type
)
{
return
false
;
return
false
;
}
}
}
}
jadx-core/src/main/java/jadx/core/dex/instructions/args/InsnArg.java
View file @
eec524ad
...
@@ -21,6 +21,12 @@ public abstract class InsnArg extends Typed {
...
@@ -21,6 +21,12 @@ public abstract class InsnArg extends Typed {
return
reg
(
InsnUtils
.
getArg
(
insn
,
argNum
),
type
);
return
reg
(
InsnUtils
.
getArg
(
insn
,
argNum
),
type
);
}
}
public
static
RegisterArg
immutableReg
(
int
regNum
,
ArgType
type
)
{
RegisterArg
r
=
new
RegisterArg
(
regNum
);
r
.
forceSetTypedVar
(
new
ImmutableTypedVar
(
type
));
return
r
;
}
public
static
LiteralArg
lit
(
long
literal
,
ArgType
type
)
{
public
static
LiteralArg
lit
(
long
literal
,
ArgType
type
)
{
return
new
LiteralArg
(
literal
,
type
);
return
new
LiteralArg
(
literal
,
type
);
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/RegisterArg.java
View file @
eec524ad
...
@@ -88,13 +88,14 @@ public class RegisterArg extends InsnArg {
...
@@ -88,13 +88,14 @@ public class RegisterArg extends InsnArg {
public
boolean
isThis
()
{
public
boolean
isThis
()
{
if
(
isRegister
())
{
if
(
isRegister
())
{
String
name
=
getTypedVar
().
getName
();
String
name
=
getTypedVar
().
getName
();
if
(
name
!=
null
&&
name
.
equals
(
"this"
))
if
(
name
!=
null
&&
name
.
equals
(
"this"
))
{
return
true
;
return
true
;
}
// maybe it was moved from 'this' register
// maybe it was moved from 'this' register
InsnNode
ai
=
getAssignInsn
();
InsnNode
ai
=
getAssignInsn
();
if
(
ai
!=
null
&&
ai
.
getType
()
==
InsnType
.
MOVE
)
{
if
(
ai
!=
null
&&
ai
.
getType
()
==
InsnType
.
MOVE
)
{
if
(
ai
.
getArg
(
0
).
isThis
())
{
InsnArg
arg
=
ai
.
getArg
(
0
);
if
(
arg
!=
this
&&
arg
.
isThis
())
{
// actually we need to remove this instruction but we can't
// actually we need to remove this instruction but we can't
// because of iterating on instructions list
// because of iterating on instructions list
// so unbind insn and rely on code shrinker
// so unbind insn and rely on code shrinker
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/Typed.java
View file @
eec524ad
package
jadx
.
core
.
dex
.
instructions
.
args
;
package
jadx
.
core
.
dex
.
instructions
.
args
;
import
java.util.List
;
public
abstract
class
Typed
{
public
abstract
class
Typed
{
protected
TypedVar
typedVar
;
TypedVar
typedVar
;
public
TypedVar
getTypedVar
()
{
public
TypedVar
getTypedVar
()
{
return
typedVar
;
return
typedVar
;
}
}
public
void
setTypedVar
(
TypedVar
arg
)
{
this
.
typedVar
=
arg
;
}
public
ArgType
getType
()
{
public
ArgType
getType
()
{
return
typedVar
.
getType
();
return
typedVar
.
getType
();
}
}
...
@@ -24,26 +22,50 @@ public abstract class Typed {
...
@@ -24,26 +22,50 @@ public abstract class Typed {
return
typedVar
.
merge
(
var
);
return
typedVar
.
merge
(
var
);
}
}
public
void
replace
(
Typed
var
)
{
public
void
forceSetTypedVar
(
TypedVar
arg
)
{
replace
(
var
.
getTypedVar
())
;
this
.
typedVar
=
arg
;
}
}
public
void
replace
(
TypedVar
newVar
)
{
public
void
mergeDebugInfo
(
Typed
arg
)
{
if
(
typedVar
==
newVar
)
merge
(
arg
);
return
;
mergeName
(
arg
);
}
if
(
typedVar
!=
null
)
{
protected
void
mergeName
(
Typed
arg
)
{
newVar
.
merge
(
typedVar
);
getTypedVar
().
mergeName
(
arg
.
getTypedVar
());
for
(
InsnArg
arg
:
typedVar
.
getUseList
())
{
if
(
arg
!=
this
)
arg
.
setTypedVar
(
newVar
);
}
}
newVar
.
getUseList
().
addAll
(
typedVar
.
getUseList
());
if
(
typedVar
.
getName
()
!=
null
)
public
boolean
replaceTypedVar
(
Typed
var
)
{
newVar
.
setName
(
typedVar
.
getName
());
TypedVar
curVar
=
this
.
typedVar
;
typedVar
.
getUseList
().
clear
();
TypedVar
newVar
=
var
.
typedVar
;
if
(
curVar
==
newVar
)
{
return
false
;
}
}
typedVar
=
newVar
;
if
(
curVar
!=
null
)
{
if
(
curVar
.
isImmutable
())
{
moveInternals
(
newVar
,
curVar
);
}
else
{
newVar
.
merge
(
curVar
);
moveInternals
(
curVar
,
newVar
);
this
.
typedVar
=
newVar
;
}
}
else
{
this
.
typedVar
=
newVar
;
}
return
true
;
}
}
private
void
moveInternals
(
TypedVar
from
,
TypedVar
to
)
{
List
<
InsnArg
>
curUseList
=
from
.
getUseList
();
if
(
curUseList
.
size
()
!=
0
)
{
for
(
InsnArg
arg
:
curUseList
)
{
if
(
arg
!=
this
)
{
arg
.
forceSetTypedVar
(
to
);
}
}
to
.
getUseList
().
addAll
(
curUseList
);
curUseList
.
clear
();
}
to
.
mergeName
(
from
);
}
}
}
jadx-core/src/main/java/jadx/core/dex/instructions/args/TypedVar.java
View file @
eec524ad
...
@@ -20,13 +20,8 @@ public class TypedVar {
...
@@ -20,13 +20,8 @@ public class TypedVar {
/**
/**
* This method must be used very carefully
* This method must be used very carefully
*/
*/
public
boolean
forceSetType
(
ArgType
newType
)
{
public
void
forceSetType
(
ArgType
newType
)
{
if
(!
newType
.
equals
(
type
))
{
type
=
newType
;
type
=
newType
;
return
true
;
}
else
{
return
false
;
}
}
}
public
boolean
merge
(
TypedVar
typedVar
)
{
public
boolean
merge
(
TypedVar
typedVar
)
{
...
@@ -43,11 +38,6 @@ public class TypedVar {
...
@@ -43,11 +38,6 @@ public class TypedVar {
}
}
}
}
public
void
use
(
InsnArg
arg
)
{
arg
.
replace
(
this
);
useList
.
add
(
arg
);
}
public
List
<
InsnArg
>
getUseList
()
{
public
List
<
InsnArg
>
getUseList
()
{
return
useList
;
return
useList
;
}
}
...
@@ -60,6 +50,19 @@ public class TypedVar {
...
@@ -60,6 +50,19 @@ public class TypedVar {
this
.
name
=
name
;
this
.
name
=
name
;
}
}
public
void
mergeName
(
TypedVar
arg
)
{
String
name
=
arg
.
getName
();
if
(
name
!=
null
)
{
setName
(
name
);
}
else
if
(
getName
()
!=
null
)
{
arg
.
setName
(
getName
());
}
}
public
boolean
isImmutable
()
{
return
false
;
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
type
.
hashCode
()
*
31
+
(
name
==
null
?
0
:
name
.
hashCode
());
return
type
.
hashCode
()
*
31
+
(
name
==
null
?
0
:
name
.
hashCode
());
...
@@ -69,7 +72,7 @@ public class TypedVar {
...
@@ -69,7 +72,7 @@ public class TypedVar {
public
boolean
equals
(
Object
obj
)
{
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
(
))
return
false
;
if
(
!(
obj
instanceof
TypedVar
))
return
false
;
TypedVar
other
=
(
TypedVar
)
obj
;
TypedVar
other
=
(
TypedVar
)
obj
;
if
(!
type
.
equals
(
other
.
type
))
return
false
;
if
(!
type
.
equals
(
other
.
type
))
return
false
;
if
(
name
==
null
)
{
if
(
name
==
null
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
View file @
eec524ad
...
@@ -291,6 +291,10 @@ public class ClassNode extends LineAttrNode implements ILoadable {
...
@@ -291,6 +291,10 @@ public class ClassNode extends LineAttrNode implements ILoadable {
innerClasses
.
add
(
cls
);
innerClasses
.
add
(
cls
);
}
}
public
boolean
isEnum
()
{
return
getAccessFlags
().
isEnum
()
&&
getSuperClass
().
getFullName
().
equals
(
Consts
.
CLASS_ENUM
);
}
public
boolean
isAnonymous
()
{
public
boolean
isAnonymous
()
{
boolean
simple
=
false
;
boolean
simple
=
false
;
for
(
MethodNode
m
:
methods
)
{
for
(
MethodNode
m
:
methods
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java
View file @
eec524ad
...
@@ -125,12 +125,13 @@ public class InsnNode extends LineAttrNode {
...
@@ -125,12 +125,13 @@ public class InsnNode extends LineAttrNode {
public
void
getRegisterArgs
(
List
<
RegisterArg
>
list
)
{
public
void
getRegisterArgs
(
List
<
RegisterArg
>
list
)
{
for
(
InsnArg
arg
:
this
.
getArguments
())
{
for
(
InsnArg
arg
:
this
.
getArguments
())
{
if
(
arg
.
isRegister
())
if
(
arg
.
isRegister
())
{
list
.
add
((
RegisterArg
)
arg
);
list
.
add
((
RegisterArg
)
arg
);
else
if
(
arg
.
isInsnWrap
())
}
else
if
(
arg
.
isInsnWrap
())
{
((
InsnWrapArg
)
arg
).
getWrapInsn
().
getRegisterArgs
(
list
);
((
InsnWrapArg
)
arg
).
getWrapInsn
().
getRegisterArgs
(
list
);
}
}
}
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
View file @
eec524ad
...
@@ -17,7 +17,6 @@ import jadx.core.dex.instructions.SwitchNode;
...
@@ -17,7 +17,6 @@ import jadx.core.dex.instructions.SwitchNode;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.nodes.parser.DebugInfoParser
;
import
jadx.core.dex.nodes.parser.DebugInfoParser
;
import
jadx.core.dex.trycatch.ExcHandlerAttr
;
import
jadx.core.dex.trycatch.ExcHandlerAttr
;
import
jadx.core.dex.trycatch.ExceptionHandler
;
import
jadx.core.dex.trycatch.ExceptionHandler
;
...
@@ -61,8 +60,6 @@ public class MethodNode extends LineAttrNode implements ILoadable {
...
@@ -61,8 +60,6 @@ public class MethodNode extends LineAttrNode implements ILoadable {
private
BlockNode
enterBlock
;
private
BlockNode
enterBlock
;
private
List
<
BlockNode
>
exitBlocks
;
private
List
<
BlockNode
>
exitBlocks
;
private
ConstructorInsn
superCall
;
private
IContainer
region
;
private
IContainer
region
;
private
List
<
ExceptionHandler
>
exceptionHandlers
;
private
List
<
ExceptionHandler
>
exceptionHandlers
;
private
List
<
LoopAttr
>
loops
=
Collections
.
emptyList
();
private
List
<
LoopAttr
>
loops
=
Collections
.
emptyList
();
...
@@ -204,22 +201,19 @@ public class MethodNode extends LineAttrNode implements ILoadable {
...
@@ -204,22 +201,19 @@ public class MethodNode extends LineAttrNode implements ILoadable {
for
(
ArgType
arg
:
args
)
for
(
ArgType
arg
:
args
)
pos
-=
arg
.
getRegCount
();
pos
-=
arg
.
getRegCount
();
}
}
if
(
accFlags
.
isStatic
())
{
if
(
accFlags
.
isStatic
())
{
thisArg
=
null
;
thisArg
=
null
;
}
else
{
}
else
{
thisArg
=
InsnArg
.
r
eg
(
pos
-
1
,
parentClass
.
getClassInfo
().
getType
());
thisArg
=
InsnArg
.
immutableR
eg
(
pos
-
1
,
parentClass
.
getClassInfo
().
getType
());
thisArg
.
getTypedVar
().
setName
(
"this"
);
thisArg
.
getTypedVar
().
setName
(
"this"
);
}
}
if
(
args
.
isEmpty
())
{
if
(
args
.
isEmpty
())
{
argsList
=
Collections
.
emptyList
();
argsList
=
Collections
.
emptyList
();
return
;
return
;
}
}
argsList
=
new
ArrayList
<
RegisterArg
>(
args
.
size
());
argsList
=
new
ArrayList
<
RegisterArg
>(
args
.
size
());
for
(
ArgType
arg
:
args
)
{
for
(
ArgType
arg
:
args
)
{
argsList
.
add
(
InsnArg
.
r
eg
(
pos
,
arg
));
argsList
.
add
(
InsnArg
.
immutableR
eg
(
pos
,
arg
));
pos
+=
arg
.
getRegCount
();
pos
+=
arg
.
getRegCount
();
}
}
}
}
...
@@ -483,14 +477,6 @@ public class MethodNode extends LineAttrNode implements ILoadable {
...
@@ -483,14 +477,6 @@ public class MethodNode extends LineAttrNode implements ILoadable {
return
accFlags
;
return
accFlags
;
}
}
public
void
setSuperCall
(
ConstructorInsn
insn
)
{
this
.
superCall
=
insn
;
}
public
ConstructorInsn
getSuperCall
()
{
return
this
.
superCall
;
}
public
IContainer
getRegion
()
{
public
IContainer
getRegion
()
{
return
region
;
return
region
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
View file @
eec524ad
...
@@ -94,7 +94,6 @@ public class RootNode {
...
@@ -94,7 +94,6 @@ public class RootNode {
public
ClassNode
resolveClass
(
ClassInfo
cls
)
{
public
ClassNode
resolveClass
(
ClassInfo
cls
)
{
String
fullName
=
cls
.
getFullName
();
String
fullName
=
cls
.
getFullName
();
ClassNode
rCls
=
searchClassByName
(
fullName
);
return
searchClassByName
(
fullName
);
return
rCls
;
}
}
}
}
jadx-core/src/main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java
View file @
eec524ad
...
@@ -211,8 +211,9 @@ public class DebugInfoParser {
...
@@ -211,8 +211,9 @@ public class DebugInfoParser {
private
static
void
merge
(
InsnArg
arg
,
LocalVar
var
)
{
private
static
void
merge
(
InsnArg
arg
,
LocalVar
var
)
{
if
(
arg
!=
null
&&
arg
.
isRegister
())
{
if
(
arg
!=
null
&&
arg
.
isRegister
())
{
if
(
var
.
getRegNum
()
==
((
RegisterArg
)
arg
).
getRegNum
())
if
(
var
.
getRegNum
()
==
((
RegisterArg
)
arg
).
getRegNum
())
{
arg
.
setTypedVar
(
var
.
getTypedVar
());
arg
.
mergeDebugInfo
(
var
);
}
}
}
}
}
}
}
jadx-core/src/main/java/jadx/core/dex/nodes/parser/LocalVar.java
View file @
eec524ad
...
@@ -33,7 +33,7 @@ final class LocalVar extends RegisterArg {
...
@@ -33,7 +33,7 @@ final class LocalVar extends RegisterArg {
}
}
TypedVar
tv
=
new
TypedVar
(
type
);
TypedVar
tv
=
new
TypedVar
(
type
);
tv
.
setName
(
name
);
tv
.
setName
(
name
);
s
etTypedVar
(
tv
);
forceS
etTypedVar
(
tv
);
}
}
public
void
start
(
int
addr
,
int
line
)
{
public
void
start
(
int
addr
,
int
line
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
View file @
eec524ad
...
@@ -34,14 +34,12 @@ public class ClassModifier extends AbstractVisitor {
...
@@ -34,14 +34,12 @@ public class ClassModifier extends AbstractVisitor {
if
(
af
.
isConstructor
()
if
(
af
.
isConstructor
()
&&
af
.
isPublic
()
&&
af
.
isPublic
()
&&
mth
.
getArguments
(
false
).
isEmpty
())
{
&&
mth
.
getArguments
(
false
).
isEmpty
())
{
if
(
mth
.
getSuperCall
()
==
null
)
{
List
<
BlockNode
>
bb
=
mth
.
getBasicBlocks
();
List
<
BlockNode
>
bb
=
mth
.
getBasicBlocks
();
if
(
bb
.
isEmpty
()
||
allBlocksEmpty
(
bb
))
{
if
(
bb
.
isEmpty
()
||
allBlocksEmpty
(
bb
))
{
it
.
remove
();
it
.
remove
();
}
}
}
}
}
}
}
return
false
;
return
false
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
View file @
eec524ad
...
@@ -60,7 +60,7 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -60,7 +60,7 @@ public class CodeShrinker extends AbstractVisitor {
InsnArg
useInsnArg
=
selectOther
(
useList
,
result
);
InsnArg
useInsnArg
=
selectOther
(
useList
,
result
);
InsnNode
useInsn
=
useInsnArg
.
getParentInsn
();
InsnNode
useInsn
=
useInsnArg
.
getParentInsn
();
if
(
useInsn
==
null
)
{
if
(
useInsn
==
null
)
{
LOG
.
debug
(
"parent insn null
in "
+
useInsnArg
+
" from "
+
insn
+
" mth: "
+
mth
);
LOG
.
debug
(
"parent insn null
: {}, mth: {}"
,
insn
,
mth
);
}
else
if
(
useInsn
!=
insn
)
{
}
else
if
(
useInsn
!=
insn
)
{
boolean
wrap
=
false
;
boolean
wrap
=
false
;
// TODO
// TODO
...
@@ -213,7 +213,7 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -213,7 +213,7 @@ public class CodeShrinker extends AbstractVisitor {
}
}
RegisterArg
fArg
=
new
FieldArg
(
field
,
reg
!=
null
?
reg
.
getRegNum
()
:
-
1
);
RegisterArg
fArg
=
new
FieldArg
(
field
,
reg
!=
null
?
reg
.
getRegNum
()
:
-
1
);
if
(
reg
!=
null
)
{
if
(
reg
!=
null
)
{
fArg
.
setTypedVar
(
get
.
getArg
(
0
).
getTypedVar
(
));
fArg
.
replaceTypedVar
(
get
.
getArg
(
0
));
}
}
if
(
wrapType
==
InsnType
.
ARITH
)
{
if
(
wrapType
==
InsnType
.
ARITH
)
{
ArithNode
ar
=
(
ArithNode
)
wrap
;
ArithNode
ar
=
(
ArithNode
)
wrap
;
...
@@ -269,9 +269,9 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -269,9 +269,9 @@ public class CodeShrinker extends AbstractVisitor {
public
static
InsnArg
inlineArgument
(
MethodNode
mth
,
RegisterArg
arg
)
{
public
static
InsnArg
inlineArgument
(
MethodNode
mth
,
RegisterArg
arg
)
{
InsnNode
assignInsn
=
arg
.
getAssignInsn
();
InsnNode
assignInsn
=
arg
.
getAssignInsn
();
if
(
assignInsn
==
null
)
if
(
assignInsn
==
null
)
{
return
null
;
return
null
;
}
// recursively wrap all instructions
// recursively wrap all instructions
List
<
RegisterArg
>
list
=
new
ArrayList
<
RegisterArg
>();
List
<
RegisterArg
>
list
=
new
ArrayList
<
RegisterArg
>();
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
false
);
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
false
);
...
@@ -281,17 +281,18 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -281,17 +281,18 @@ public class CodeShrinker extends AbstractVisitor {
assignInsn
.
getRegisterArgs
(
list
);
assignInsn
.
getRegisterArgs
(
list
);
for
(
RegisterArg
rarg
:
list
)
{
for
(
RegisterArg
rarg
:
list
)
{
InsnNode
ai
=
rarg
.
getAssignInsn
();
InsnNode
ai
=
rarg
.
getAssignInsn
();
if
(
ai
!=
assignInsn
&&
ai
!=
null
if
(
ai
!=
assignInsn
&&
ai
!=
null
&&
ai
!=
rarg
.
getParentInsn
())
{
&&
rarg
.
getParentInsn
()
!=
ai
)
rarg
.
wrapInstruction
(
ai
);
rarg
.
wrapInstruction
(
ai
);
}
}
}
// remove method args
// remove method args
if
(
list
.
size
()
!=
0
&&
args
.
size
()
!=
0
)
{
if
(
list
.
size
()
!=
0
&&
args
.
size
()
!=
0
)
{
list
.
removeAll
(
args
);
list
.
removeAll
(
args
);
}
}
i
++;
i
++;
if
(
i
>
1000
)
if
(
i
>
1000
)
{
throw
new
JadxRuntimeException
(
"Can't inline arguments for: "
+
arg
+
" insn: "
+
assignInsn
);
throw
new
JadxRuntimeException
(
"Can't inline arguments for: "
+
arg
+
" insn: "
+
assignInsn
);
}
}
while
(!
list
.
isEmpty
());
}
while
(!
list
.
isEmpty
());
return
arg
.
wrapInstruction
(
assignInsn
);
return
arg
.
wrapInstruction
(
assignInsn
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java
View file @
eec524ad
...
@@ -69,7 +69,6 @@ public class DotGraphVisitor extends AbstractVisitor {
...
@@ -69,7 +69,6 @@ public class DotGraphVisitor extends AbstractVisitor {
+
mth
.
getParentClass
().
getFullName
()
+
"."
+
mth
.
getName
()
+
mth
.
getParentClass
().
getFullName
()
+
"."
+
mth
.
getName
()
+
"("
+
Utils
.
listToString
(
mth
.
getArguments
(
true
))
+
") "
)
+
"("
+
Utils
.
listToString
(
mth
.
getArguments
(
true
))
+
") "
)
+
(
attrs
.
length
()
==
0
?
""
:
" | "
+
attrs
)
+
(
attrs
.
length
()
==
0
?
""
:
" | "
+
attrs
)
+
(
mth
.
getSuperCall
()
!=
null
?
"| Super call: "
+
escape
(
mth
.
getSuperCall
().
toString
())
:
""
)
+
"}\"];"
);
+
"}\"];"
);
dot
.
startLine
(
"MethodNode -> "
+
makeName
(
mth
.
getEnterBlock
())
+
";"
);
dot
.
startLine
(
"MethodNode -> "
+
makeName
(
mth
.
getEnterBlock
())
+
";"
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/EnumVisitor.java
View file @
eec524ad
...
@@ -30,8 +30,7 @@ public class EnumVisitor extends AbstractVisitor {
...
@@ -30,8 +30,7 @@ public class EnumVisitor extends AbstractVisitor {
@Override
@Override
public
boolean
visit
(
ClassNode
cls
)
throws
JadxException
{
public
boolean
visit
(
ClassNode
cls
)
throws
JadxException
{
if
(!
cls
.
getAccessFlags
().
isEnum
()
if
(!
cls
.
isEnum
())
||
!
cls
.
getSuperClass
().
getFullName
().
equals
(
"java.lang.Enum"
))
return
true
;
return
true
;
// collect enum fields, remove synthetic
// collect enum fields, remove synthetic
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
View file @
eec524ad
...
@@ -52,6 +52,7 @@ public class ModVisitor extends AbstractVisitor {
...
@@ -52,6 +52,7 @@ public class ModVisitor extends AbstractVisitor {
}
}
private
void
replaceStep
(
MethodNode
mth
)
{
private
void
replaceStep
(
MethodNode
mth
)
{
ConstructorInsn
superCall
=
null
;
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
InstructionRemover
remover
=
new
InstructionRemover
(
block
.
getInstructions
());
InstructionRemover
remover
=
new
InstructionRemover
(
block
.
getInstructions
());
...
@@ -75,14 +76,13 @@ public class ModVisitor extends AbstractVisitor {
...
@@ -75,14 +76,13 @@ public class ModVisitor extends AbstractVisitor {
CodeShrinker
.
inlineArgument
(
mth
,
(
RegisterArg
)
arg
);
CodeShrinker
.
inlineArgument
(
mth
,
(
RegisterArg
)
arg
);
}
}
}
}
if
(!
mth
.
getParentClass
().
getAccessFlags
().
isEnum
())
mth
.
setSuperCall
(
co
);
}
}
remover
.
add
(
insn
);
}
catch
(
JadxRuntimeException
e
)
{
}
catch
(
JadxRuntimeException
e
)
{
// inline args into super fail
// inline args into super fail
LOG
.
warn
(
"Can't inline args into super call: "
+
inv
+
", mth: "
+
mth
);
LOG
.
warn
(
"Can't inline args into super call: "
+
inv
+
", mth: "
+
mth
);
replaceInsn
(
block
,
i
,
co
);
}
finally
{
superCall
=
co
;
remover
.
add
(
insn
);
}
}
}
else
if
(
co
.
isThis
()
&&
co
.
getArgsCount
()
==
0
)
{
}
else
if
(
co
.
isThis
()
&&
co
.
getArgsCount
()
==
0
)
{
MethodNode
defCo
=
mth
.
getParentClass
()
MethodNode
defCo
=
mth
.
getParentClass
()
...
@@ -138,6 +138,10 @@ public class ModVisitor extends AbstractVisitor {
...
@@ -138,6 +138,10 @@ public class ModVisitor extends AbstractVisitor {
}
}
remover
.
perform
();
remover
.
perform
();
}
}
if
(
superCall
!=
null
&&
!
mth
.
getParentClass
().
isEnum
())
{
List
<
InsnNode
>
insns
=
mth
.
getEnterBlock
().
getInstructions
();
insns
.
add
(
0
,
superCall
);
}
}
}
/**
/**
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/TypeResolver.java
View file @
eec524ad
...
@@ -103,12 +103,12 @@ public class TypeResolver extends AbstractVisitor {
...
@@ -103,12 +103,12 @@ public class TypeResolver extends AbstractVisitor {
if
(
back
)
{
if
(
back
)
{
if
(
er
.
getTypedVar
()
==
null
&&
sr
.
getTypedVar
()
!=
null
)
{
if
(
er
.
getTypedVar
()
==
null
&&
sr
.
getTypedVar
()
!=
null
)
{
er
.
replace
(
sr
);
er
.
replace
TypedVar
(
sr
);
changed
=
true
;
changed
=
true
;
}
}
}
else
{
}
else
{
if
(
sr
.
getTypedVar
()
!=
null
&&
er
.
getTypedVar
()
!=
null
)
{
if
(
sr
.
getTypedVar
()
!=
null
&&
er
.
getTypedVar
()
!=
null
)
{
sr
.
replace
(
er
);
sr
.
replace
TypedVar
(
er
);
changed
=
true
;
changed
=
true
;
}
}
}
}
...
...
jadx-core/src/test/java/jadx/tests/functional/JadxClasspathTest.java
View file @
eec524ad
...
@@ -9,6 +9,7 @@ import java.io.IOException;
...
@@ -9,6 +9,7 @@ import java.io.IOException;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
STRING
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
object
;
import
static
jadx
.
core
.
dex
.
instructions
.
args
.
ArgType
.
object
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
@@ -37,5 +38,7 @@ public class JadxClasspathTest {
...
@@ -37,5 +38,7 @@ public class JadxClasspathTest {
assertFalse
(
ArgType
.
isCastNeeded
(
objExc
,
objThr
));
assertFalse
(
ArgType
.
isCastNeeded
(
objExc
,
objThr
));
assertTrue
(
ArgType
.
isCastNeeded
(
objThr
,
objExc
));
assertTrue
(
ArgType
.
isCastNeeded
(
objThr
,
objExc
));
assertTrue
(
ArgType
.
isCastNeeded
(
ArgType
.
OBJECT
,
STRING
));
}
}
}
}
jadx-core/src/test/java/jadx/tests/internal/TestDuplicateCast.java
View file @
eec524ad
...
@@ -9,8 +9,6 @@ import jadx.core.dex.nodes.MethodNode;
...
@@ -9,8 +9,6 @@ import jadx.core.dex.nodes.MethodNode;
import
java.util.List
;
import
java.util.List
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
...
@@ -25,11 +23,14 @@ public class TestDuplicateCast extends InternalJadxTest {
...
@@ -25,11 +23,14 @@ public class TestDuplicateCast extends InternalJadxTest {
}
}
}
}
@Test
//
@Test
public
void
test
()
{
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
MethodNode
mth
=
getMethod
(
cls
,
"method"
);
MethodNode
mth
=
getMethod
(
cls
,
"method"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"return (int[]) o;"
));
List
<
InsnNode
>
insns
=
mth
.
getBasicBlocks
().
get
(
1
).
getInstructions
();
List
<
InsnNode
>
insns
=
mth
.
getBasicBlocks
().
get
(
1
).
getInstructions
();
assertEquals
(
insns
.
size
(),
1
);
assertEquals
(
insns
.
size
(),
1
);
InsnNode
insnNode
=
insns
.
get
(
0
);
InsnNode
insnNode
=
insns
.
get
(
0
);
...
@@ -38,8 +39,5 @@ public class TestDuplicateCast extends InternalJadxTest {
...
@@ -38,8 +39,5 @@ public class TestDuplicateCast extends InternalJadxTest {
InsnNode
wrapInsn
=
((
InsnWrapArg
)
insnNode
.
getArg
(
0
)).
getWrapInsn
();
InsnNode
wrapInsn
=
((
InsnWrapArg
)
insnNode
.
getArg
(
0
)).
getWrapInsn
();
assertEquals
(
InsnType
.
CHECK_CAST
,
wrapInsn
.
getType
());
assertEquals
(
InsnType
.
CHECK_CAST
,
wrapInsn
.
getType
());
assertFalse
(
wrapInsn
.
getArg
(
0
).
isInsnWrap
());
assertFalse
(
wrapInsn
.
getArg
(
0
).
isInsnWrap
());
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"return (int[]) o;"
));
}
}
}
}
jadx-core/src/test/java/jadx/tests/internal/TestRedundantBrackets.java
View file @
eec524ad
...
@@ -57,5 +57,10 @@ public class TestRedundantBrackets extends InternalJadxTest {
...
@@ -57,5 +57,10 @@ public class TestRedundantBrackets extends InternalJadxTest {
assertThat
(
code
,
containsString
(
"a[1] = n * 2;"
));
assertThat
(
code
,
containsString
(
"a[1] = n * 2;"
));
assertThat
(
code
,
containsString
(
"a[n - 1] = 1;"
));
assertThat
(
code
,
containsString
(
"a[n - 1] = 1;"
));
// argument type not changed to String
assertThat
(
code
,
containsString
(
"public int method2(Object obj) {"
));
// cast not eliminated
assertThat
(
code
,
containsString
(
"((String) obj).length()"
));
}
}
}
}
jadx-samples/src/main/java/jadx/samples/TestTypeResolver.java
View file @
eec524ad
...
@@ -20,7 +20,7 @@ public class TestTypeResolver extends AbstractTest {
...
@@ -20,7 +20,7 @@ public class TestTypeResolver extends AbstractTest {
public
static
class
TestTernaryInSuper
extends
TestTypeResolver
{
public
static
class
TestTernaryInSuper
extends
TestTypeResolver
{
public
TestTernaryInSuper
(
int
c
)
{
public
TestTernaryInSuper
(
int
c
)
{
super
(
c
>
0
?
c
:
-
c
,
1
);
//
super(c > 0 ? c : -c, 1);
}
}
}
}
...
...
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