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
3c84975a
Commit
3c84975a
authored
Feb 22, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix code style issues
parent
bb4ef4f0
Show whitespace changes
Inline
Side-by-side
Showing
58 changed files
with
352 additions
and
367 deletions
+352
-367
JadxCLIArgs.java
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
+13
-11
Decompiler.java
jadx-core/src/main/java/jadx/api/Decompiler.java
+11
-12
Jadx.java
jadx-core/src/main/java/jadx/core/Jadx.java
+2
-2
ProcessClass.java
jadx-core/src/main/java/jadx/core/ProcessClass.java
+5
-9
AnnotationGen.java
jadx-core/src/main/java/jadx/core/codegen/AnnotationGen.java
+1
-1
ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+4
-5
CodeWriter.java
jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java
+2
-2
ConditionGen.java
jadx-core/src/main/java/jadx/core/codegen/ConditionGen.java
+1
-1
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+4
-3
MethodGen.java
jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
+3
-2
RegionGen.java
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
+39
-107
NameMapper.java
jadx-core/src/main/java/jadx/core/deobf/NameMapper.java
+2
-1
AttributeFlag.java
...src/main/java/jadx/core/dex/attributes/AttributeFlag.java
+2
-0
AttributeType.java
...src/main/java/jadx/core/dex/attributes/AttributeType.java
+2
-1
BlockRegState.java
...src/main/java/jadx/core/dex/attributes/BlockRegState.java
+1
-1
DeclareVariablesAttr.java
...n/java/jadx/core/dex/attributes/DeclareVariablesAttr.java
+33
-0
JadxErrorAttr.java
...src/main/java/jadx/core/dex/attributes/JadxErrorAttr.java
+1
-1
JumpAttribute.java
...src/main/java/jadx/core/dex/attributes/JumpAttribute.java
+1
-5
ClassInfo.java
jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
+14
-14
MethodInfo.java
jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java
+3
-5
ArgType.java
...rc/main/java/jadx/core/dex/instructions/args/ArgType.java
+1
-1
RegisterArg.java
...ain/java/jadx/core/dex/instructions/args/RegisterArg.java
+2
-8
TypedVar.java
...c/main/java/jadx/core/dex/instructions/args/TypedVar.java
+3
-3
ClassNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
+1
-1
InsnNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java
+3
-5
RootNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
+1
-1
AnnotationsParser.java
...in/java/jadx/core/dex/nodes/parser/AnnotationsParser.java
+17
-6
DebugInfoParser.java
...main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java
+17
-12
LoopRegion.java
...-core/src/main/java/jadx/core/dex/regions/LoopRegion.java
+2
-2
TernaryRegion.java
...re/src/main/java/jadx/core/dex/regions/TernaryRegion.java
+1
-1
BlockMakerVisitor.java
...c/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java
+11
-10
ClassModifier.java
...e/src/main/java/jadx/core/dex/visitors/ClassModifier.java
+8
-10
CodeShrinker.java
...re/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
+2
-4
ConstInlinerVisitor.java
...main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
+2
-4
DotGraphVisitor.java
...src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java
+4
-11
MethodInlineVisitor.java
...main/java/jadx/core/dex/visitors/MethodInlineVisitor.java
+10
-7
ModVisitor.java
...core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
+4
-4
CheckRegions.java
...ain/java/jadx/core/dex/visitors/regions/CheckRegions.java
+5
-12
ProcessTryCatchRegions.java
...adx/core/dex/visitors/regions/ProcessTryCatchRegions.java
+2
-2
ProcessVariables.java
...java/jadx/core/dex/visitors/regions/ProcessVariables.java
+7
-7
RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+6
-6
TracedRegionVisitor.java
...a/jadx/core/dex/visitors/regions/TracedRegionVisitor.java
+1
-1
TypeResolver.java
...ava/jadx/core/dex/visitors/typeresolver/TypeResolver.java
+7
-8
CheckTypeVisitor.java
...re/dex/visitors/typeresolver/finish/CheckTypeVisitor.java
+4
-5
BlockUtils.java
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
+4
-11
ErrorsCounter.java
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
+1
-1
InsnUtils.java
jadx-core/src/main/java/jadx/core/utils/InsnUtils.java
+1
-1
RegionUtils.java
jadx-core/src/main/java/jadx/core/utils/RegionUtils.java
+3
-5
InternalJadxTest.java
jadx-core/src/test/java/jadx/api/InternalJadxTest.java
+3
-0
TestSyntheticInline.java
.../java/jadx/tests/internal/inline/TestSyntheticInline.java
+49
-0
JClass.java
jadx-gui/src/main/java/jadx/gui/treemodel/JClass.java
+5
-6
JField.java
jadx-gui/src/main/java/jadx/gui/treemodel/JField.java
+0
-4
JMethod.java
jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java
+0
-4
JNode.java
jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java
+0
-2
JPackage.java
jadx-gui/src/main/java/jadx/gui/treemodel/JPackage.java
+4
-5
JRoot.java
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
+5
-6
TextNode.java
jadx-gui/src/main/java/jadx/gui/treemodel/TextNode.java
+0
-4
Utils.java
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
+12
-4
No files found.
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
View file @
3c84975a
...
...
@@ -68,25 +68,25 @@ public final class JadxCLIArgs implements IJadxArgs {
System
.
exit
(
0
);
}
try
{
if
(
threadsCount
<=
0
)
if
(
threadsCount
<=
0
)
{
throw
new
JadxException
(
"Threads count must be positive"
);
}
if
(
files
!=
null
)
{
for
(
String
fileName
:
files
)
{
File
file
=
new
File
(
fileName
);
if
(
file
.
exists
())
if
(
file
.
exists
())
{
input
.
add
(
file
);
else
}
else
{
throw
new
JadxException
(
"File not found: "
+
file
);
}
}
if
(
input
.
size
()
>
1
)
}
if
(
input
.
size
()
>
1
)
{
throw
new
JadxException
(
"Only one input file is supported"
);
if
(
outDirName
!=
null
)
}
if
(
outDirName
!=
null
)
{
outputDir
=
new
File
(
outDirName
);
}
if
(
isVerbose
())
{
ch
.
qos
.
logback
.
classic
.
Logger
rootLogger
=
(
ch
.
qos
.
logback
.
classic
.
Logger
)
LoggerFactory
.
getLogger
(
Logger
.
ROOT_LOGGER_NAME
);
...
...
@@ -114,9 +114,10 @@ public final class JadxCLIArgs implements IJadxArgs {
int
maxNamesLen
=
0
;
for
(
ParameterDescription
p
:
params
)
{
int
len
=
p
.
getNames
().
length
();
if
(
len
>
maxNamesLen
)
if
(
len
>
maxNamesLen
)
{
maxNamesLen
=
len
;
}
}
Field
[]
fields
=
this
.
getClass
().
getDeclaredFields
();
for
(
Field
f
:
fields
)
{
...
...
@@ -137,9 +138,10 @@ public final class JadxCLIArgs implements IJadxArgs {
}
private
static
void
addSpaces
(
StringBuilder
str
,
int
count
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
str
.
append
(
' '
);
}
}
public
List
<
File
>
getInput
()
{
return
input
;
...
...
jadx-core/src/main/java/jadx/api/Decompiler.java
View file @
3c84975a
...
...
@@ -16,7 +16,6 @@ import jadx.core.utils.files.InputFile;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
...
...
@@ -80,7 +79,7 @@ public final class Decompiler {
}
public
void
loadFile
(
File
file
)
throws
IOException
,
DecodeException
{
loadFiles
(
Arrays
.
as
List
(
file
));
loadFiles
(
Collections
.
singleton
List
(
file
));
}
public
void
loadFiles
(
List
<
File
>
files
)
throws
IOException
,
DecodeException
{
...
...
@@ -110,15 +109,20 @@ public final class Decompiler {
int
threadsCount
=
args
.
getThreadsCount
();
LOG
.
debug
(
"processing threads count: {}"
,
threadsCount
);
Array
List
<
IDexTreeVisitor
>
passList
=
new
ArrayList
<
IDexTreeVisitor
>(
passes
);
final
List
<
IDexTreeVisitor
>
passList
=
new
ArrayList
<
IDexTreeVisitor
>(
passes
);
SaveCode
savePass
=
new
SaveCode
(
outDir
,
args
);
passList
.
add
(
savePass
);
LOG
.
info
(
"processing ..."
);
ThreadPoolExecutor
executor
=
(
ThreadPoolExecutor
)
Executors
.
newFixedThreadPool
(
threadsCount
);
for
(
ClassNode
cls
:
root
.
getClasses
(
false
))
{
for
(
final
ClassNode
cls
:
root
.
getClasses
(
false
))
{
if
(
cls
.
getCode
()
==
null
)
{
ProcessClass
job
=
new
ProcessClass
(
cls
,
passList
);
Runnable
job
=
new
Runnable
()
{
@Override
public
void
run
()
{
ProcessClass
.
process
(
cls
,
passList
);
}
};
executor
.
execute
(
job
);
}
else
{
try
{
...
...
@@ -183,13 +187,8 @@ public final class Decompiler {
}
void
processClass
(
ClassNode
cls
)
{
try
{
ProcessClass
job
=
new
ProcessClass
(
cls
,
passes
);
LOG
.
info
(
"processing class {} ..."
,
cls
);
job
.
run
();
}
catch
(
Throwable
e
)
{
LOG
.
error
(
"Process class error"
,
e
);
}
ProcessClass
.
process
(
cls
,
passes
);
}
RootNode
getRoot
()
{
...
...
jadx-core/src/main/java/jadx/core/Jadx.java
View file @
3c84975a
...
...
@@ -10,7 +10,7 @@ import jadx.core.dex.visitors.DotGraphVisitor;
import
jadx.core.dex.visitors.EnumVisitor
;
import
jadx.core.dex.visitors.FallbackModeVisitor
;
import
jadx.core.dex.visitors.IDexTreeVisitor
;
import
jadx.core.dex.visitors.MethodInline
r
Visitor
;
import
jadx.core.dex.visitors.MethodInlineVisitor
;
import
jadx.core.dex.visitors.ModVisitor
;
import
jadx.core.dex.visitors.SimplifyVisitor
;
import
jadx.core.dex.visitors.regions.CheckRegions
;
...
...
@@ -79,7 +79,7 @@ public class Jadx {
passes
.
add
(
new
DotGraphVisitor
(
outDir
,
true
));
}
passes
.
add
(
new
MethodInline
r
Visitor
());
passes
.
add
(
new
MethodInlineVisitor
());
passes
.
add
(
new
ClassModifier
());
}
passes
.
add
(
new
CodeGen
(
args
));
...
...
jadx-core/src/main/java/jadx/core/ProcessClass.java
View file @
3c84975a
...
...
@@ -10,19 +10,13 @@ import java.util.List;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
final
class
ProcessClass
implements
Runnable
{
public
final
class
ProcessClass
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ProcessClass
.
class
);
private
final
ClassNode
cls
;
private
final
List
<
IDexTreeVisitor
>
passes
;
public
ProcessClass
(
ClassNode
cls
,
List
<
IDexTreeVisitor
>
passes
)
{
this
.
cls
=
cls
;
this
.
passes
=
passes
;
private
ProcessClass
()
{
}
@Override
public
void
run
()
{
public
static
void
process
(
ClassNode
cls
,
List
<
IDexTreeVisitor
>
passes
)
{
try
{
cls
.
load
();
for
(
IDexTreeVisitor
visitor
:
passes
)
{
...
...
@@ -30,6 +24,8 @@ public final class ProcessClass implements Runnable {
}
}
catch
(
DecodeException
e
)
{
LOG
.
error
(
"Decode exception: "
+
cls
,
e
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Class process exception: "
+
cls
,
e
);
}
finally
{
cls
.
unload
();
}
...
...
jadx-core/src/main/java/jadx/core/codegen/AnnotationGen.java
View file @
3c84975a
...
...
@@ -76,7 +76,7 @@ public class AnnotationGen {
code
.
add
(
'@'
);
code
.
add
(
classGen
.
useClass
(
a
.
getType
()));
Map
<
String
,
Object
>
vl
=
a
.
getValues
();
if
(
vl
.
size
()
!=
0
)
{
if
(
!
vl
.
isEmpty
()
)
{
code
.
add
(
'('
);
if
(
vl
.
size
()
==
1
&&
vl
.
containsKey
(
"value"
))
{
code
.
add
(
encValueToString
(
vl
.
get
(
"value"
)));
...
...
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
View file @
3c84975a
...
...
@@ -379,13 +379,12 @@ public class ClassGen {
if
(
searchCollision
(
cls
.
dex
(),
useCls
,
shortName
))
{
return
clsStr
;
}
for
(
ClassInfo
c
ls
:
imports
)
{
if
(!
cls
.
equals
(
classInfo
))
{
if
(
c
ls
.
getShortName
().
equals
(
shortName
))
{
for
(
ClassInfo
importC
ls
:
imports
)
{
if
(!
importCls
.
equals
(
classInfo
)
&&
importC
ls
.
getShortName
().
equals
(
shortName
))
{
return
clsStr
;
}
}
}
addImport
(
classInfo
);
return
shortName
;
}
...
...
jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java
View file @
3c84975a
...
...
@@ -82,7 +82,7 @@ public class CodeWriter {
attachAnnotation
(
entry
.
getKey
(),
line
+
entry
.
getValue
());
}
line
+=
code
.
line
;
buf
.
append
(
code
.
toString
()
);
buf
.
append
(
code
);
return
this
;
}
...
...
@@ -116,7 +116,7 @@ public class CodeWriter {
return
this
;
}
private
static
final
String
[]
INDENT_CACHE
=
new
String
[]
{
private
static
final
String
[]
INDENT_CACHE
=
{
""
,
INDENT
,
INDENT
+
INDENT
,
...
...
jadx-core/src/main/java/jadx/core/codegen/ConditionGen.java
View file @
3c84975a
...
...
@@ -42,7 +42,7 @@ public class ConditionGen {
}
return
sb
.
toString
();
default
:
return
"??"
+
condition
.
toString
()
;
return
"??"
+
condition
;
}
}
...
...
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
3c84975a
...
...
@@ -114,7 +114,7 @@ public class InsnGen {
public
String
assignVar
(
InsnNode
insn
)
throws
CodegenException
{
RegisterArg
arg
=
insn
.
getResult
();
if
(
insn
.
getAttributes
().
contains
(
Attribute
Type
.
DECLARE_VARIABLE
))
{
if
(
insn
.
getAttributes
().
contains
(
Attribute
Flag
.
DECLARE_VAR
))
{
return
declareVar
(
arg
);
}
else
{
return
arg
(
arg
).
toString
();
...
...
@@ -125,7 +125,7 @@ public class InsnGen {
return
useType
(
arg
.
getType
())
+
" "
+
mgen
.
assignArg
(
arg
);
}
private
String
lit
(
LiteralArg
arg
)
{
private
static
String
lit
(
LiteralArg
arg
)
{
return
TypeGen
.
literalToString
(
arg
.
getLiteral
(),
arg
.
getType
());
}
...
...
@@ -483,7 +483,8 @@ public class InsnGen {
if
(!
elType
.
equals
(
insnElementType
)
&&
!
insnArrayType
.
equals
(
ArgType
.
OBJECT
))
{
ErrorsCounter
.
methodError
(
mth
,
"Incorrect type for fill-array insn "
+
InsnUtils
.
formatOffset
(
insn
.
getOffset
())
+
", element type: "
+
elType
+
", insn element type: "
+
insnElementType
);
+
", element type: "
+
elType
+
", insn element type: "
+
insnElementType
);
if
(!
elType
.
isTypeKnown
())
{
elType
=
insnElementType
.
isTypeKnown
()
?
insnElementType
:
elType
.
selectFirst
();
}
...
...
jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
View file @
3c84975a
...
...
@@ -105,7 +105,8 @@ public class MethodGen {
}
else
{
LOG
.
warn
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
"Incorrect number of args for enum constructor: "
+
args
.
size
()
+
" (expected >= 2)"
));
+
" (expected >= 2)"
));
}
}
code
.
add
(
makeArguments
(
args
));
...
...
@@ -269,7 +270,7 @@ public class MethodGen {
code
.
startLine
(
"*/"
);
}
private
void
makeFallbackMethod
(
CodeWriter
code
,
MethodNode
mth
)
{
private
static
void
makeFallbackMethod
(
CodeWriter
code
,
MethodNode
mth
)
{
if
(
mth
.
getInstructions
()
==
null
)
{
// loadFile original instructions
try
{
...
...
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
View file @
3c84975a
...
...
@@ -2,19 +2,13 @@ package jadx.core.codegen;
import
jadx.core.dex.attributes.AttributeFlag
;
import
jadx.core.dex.attributes.AttributeType
;
import
jadx.core.dex.attributes.DeclareVariableAttr
;
import
jadx.core.dex.attributes.DeclareVariable
s
Attr
;
import
jadx.core.dex.attributes.ForceReturnAttr
;
import
jadx.core.dex.attributes.IAttribute
;
import
jadx.core.dex.info.FieldInfo
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.IfOp
;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.SwitchNode
;
import
jadx.core.dex.instructions.args.ArgType
;
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.nodes.BlockNode
;
import
jadx.core.dex.nodes.IBlock
;
...
...
@@ -22,7 +16,6 @@ import jadx.core.dex.nodes.IContainer;
import
jadx.core.dex.nodes.IRegion
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.regions.Compare
;
import
jadx.core.dex.regions.IfCondition
;
import
jadx.core.dex.regions.IfRegion
;
import
jadx.core.dex.regions.LoopRegion
;
...
...
@@ -32,7 +25,6 @@ import jadx.core.dex.regions.SynchronizedRegion;
import
jadx.core.dex.trycatch.CatchAttr
;
import
jadx.core.dex.trycatch.ExceptionHandler
;
import
jadx.core.dex.trycatch.TryCatchBlock
;
import
jadx.core.utils.ErrorsCounter
;
import
jadx.core.utils.RegionUtils
;
import
jadx.core.utils.exceptions.CodegenException
;
...
...
@@ -49,22 +41,12 @@ public class RegionGen extends InsnGen {
}
public
void
makeRegion
(
CodeWriter
code
,
IContainer
cont
)
throws
CodegenException
{
assert
cont
!=
null
;
if
(
cont
instanceof
IBlock
)
{
makeSimpleBlock
((
IBlock
)
cont
,
code
);
}
else
if
(
cont
instanceof
IRegion
)
{
declareVars
(
code
,
cont
);
if
(
cont
instanceof
Region
)
{
Region
r
=
(
Region
)
cont
;
CatchAttr
tc
=
(
CatchAttr
)
r
.
getAttributes
().
get
(
AttributeType
.
CATCH_BLOCK
);
if
(
tc
!=
null
)
{
makeTryCatch
(
cont
,
tc
.
getTryBlock
(),
code
);
}
else
{
for
(
IContainer
c
:
r
.
getSubBlocks
())
{
makeRegion
(
code
,
c
);
}
}
makeSimpleRegion
(
code
,
(
Region
)
cont
);
}
else
if
(
cont
instanceof
IfRegion
)
{
makeIf
((
IfRegion
)
cont
,
code
,
true
);
}
else
if
(
cont
instanceof
SwitchRegion
)
{
...
...
@@ -75,13 +57,13 @@ public class RegionGen extends InsnGen {
makeSynchronizedRegion
((
SynchronizedRegion
)
cont
,
code
);
}
}
else
{
throw
new
CodegenException
(
"Not processed container: "
+
cont
.
toString
()
);
throw
new
CodegenException
(
"Not processed container: "
+
cont
);
}
}
private
void
declareVars
(
CodeWriter
code
,
IContainer
cont
)
{
DeclareVariableAttr
declVars
=
(
DeclareVariable
Attr
)
cont
.
getAttributes
().
get
(
AttributeType
.
DECLARE_VARIABLE
);
DeclareVariable
s
Attr
declVars
=
(
DeclareVariable
sAttr
)
cont
.
getAttributes
().
get
(
AttributeType
.
DECLARE_VARIABLES
);
if
(
declVars
!=
null
)
{
for
(
RegisterArg
v
:
declVars
.
getVars
())
{
code
.
startLine
(
declareVar
(
v
)).
add
(
';'
);
...
...
@@ -89,6 +71,17 @@ public class RegionGen extends InsnGen {
}
}
private
void
makeSimpleRegion
(
CodeWriter
code
,
Region
region
)
throws
CodegenException
{
CatchAttr
tc
=
(
CatchAttr
)
region
.
getAttributes
().
get
(
AttributeType
.
CATCH_BLOCK
);
if
(
tc
!=
null
)
{
makeTryCatch
(
region
,
tc
.
getTryBlock
(),
code
);
}
else
{
for
(
IContainer
c
:
region
.
getSubBlocks
())
{
makeRegion
(
code
,
c
);
}
}
}
public
void
makeRegionIndent
(
CodeWriter
code
,
IContainer
region
)
throws
CodegenException
{
code
.
incIndent
();
makeRegion
(
code
,
region
);
...
...
@@ -125,8 +118,19 @@ public class RegionGen extends InsnGen {
IContainer
els
=
region
.
getElseRegion
();
if
(
els
!=
null
&&
RegionUtils
.
notEmpty
(
els
))
{
code
.
add
(
" else "
);
if
(
connectElseIf
(
code
,
els
))
{
return
;
}
code
.
add
(
'{'
);
makeRegionIndent
(
code
,
els
);
code
.
startLine
(
'}'
);
}
}
// connect if-else-if block
/**
* Connect if-else-if block
*/
private
boolean
connectElseIf
(
CodeWriter
code
,
IContainer
els
)
throws
CodegenException
{
if
(
els
instanceof
Region
)
{
Region
re
=
(
Region
)
els
;
List
<
IContainer
>
subBlocks
=
re
.
getSubBlocks
();
...
...
@@ -134,15 +138,11 @@ public class RegionGen extends InsnGen {
IfRegion
ifRegion
=
(
IfRegion
)
subBlocks
.
get
(
0
);
if
(
ifRegion
.
getAttributes
().
contains
(
AttributeFlag
.
ELSE_IF_CHAIN
))
{
makeIf
(
ifRegion
,
code
,
false
);
return
;
}
return
true
;
}
}
code
.
add
(
'{'
);
makeRegionIndent
(
code
,
els
);
code
.
startLine
(
'}'
);
}
return
false
;
}
private
CodeWriter
makeLoop
(
LoopRegion
region
,
CodeWriter
code
)
throws
CodegenException
{
...
...
@@ -152,7 +152,8 @@ public class RegionGen extends InsnGen {
if
(
headerInsns
.
size
()
>
1
)
{
// write not inlined instructions from header
mth
.
getAttributes
().
add
(
AttributeFlag
.
INCONSISTENT_CODE
);
for
(
int
i
=
0
;
i
<
headerInsns
.
size
()
-
1
;
i
++)
{
int
last
=
headerInsns
.
size
()
-
1
;
for
(
int
i
=
0
;
i
<
last
;
i
++)
{
InsnNode
insn
=
headerInsns
.
get
(
i
);
makeInsn
(
insn
,
code
);
}
...
...
@@ -187,75 +188,6 @@ public class RegionGen extends InsnGen {
code
.
startLine
(
'}'
);
}
private
String
makeCondition
(
IfCondition
condition
)
throws
CodegenException
{
switch
(
condition
.
getMode
())
{
case
COMPARE:
return
makeCompare
(
condition
.
getCompare
());
case
NOT:
return
"!"
+
makeCondition
(
condition
.
getArgs
().
get
(
0
));
case
AND:
case
OR:
String
mode
=
condition
.
getMode
()
==
IfCondition
.
Mode
.
AND
?
" && "
:
" || "
;
StringBuilder
sb
=
new
StringBuilder
();
for
(
IfCondition
arg
:
condition
.
getArgs
())
{
if
(
sb
.
length
()
!=
0
)
{
sb
.
append
(
mode
);
}
String
s
=
makeCondition
(
arg
);
if
(
arg
.
isCompare
())
{
sb
.
append
(
s
);
}
else
{
sb
.
append
(
'('
).
append
(
s
).
append
(
')'
);
}
}
return
sb
.
toString
();
default
:
return
"??"
+
condition
.
toString
();
}
}
private
String
makeCompare
(
Compare
compare
)
throws
CodegenException
{
IfOp
op
=
compare
.
getOp
();
InsnArg
firstArg
=
compare
.
getA
();
InsnArg
secondArg
=
compare
.
getB
();
if
(
firstArg
.
getType
().
equals
(
ArgType
.
BOOLEAN
)
&&
secondArg
.
isLiteral
()
&&
secondArg
.
getType
().
equals
(
ArgType
.
BOOLEAN
))
{
LiteralArg
lit
=
(
LiteralArg
)
secondArg
;
if
(
lit
.
getLiteral
()
==
0
)
{
op
=
op
.
invert
();
}
if
(
op
==
IfOp
.
EQ
)
{
return
arg
(
firstArg
,
false
).
toString
();
// == true
}
else
if
(
op
==
IfOp
.
NE
)
{
return
"!"
+
arg
(
firstArg
);
// != true
}
LOG
.
warn
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
"Unsupported boolean condition "
+
op
.
getSymbol
()));
}
return
arg
(
firstArg
,
isWrapNeeded
(
firstArg
))
+
" "
+
op
.
getSymbol
()
+
" "
+
arg
(
secondArg
,
isWrapNeeded
(
secondArg
));
}
private
boolean
isWrapNeeded
(
InsnArg
arg
)
{
if
(!
arg
.
isInsnWrap
())
{
return
false
;
}
InsnNode
insn
=
((
InsnWrapArg
)
arg
).
getWrapInsn
();
if
(
insn
.
getType
()
==
InsnType
.
ARITH
)
{
ArithNode
arith
=
((
ArithNode
)
insn
);
switch
(
arith
.
getOp
())
{
case
ADD:
case
SUB:
case
MUL:
case
DIV:
case
REM:
return
false
;
}
}
return
true
;
}
private
CodeWriter
makeSwitch
(
SwitchRegion
sw
,
CodeWriter
code
)
throws
CodegenException
{
SwitchNode
insn
=
(
SwitchNode
)
sw
.
getHeader
().
getInstructions
().
get
(
0
);
InsnArg
arg
=
insn
.
getArg
(
0
);
...
...
@@ -324,7 +256,7 @@ public class RegionGen extends InsnGen {
private
void
makeCatchBlock
(
CodeWriter
code
,
ExceptionHandler
handler
)
throws
CodegenException
{
IContainer
region
=
handler
.
getHandlerRegion
();
if
(
region
!=
null
/* && RegionUtils.notEmpty(region) */
)
{
if
(
region
!=
null
)
{
code
.
startLine
(
"} catch ("
);
code
.
add
(
handler
.
isCatchAll
()
?
"Throwable"
:
useClass
(
handler
.
getCatchType
()));
code
.
add
(
' '
);
...
...
jadx-core/src/main/java/jadx/core/deobf/NameMapper.java
View file @
3c84975a
...
...
@@ -61,7 +61,8 @@ public class NameMapper {
"void"
,
"volatile"
,
"while"
,
}));
})
);
public
static
boolean
isReserved
(
String
str
)
{
return
RESERVED_NAMES
.
contains
(
str
);
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/AttributeFlag.java
View file @
3c84975a
...
...
@@ -12,6 +12,8 @@ public enum AttributeFlag {
BREAK
,
RETURN
,
// block contains only return instruction
DECLARE_VAR
,
DONT_SHRINK
,
DONT_GENERATE
,
SKIP
,
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/AttributeType.java
View file @
3c84975a
...
...
@@ -27,7 +27,8 @@ public enum AttributeType {
SOURCE_FILE
(
true
),
DECLARE_VARIABLE
(
true
);
// for regions
DECLARE_VARIABLES
(
true
);
private
static
final
int
NOT_UNIQ_COUNT
;
private
final
boolean
uniq
;
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/BlockRegState.java
View file @
3c84975a
...
...
@@ -48,7 +48,7 @@ public final class BlockRegState {
if
(
str
.
length
()
!=
0
)
{
str
.
append
(
", "
);
}
str
.
append
(
reg
.
toString
()
);
str
.
append
(
reg
);
}
}
return
str
.
toString
();
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/DeclareVariableAttr.java
→
jadx-core/src/main/java/jadx/core/dex/attributes/DeclareVariable
s
Attr.java
View file @
3c84975a
...
...
@@ -3,37 +3,27 @@ package jadx.core.dex.attributes;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.utils.Utils
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
DeclareVariableAttr
implements
IAttribute
{
/**
* List of variables to be declared at region start.
*/
public
class
DeclareVariablesAttr
implements
IAttribute
{
private
final
List
<
RegisterArg
>
vars
;
private
final
List
<
RegisterArg
>
vars
=
new
LinkedList
<
RegisterArg
>()
;
public
DeclareVariableAttr
()
{
this
.
vars
=
null
;
// for instruction use result
}
public
DeclareVariableAttr
(
List
<
RegisterArg
>
vars
)
{
this
.
vars
=
vars
;
// for regions
}
public
List
<
RegisterArg
>
getVars
()
{
public
Iterable
<
RegisterArg
>
getVars
()
{
return
vars
;
}
public
void
addVar
(
RegisterArg
arg
)
{
int
i
;
if
((
i
=
vars
.
indexOf
(
arg
))
!=
-
1
)
{
if
(
vars
.
get
(
i
).
getType
().
equals
(
arg
.
getType
()))
{
return
;
}
}
vars
.
add
(
arg
);
}
@Override
public
AttributeType
getType
()
{
return
AttributeType
.
DECLARE_VARIABLE
;
return
AttributeType
.
DECLARE_VARIABLE
S
;
}
@Override
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/JadxErrorAttr.java
View file @
3c84975a
...
...
@@ -26,7 +26,7 @@ public class JadxErrorAttr implements IAttribute {
if
(
cause
==
null
)
{
str
.
append
(
"null"
);
}
else
{
str
.
append
(
cause
.
getClass
()
.
toString
()
);
str
.
append
(
cause
.
getClass
());
str
.
append
(
":"
);
str
.
append
(
cause
.
getMessage
());
str
.
append
(
"\n"
);
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/JumpAttribute.java
View file @
3c84975a
...
...
@@ -32,11 +32,7 @@ public class JumpAttribute implements IAttribute {
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
dest
;
result
=
prime
*
result
+
src
;
return
result
;
return
31
*
dest
+
src
;
}
@Override
...
...
jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
View file @
3c84975a
...
...
@@ -58,37 +58,37 @@ public final class ClassInfo {
String
fullObjectName
=
type
.
getObject
();
assert
fullObjectName
.
indexOf
(
'/'
)
==
-
1
:
"Raw type: "
+
type
;
String
n
ame
;
String
clsN
ame
;
int
dot
=
fullObjectName
.
lastIndexOf
(
'.'
);
if
(
dot
==
-
1
)
{
// rename default package if it used from class with package (often for obfuscated apps),
pkg
=
Consts
.
DEFAULT_PACKAGE_NAME
;
n
ame
=
fullObjectName
;
clsN
ame
=
fullObjectName
;
}
else
{
pkg
=
fullObjectName
.
substring
(
0
,
dot
);
n
ame
=
fullObjectName
.
substring
(
dot
+
1
);
clsN
ame
=
fullObjectName
.
substring
(
dot
+
1
);
}
int
sep
=
n
ame
.
lastIndexOf
(
'$'
);
if
(
canBeInner
&&
sep
>
0
&&
sep
!=
n
ame
.
length
()
-
1
)
{
String
parClsName
=
pkg
+
'.'
+
n
ame
.
substring
(
0
,
sep
);
int
sep
=
clsN
ame
.
lastIndexOf
(
'$'
);
if
(
canBeInner
&&
sep
>
0
&&
sep
!=
clsN
ame
.
length
()
-
1
)
{
String
parClsName
=
pkg
+
'.'
+
clsN
ame
.
substring
(
0
,
sep
);
parentClass
=
fromName
(
parClsName
);
name
=
n
ame
.
substring
(
sep
+
1
);
clsName
=
clsN
ame
.
substring
(
sep
+
1
);
}
else
{
parentClass
=
null
;
}
char
firstChar
=
n
ame
.
charAt
(
0
);
char
firstChar
=
clsN
ame
.
charAt
(
0
);
if
(
Character
.
isDigit
(
firstChar
))
{
name
=
Consts
.
ANONYMOUS_CLASS_PREFIX
+
n
ame
;
clsName
=
Consts
.
ANONYMOUS_CLASS_PREFIX
+
clsN
ame
;
}
else
if
(
firstChar
==
'$'
)
{
name
=
"_"
+
n
ame
;
clsName
=
"_"
+
clsN
ame
;
}
if
(
NameMapper
.
isReserved
(
n
ame
))
{
n
ame
+=
"_"
;
if
(
NameMapper
.
isReserved
(
clsN
ame
))
{
clsN
ame
+=
"_"
;
}
this
.
fullName
=
(
parentClass
!=
null
?
parentClass
.
getFullName
()
:
pkg
)
+
"."
+
n
ame
;
this
.
name
=
n
ame
;
this
.
fullName
=
(
parentClass
!=
null
?
parentClass
.
getFullName
()
:
pkg
)
+
"."
+
clsN
ame
;
this
.
name
=
clsN
ame
;
}
public
String
getFullPath
()
{
...
...
jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java
View file @
3c84975a
...
...
@@ -88,11 +88,9 @@ public final class MethodInfo {
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
declClass
.
hashCode
();
result
=
prime
*
result
+
retType
.
hashCode
();
result
=
prime
*
result
+
shortId
.
hashCode
();
int
result
=
declClass
.
hashCode
();
result
=
31
*
result
+
retType
.
hashCode
();
result
=
31
*
result
+
shortId
.
hashCode
();
return
result
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java
View file @
3c84975a
...
...
@@ -229,7 +229,7 @@ public abstract class ArgType {
@Override
public
String
toString
()
{
return
arrayElement
.
toString
()
+
"[]"
;
return
arrayElement
+
"[]"
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/RegisterArg.java
View file @
3c84975a
...
...
@@ -88,7 +88,7 @@ public class RegisterArg extends InsnArg {
public
boolean
isThis
()
{
if
(
isRegister
())
{
String
name
=
getTypedVar
().
getName
();
if
(
name
!=
null
&&
name
.
equals
(
"this"
))
{
if
(
"this"
.
equals
(
name
))
{
return
true
;
}
// maybe it was moved from 'this' register
...
...
@@ -120,13 +120,7 @@ public class RegisterArg extends InsnArg {
return
false
;
}
RegisterArg
other
=
(
RegisterArg
)
obj
;
if
(
regNum
!=
other
.
regNum
)
{
return
false
;
}
if
(!
typedVar
.
equals
(
other
.
typedVar
))
{
return
false
;
}
return
true
;
return
regNum
==
other
.
regNum
&&
typedVar
.
equals
(
other
.
typedVar
);
}
@Override
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/TypedVar.java
View file @
3c84975a
...
...
@@ -51,9 +51,9 @@ public class TypedVar {
}
public
void
mergeName
(
TypedVar
arg
)
{
String
n
ame
=
arg
.
getName
();
if
(
n
ame
!=
null
)
{
setName
(
n
ame
);
String
argN
ame
=
arg
.
getName
();
if
(
argN
ame
!=
null
)
{
setName
(
argN
ame
);
}
else
if
(
getName
()
!=
null
)
{
arg
.
setName
(
getName
());
}
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
View file @
3c84975a
...
...
@@ -124,7 +124,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
int
offset
=
cls
.
getAnnotationsOffset
();
if
(
offset
!=
0
)
{
try
{
new
AnnotationsParser
(
this
,
offset
);
new
AnnotationsParser
(
this
).
parse
(
offset
);
}
catch
(
DecodeException
e
)
{
LOG
.
error
(
"Error parsing annotations in "
+
this
,
e
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java
View file @
3c84975a
...
...
@@ -91,13 +91,11 @@ public class InsnNode extends LineAttrNode {
InsnArg
arg
=
arguments
.
get
(
i
);
if
(
arg
==
from
)
{
// TODO correct remove from use list
// from.getTypedVar().getUseList().remove(from);
setArg
(
i
,
to
);
return
true
;
}
else
if
(
arg
.
isInsnWrap
())
{
if
(((
InsnWrapArg
)
arg
).
getWrapInsn
().
replaceArg
(
from
,
to
))
{
return
true
;
}
if
(
arg
.
isInsnWrap
()
&&
((
InsnWrapArg
)
arg
).
getWrapInsn
().
replaceArg
(
from
,
to
))
{
return
true
;
}
}
return
false
;
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
View file @
3c84975a
...
...
@@ -47,7 +47,7 @@ public class RootNode {
initInnerClasses
(
classes
);
}
private
void
initClassPath
(
List
<
ClassNode
>
classes
)
throws
IOException
,
DecodeException
{
private
static
void
initClassPath
(
List
<
ClassNode
>
classes
)
throws
IOException
,
DecodeException
{
ClspGraph
clsp
=
new
ClspGraph
();
clsp
.
load
();
clsp
.
addApp
(
classes
);
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/parser/AnnotationsParser.java
View file @
3c84975a
...
...
@@ -4,6 +4,7 @@ import jadx.core.dex.attributes.annotations.Annotation;
import
jadx.core.dex.attributes.annotations.Annotation.Visibility
;
import
jadx.core.dex.attributes.annotations.AnnotationsList
;
import
jadx.core.dex.attributes.annotations.MethodParameters
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.DexNode
;
import
jadx.core.dex.nodes.FieldNode
;
...
...
@@ -20,9 +21,14 @@ import com.android.dx.io.DexBuffer.Section;
public
class
AnnotationsParser
{
private
final
DexNode
dex
;
private
final
ClassNode
cls
;
public
AnnotationsParser
(
ClassNode
cls
,
int
offset
)
throws
DecodeException
{
public
AnnotationsParser
(
ClassNode
cls
)
{
this
.
cls
=
cls
;
this
.
dex
=
cls
.
dex
();
}
public
void
parse
(
int
offset
)
throws
DecodeException
{
Section
section
=
dex
.
openSection
(
offset
);
// TODO read as unsigned int
...
...
@@ -70,10 +76,10 @@ public class AnnotationsParser {
return
new
AnnotationsList
(
list
);
}
private
static
final
Annotation
.
Visibility
[]
VISIBILITIES
=
new
Annotation
.
Visibility
[]
{
Annotation
.
Visibility
.
BUILD
,
Annotation
.
Visibility
.
RUNTIME
,
Annotation
.
Visibility
.
SYSTEM
private
static
final
Annotation
.
Visibility
[]
VISIBILITIES
=
{
Visibility
.
BUILD
,
Visibility
.
RUNTIME
,
Visibility
.
SYSTEM
};
public
static
Annotation
readAnnotation
(
DexNode
dex
,
Section
s
,
boolean
readVisibility
)
throws
DecodeException
{
...
...
@@ -89,6 +95,11 @@ public class AnnotationsParser {
String
name
=
dex
.
getString
(
s
.
readUleb128
());
values
.
put
(
name
,
parser
.
parseValue
());
}
return
new
Annotation
(
visibility
,
dex
.
getType
(
typeIndex
),
values
);
ArgType
type
=
dex
.
getType
(
typeIndex
);
Annotation
annotation
=
new
Annotation
(
visibility
,
type
,
values
);
if
(!
type
.
isObject
())
{
throw
new
DecodeException
(
"Incorrect type for annotation: "
+
annotation
);
}
return
annotation
;
}
}
jadx-core/src/main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java
View file @
3c84975a
...
...
@@ -25,9 +25,12 @@ public class DebugInfoParser {
private
static
final
int
DBG_SET_EPILOGUE_BEGIN
=
0x08
;
private
static
final
int
DBG_SET_FILE
=
0x09
;
private
static
final
int
DBG_FIRST_SPECIAL
=
0x0a
;
// the smallest special opcode
private
static
final
int
DBG_LINE_BASE
=
-
4
;
// the smallest line number increment
private
static
final
int
DBG_LINE_RANGE
=
15
;
// the number of line increments represented
// the smallest special opcode
private
static
final
int
DBG_FIRST_SPECIAL
=
0x0a
;
// the smallest line number increment
private
static
final
int
DBG_LINE_BASE
=
-
4
;
// the number of line increments represented
private
static
final
int
DBG_LINE_RANGE
=
15
;
private
final
MethodNode
mth
;
private
final
Section
section
;
...
...
@@ -42,8 +45,9 @@ public class DebugInfoParser {
this
.
dex
=
mth
.
dex
();
this
.
section
=
dex
.
openSection
(
debugOffset
);
this
.
locals
=
new
LocalVar
[
mth
.
getRegsCount
()];
this
.
activeRegisters
=
new
InsnArg
[
mth
.
getRegsCount
()];
int
regsCount
=
mth
.
getRegsCount
();
this
.
locals
=
new
LocalVar
[
regsCount
];
this
.
activeRegisters
=
new
InsnArg
[
regsCount
];
this
.
insnByOffset
=
insnByOffset
;
}
...
...
@@ -51,7 +55,7 @@ public class DebugInfoParser {
int
addr
=
0
;
int
line
=
section
.
readUleb128
();
int
paramsCount
=
section
.
readUleb128
();
// exclude 'this'
int
paramsCount
=
section
.
readUleb128
();
List
<
RegisterArg
>
mthArgs
=
mth
.
getArguments
(
false
);
assert
paramsCount
==
mthArgs
.
size
();
...
...
@@ -69,7 +73,8 @@ public class DebugInfoParser {
activeRegisters
[
rn
]
=
arg
;
}
addrChange
(-
1
,
1
,
line
);
// process '0' instruction
// process '0' instruction
addrChange
(-
1
,
1
,
line
);
int
c
=
section
.
readByte
()
&
0xFF
;
while
(
c
!=
DBG_END_SEQUENCE
)
{
...
...
@@ -139,7 +144,7 @@ public class DebugInfoParser {
if
(
c
>=
DBG_FIRST_SPECIAL
)
{
int
adjustedOpcode
=
c
-
DBG_FIRST_SPECIAL
;
line
+=
DBG_LINE_BASE
+
(
adjustedOpcode
%
DBG_LINE_RANGE
);
int
addrInc
=
(
adjustedOpcode
/
DBG_LINE_RANGE
)
;
int
addrInc
=
adjustedOpcode
/
DBG_LINE_RANGE
;
addr
=
addrChange
(
addr
,
addrInc
,
line
);
}
else
{
throw
new
DecodeException
(
"Unknown debug insn code: "
+
c
);
...
...
@@ -213,10 +218,10 @@ public class DebugInfoParser {
}
private
static
void
merge
(
InsnArg
arg
,
LocalVar
var
)
{
if
(
arg
!=
null
&&
arg
.
isRegister
())
{
if
(
var
.
getRegNum
()
==
((
RegisterArg
)
arg
).
getRegNum
())
{
if
(
arg
!=
null
&&
arg
.
isRegister
()
&&
var
.
getRegNum
()
==
((
RegisterArg
)
arg
).
getRegNum
())
{
arg
.
mergeDebugInfo
(
var
);
}
}
}
}
jadx-core/src/main/java/jadx/core/dex/regions/LoopRegion.java
View file @
3c84975a
...
...
@@ -15,9 +15,9 @@ public final class LoopRegion extends AbstractRegion {
// loop header contains one 'if' insn, equals null for infinite loop
private
IfCondition
condition
;
private
BlockNode
conditionBlock
;
private
final
BlockNode
conditionBlock
;
// instruction which must be executed before condition in every loop
private
BlockNode
preCondition
=
null
;
private
BlockNode
preCondition
;
private
IContainer
body
;
private
final
boolean
conditionAtEnd
;
...
...
jadx-core/src/main/java/jadx/core/dex/regions/TernaryRegion.java
View file @
3c84975a
...
...
@@ -9,7 +9,7 @@ import java.util.Collections;
import
java.util.List
;
public
final
class
TernaryRegion
extends
AbstractRegion
{
private
IBlock
container
;
private
final
IBlock
container
;
public
TernaryRegion
(
IRegion
parent
,
BlockNode
block
)
{
super
(
parent
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java
View file @
3c84975a
...
...
@@ -17,10 +17,12 @@ import jadx.core.dex.nodes.MethodNode;
import
jadx.core.dex.trycatch.CatchAttr
;
import
jadx.core.dex.trycatch.ExceptionHandler
;
import
jadx.core.dex.trycatch.SplitterBlockAttr
;
import
jadx.core.utils.BlockUtils
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
import
java.util.ArrayList
;
import
java.util.BitSet
;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.HashMap
;
import
java.util.Iterator
;
...
...
@@ -223,7 +225,7 @@ public class BlockMakerVisitor extends AbstractVisitor {
}
private
static
void
computeDominators
(
MethodNode
mth
)
{
List
<
BlockNode
>
basicBlocks
=
mth
.
getBasicBlocks
(
);
List
<
BlockNode
>
basicBlocks
=
Collections
.
unmodifiableList
(
mth
.
getBasicBlocks
()
);
int
nBlocks
=
basicBlocks
.
size
();
for
(
int
i
=
0
;
i
<
nBlocks
;
i
++)
{
BlockNode
block
=
basicBlocks
.
get
(
i
);
...
...
@@ -245,13 +247,15 @@ public class BlockMakerVisitor extends AbstractVisitor {
continue
;
}
BitSet
d
=
block
.
getDoms
();
if
(!
changed
)
{
dset
.
clear
();
dset
.
or
(
d
);
}
for
(
BlockNode
pred
:
block
.
getPredecessors
())
{
d
.
and
(
pred
.
getDoms
());
}
d
.
set
(
block
.
getId
());
if
(!
d
.
equals
(
dset
))
{
if
(!
changed
&&
!
d
.
equals
(
dset
))
{
changed
=
true
;
}
}
...
...
@@ -315,15 +319,12 @@ public class BlockMakerVisitor extends AbstractVisitor {
private
static
void
markReturnBlocks
(
MethodNode
mth
)
{
mth
.
getExitBlocks
().
clear
();
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
List
<
InsnNode
>
insns
=
block
.
getInstructions
();
if
(
insns
.
size
()
==
1
)
{
if
(
insns
.
get
(
0
).
getType
()
==
InsnType
.
RETURN
)
{
if
(
BlockUtils
.
lastInsnType
(
block
,
InsnType
.
RETURN
))
{
block
.
getAttributes
().
add
(
AttributeFlag
.
RETURN
);
mth
.
getExitBlocks
().
add
(
block
);
}
}
}
}
private
static
void
registerLoops
(
MethodNode
mth
)
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
View file @
3c84975a
...
...
@@ -111,12 +111,10 @@ public class ClassModifier extends AbstractVisitor {
AccessInfo
af
=
mth
.
getAccessFlags
();
// remove bridge methods
if
(
af
.
isBridge
()
&&
af
.
isSynthetic
())
{
if
(!
isMethodUniq
(
cls
,
mth
))
{
if
(
af
.
isBridge
()
&&
af
.
isSynthetic
()
&&
!
isMethodUniq
(
cls
,
mth
))
{
// TODO add more checks before method deletion
it
.
remove
();
}
}
// remove synthetic constructor for inner non-static classes
if
(
af
.
isSynthetic
()
&&
af
.
isConstructor
()
&&
mth
.
getBasicBlocks
().
size
()
==
2
)
{
...
...
@@ -135,11 +133,11 @@ public class ClassModifier extends AbstractVisitor {
private
static
boolean
isMethodUniq
(
ClassNode
cls
,
MethodNode
mth
)
{
MethodInfo
mi
=
mth
.
getMethodInfo
();
for
(
MethodNode
otherMth
:
cls
.
getMethods
())
{
if
(
otherMth
!=
mth
)
{
MethodInfo
omi
=
otherMth
.
getMethodInfo
();
if
(
omi
.
getName
().
equals
(
mi
.
getName
())
&&
otherMth
!=
mth
)
{
if
(
omi
.
getArgumentsTypes
().
size
()
==
mi
.
getArgumentsTypes
().
size
())
{
// TODO: check to args objects types
&&
omi
.
getArgumentsTypes
().
size
()
==
mi
.
getArgumentsTypes
().
size
())
{
// TODO: check objects types
return
false
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
View file @
3c84975a
...
...
@@ -231,11 +231,9 @@ public class CodeShrinker extends AbstractVisitor {
List
<
RegisterArg
>
args
=
ArgsInfo
.
getArgs
(
assignInsn
);
boolean
startCheck
=
false
;
for
(
InsnNode
insn
:
assignBlock
.
getInstructions
())
{
if
(
startCheck
)
{
if
(!
insn
.
canReorder
()
||
ArgsInfo
.
usedArgAssign
(
insn
,
args
))
{
if
(
startCheck
&&
(!
insn
.
canReorder
()
||
ArgsInfo
.
usedArgAssign
(
insn
,
args
)))
{
return
false
;
}
}
if
(
insn
==
assignInsn
)
{
startCheck
=
true
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
View file @
3c84975a
...
...
@@ -116,11 +116,10 @@ public class ConstInlinerVisitor extends AbstractVisitor {
break
;
case
IPUT:
case
SPUT:
{
case
SPUT:
IndexInsnNode
node
=
(
IndexInsnNode
)
insn
;
insn
.
getArg
(
0
).
merge
(((
FieldInfo
)
node
.
getIndex
()).
getType
());
break
;
}
case
IF:
{
InsnArg
arg0
=
insn
.
getArg
(
0
);
...
...
@@ -133,7 +132,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
break
;
}
case
CMP_G:
case
CMP_L:
{
case
CMP_L:
InsnArg
arg0
=
insn
.
getArg
(
0
);
InsnArg
arg1
=
insn
.
getArg
(
1
);
if
(
arg0
==
litArg
)
{
...
...
@@ -142,7 +141,6 @@ public class ConstInlinerVisitor extends AbstractVisitor {
arg1
.
merge
(
arg0
);
}
break
;
}
case
RETURN:
if
(
insn
.
getArgsCount
()
!=
0
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java
View file @
3c84975a
...
...
@@ -9,7 +9,6 @@ import jadx.core.dex.nodes.IRegion;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.trycatch.ExceptionHandler
;
import
jadx.core.utils.BlockUtils
;
import
jadx.core.utils.InsnUtils
;
import
jadx.core.utils.Utils
;
...
...
@@ -94,7 +93,7 @@ public class DotGraphVisitor extends AbstractVisitor {
IRegion
r
=
(
IRegion
)
region
;
String
attrs
=
attributesString
(
r
);
dot
.
startLine
(
"subgraph "
+
makeName
(
region
)
+
" {"
);
dot
.
startLine
(
"label = \""
+
r
.
toString
()
dot
.
startLine
(
"label = \""
+
r
+
(
attrs
.
length
()
==
0
?
""
:
" | "
+
attrs
)
+
"\";"
);
dot
.
startLine
(
"node [shape=record,color=blue];"
);
...
...
@@ -136,12 +135,6 @@ public class DotGraphVisitor extends AbstractVisitor {
for
(
BlockNode
next
:
block
.
getDominatesOn
())
{
conn
.
startLine
(
makeName
(
block
)
+
" -> "
+
makeName
(
next
)
+
"[style=dotted];"
);
}
// add all dominators connections
if
(
false
)
{
for
(
BlockNode
next
:
BlockUtils
.
bitsetToBlocks
(
mth
,
block
.
getDoms
()))
{
conn
.
startLine
(
makeName
(
block
)
+
" -> "
+
makeName
(
next
)
+
"[style=dotted, color=green];"
);
}
}
}
private
String
attributesString
(
IAttributeNode
block
)
{
...
...
@@ -152,7 +145,7 @@ public class DotGraphVisitor extends AbstractVisitor {
return
attrs
.
toString
();
}
private
String
makeName
(
IContainer
c
)
{
private
static
String
makeName
(
IContainer
c
)
{
String
name
;
if
(
c
instanceof
BlockNode
)
{
name
=
"Node_"
+
((
BlockNode
)
c
).
getId
();
...
...
@@ -166,7 +159,7 @@ public class DotGraphVisitor extends AbstractVisitor {
if
(
rawInsn
)
{
StringBuilder
str
=
new
StringBuilder
();
for
(
InsnNode
insn
:
block
.
getInstructions
())
{
str
.
append
(
escape
(
insn
.
toString
()
+
" "
+
insn
.
getAttributes
()));
str
.
append
(
escape
(
insn
+
" "
+
insn
.
getAttributes
()));
str
.
append
(
NL
);
}
return
str
.
toString
();
...
...
@@ -181,7 +174,7 @@ public class DotGraphVisitor extends AbstractVisitor {
}
}
private
String
escape
(
String
string
)
{
private
static
String
escape
(
String
string
)
{
return
string
.
replace
(
"\\"
,
""
)
// TODO replace \"
.
replace
(
"/"
,
"\\/"
)
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/MethodInline
r
Visitor.java
→
jadx-core/src/main/java/jadx/core/dex/visitors/MethodInlineVisitor.java
View file @
3c84975a
...
...
@@ -10,20 +10,23 @@ import jadx.core.dex.nodes.InsnNode;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.utils.exceptions.JadxException
;
public
class
MethodInlinerVisitor
extends
AbstractVisitor
{
/**
* Inline synthetic methods.
*/
public
class
MethodInlineVisitor
extends
AbstractVisitor
{
@Override
public
void
visit
(
MethodNode
mth
)
throws
JadxException
{
AccessInfo
accessFlags
=
mth
.
getAccessFlags
();
if
(
accessFlags
.
isSynthetic
()
&&
accessFlags
.
isStatic
())
{
if
(
mth
.
getBasicBlocks
().
size
()
==
2
)
{
if
(
accessFlags
.
isSynthetic
()
&&
accessFlags
.
isStatic
()
&&
mth
.
getBasicBlocks
().
size
()
==
2
)
{
BlockNode
block
=
mth
.
getBasicBlocks
().
get
(
1
);
if
(
block
.
getAttributes
().
contains
(
AttributeFlag
.
RETURN
))
{
inlineMth
(
mth
);
}
}
}
}
private
static
void
inlineMth
(
MethodNode
mth
)
{
BlockNode
firstBlock
=
mth
.
getBasicBlocks
().
get
(
0
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
View file @
3c84975a
...
...
@@ -51,7 +51,7 @@ public class ModVisitor extends AbstractVisitor {
}
}
private
void
replaceStep
(
MethodNode
mth
)
{
private
static
void
replaceStep
(
MethodNode
mth
)
{
ClassNode
parentClass
=
mth
.
getParentClass
();
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
InstructionRemover
remover
=
new
InstructionRemover
(
block
.
getInstructions
());
...
...
@@ -147,7 +147,7 @@ public class ModVisitor extends AbstractVisitor {
/**
* Remove unnecessary instructions
*/
private
void
removeStep
(
MethodNode
mth
)
{
private
static
void
removeStep
(
MethodNode
mth
)
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
InstructionRemover
remover
=
new
InstructionRemover
(
block
.
getInstructions
());
...
...
@@ -193,7 +193,7 @@ public class ModVisitor extends AbstractVisitor {
}
}
private
void
processExceptionHander
(
MethodNode
mth
,
BlockNode
block
)
{
private
static
void
processExceptionHander
(
MethodNode
mth
,
BlockNode
block
)
{
ExcHandlerAttr
handlerAttr
=
(
ExcHandlerAttr
)
block
.
getAttributes
().
get
(
AttributeType
.
EXC_HANDLER
);
if
(
handlerAttr
==
null
)
{
return
;
...
...
@@ -252,7 +252,7 @@ public class ModVisitor extends AbstractVisitor {
block
.
getInstructions
().
set
(
i
,
insn
);
}
private
void
checkArgsNames
(
MethodNode
mth
)
{
private
static
void
checkArgsNames
(
MethodNode
mth
)
{
for
(
RegisterArg
arg
:
mth
.
getArguments
(
false
))
{
String
name
=
arg
.
getTypedVar
().
getName
();
if
(
name
!=
null
&&
NameMapper
.
isReserved
(
name
))
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/CheckRegions.java
View file @
3c84975a
package
jadx
.
core
.
dex
.
visitors
.
regions
;
import
jadx.core.Consts
;
import
jadx.core.dex.attributes.AttributeFlag
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.IBlock
;
...
...
@@ -33,7 +32,6 @@ public class CheckRegions extends AbstractVisitor {
public
void
processBlock
(
MethodNode
mth
,
IBlock
container
)
{
if
(
container
instanceof
BlockNode
)
{
blocksInRegions
.
add
((
BlockNode
)
container
);
}
}
};
...
...
@@ -41,16 +39,11 @@ public class CheckRegions extends AbstractVisitor {
if
(
mth
.
getBasicBlocks
().
size
()
!=
blocksInRegions
.
size
())
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
if
(!
blocksInRegions
.
contains
(
block
)
)
{
if
(
!
block
.
getInstructions
().
isEmpty
()
if
(!
blocksInRegions
.
contains
(
block
)
&&
!
block
.
getInstructions
().
isEmpty
()
&&
!
block
.
getAttributes
().
contains
(
AttributeFlag
.
SKIP
))
{
mth
.
getAttributes
().
add
(
AttributeFlag
.
INCONSISTENT_CODE
);
if
(
Consts
.
DEBUG
)
{
LOG
.
debug
(
" Missing block: {} in {}"
,
block
,
mth
);
}
else
{
break
;
}
}
}
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessTryCatchRegions.java
View file @
3c84975a
...
...
@@ -69,11 +69,11 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
assert
bs
!=
null
;
// intersect to get dominator of dominators
List
<
BlockNode
>
domBlocks
=
BlockUtils
.
bit
s
etToBlocks
(
mth
,
bs
);
List
<
BlockNode
>
domBlocks
=
BlockUtils
.
bit
S
etToBlocks
(
mth
,
bs
);
for
(
BlockNode
block
:
domBlocks
)
{
bs
.
andNot
(
block
.
getDoms
());
}
domBlocks
=
BlockUtils
.
bit
s
etToBlocks
(
mth
,
bs
);
domBlocks
=
BlockUtils
.
bit
S
etToBlocks
(
mth
,
bs
);
if
(
domBlocks
.
size
()
!=
1
)
{
throw
new
JadxRuntimeException
(
"Exception block dominator not found, method:"
+
mth
+
". bs: "
+
bs
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessVariables.java
View file @
3c84975a
package
jadx
.
core
.
dex
.
visitors
.
regions
;
import
jadx.core.dex.attributes.AttributeFlag
;
import
jadx.core.dex.attributes.AttributeType
;
import
jadx.core.dex.attributes.DeclareVariableAttr
;
import
jadx.core.dex.attributes.DeclareVariable
s
Attr
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.nodes.IBlock
;
import
jadx.core.dex.nodes.IContainer
;
...
...
@@ -125,7 +126,7 @@ public class ProcessVariables extends AbstractVisitor {
for
(
IRegion
assignRegion
:
u
.
getAssigns
())
{
if
(
u
.
getArgRegion
()
==
assignRegion
&&
canDeclareInRegion
(
u
,
assignRegion
))
{
u
.
getArg
().
getParentInsn
().
getAttributes
().
add
(
new
DeclareVariableAttr
()
);
u
.
getArg
().
getParentInsn
().
getAttributes
().
add
(
AttributeFlag
.
DECLARE_VAR
);
it
.
remove
();
break
;
}
...
...
@@ -167,17 +168,16 @@ public class ProcessVariables extends AbstractVisitor {
}
}
private
void
declareVar
(
IContainer
region
,
RegisterArg
arg
)
{
DeclareVariableAttr
dv
=
(
DeclareVariableAttr
)
region
.
getAttributes
().
get
(
AttributeType
.
DECLARE_VARIABLE
);
private
static
void
declareVar
(
IContainer
region
,
RegisterArg
arg
)
{
DeclareVariablesAttr
dv
=
(
DeclareVariablesAttr
)
region
.
getAttributes
().
get
(
AttributeType
.
DECLARE_VARIABLES
);
if
(
dv
==
null
)
{
dv
=
new
DeclareVariable
Attr
(
new
ArrayList
<
RegisterArg
>()
);
dv
=
new
DeclareVariable
sAttr
(
);
region
.
getAttributes
().
add
(
dv
);
}
dv
.
addVar
(
arg
);
}
private
boolean
canDeclareInRegion
(
Usage
u
,
IRegion
region
)
{
private
static
boolean
canDeclareInRegion
(
Usage
u
,
IRegion
region
)
{
for
(
IRegion
r
:
u
.
getAssigns
())
{
if
(!
RegionUtils
.
isRegionContainsRegion
(
region
,
r
))
{
return
false
;
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
View file @
3c84975a
...
...
@@ -350,7 +350,7 @@ public class RegionMaker {
/**
* Traverse from monitor-enter thru successors and collect blocks contains monitor-exit
*/
private
void
traverseMonitorExits
(
InsnArg
arg
,
BlockNode
block
,
Set
<
BlockNode
>
exits
,
Set
<
BlockNode
>
visited
)
{
private
static
void
traverseMonitorExits
(
InsnArg
arg
,
BlockNode
block
,
Set
<
BlockNode
>
exits
,
Set
<
BlockNode
>
visited
)
{
visited
.
add
(
block
);
for
(
InsnNode
insn
:
block
.
getInstructions
())
{
if
(
insn
.
getType
()
==
InsnType
.
MONITOR_EXIT
...
...
@@ -370,7 +370,7 @@ public class RegionMaker {
/**
* Traverse from monitor-enter thru successors and search for exit paths cross
*/
private
BlockNode
traverseMonitorExitsCross
(
BlockNode
block
,
Set
<
BlockNode
>
exits
,
Set
<
BlockNode
>
visited
)
{
private
static
BlockNode
traverseMonitorExitsCross
(
BlockNode
block
,
Set
<
BlockNode
>
exits
,
Set
<
BlockNode
>
visited
)
{
visited
.
add
(
block
);
for
(
BlockNode
node
:
block
.
getCleanSuccessors
())
{
boolean
cross
=
true
;
...
...
@@ -543,7 +543,7 @@ public class RegionMaker {
return
result
;
}
private
BlockNode
getIfNode
(
BlockNode
block
)
{
private
static
BlockNode
getIfNode
(
BlockNode
block
)
{
if
(
block
!=
null
&&
!
block
.
getAttributes
().
contains
(
AttributeType
.
LOOP
))
{
List
<
InsnNode
>
insns
=
block
.
getInstructions
();
if
(
insns
.
size
()
==
1
&&
insns
.
get
(
0
).
getType
()
==
InsnType
.
IF
)
{
...
...
@@ -603,7 +603,7 @@ public class RegionMaker {
Map
<
BlockNode
,
List
<
Object
>>
blocksMap
=
new
LinkedHashMap
<
BlockNode
,
List
<
Object
>>(
len
);
for
(
Entry
<
Integer
,
List
<
Object
>>
entry
:
casesMap
.
entrySet
())
{
BlockNode
c
=
getBlockByOffset
(
(
int
)
entry
.
getKey
(),
block
.
getSuccessors
());
BlockNode
c
=
getBlockByOffset
(
entry
.
getKey
(),
block
.
getSuccessors
());
assert
c
!=
null
;
blocksMap
.
put
(
c
,
entry
.
getValue
());
}
...
...
@@ -648,7 +648,7 @@ public class RegionMaker {
if
(
out
!=
null
)
{
stack
.
addExit
(
out
);
}
else
{
for
(
BlockNode
e
:
BlockUtils
.
bit
s
etToBlocks
(
mth
,
domsOn
))
{
for
(
BlockNode
e
:
BlockUtils
.
bit
S
etToBlocks
(
mth
,
domsOn
))
{
stack
.
addExit
(
e
);
}
}
...
...
@@ -689,7 +689,7 @@ public class RegionMaker {
handler
.
getHandlerRegion
().
getAttributes
().
add
(
excHandlerAttr
);
}
private
boolean
isEqualReturns
(
BlockNode
b1
,
BlockNode
b2
)
{
private
static
boolean
isEqualReturns
(
BlockNode
b1
,
BlockNode
b2
)
{
if
(
b1
==
b2
)
{
return
true
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/TracedRegionVisitor.java
View file @
3c84975a
...
...
@@ -18,7 +18,7 @@ public abstract class TracedRegionVisitor implements IRegionVisitor {
@Override
public
void
processBlock
(
MethodNode
mth
,
IBlock
container
)
{
final
IRegion
curRegion
=
regionStack
.
peek
();
IRegion
curRegion
=
regionStack
.
peek
();
processBlockTraced
(
mth
,
container
,
curRegion
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/TypeResolver.java
View file @
3c84975a
...
...
@@ -2,6 +2,7 @@ package jadx.core.dex.visitors.typeresolver;
import
jadx.core.dex.attributes.BlockRegState
;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
...
...
@@ -34,20 +35,18 @@ public class TypeResolver extends AbstractVisitor {
/**
* Check argument types (can be broken after merging debug info)
*/
private
void
prepare
(
MethodNode
mth
)
{
private
static
void
prepare
(
MethodNode
mth
)
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
for
(
InsnNode
insn
:
block
.
getInstructions
())
{
switch
(
insn
.
getType
())
{
case
CHECK_CAST:
if
(
insn
.
getType
()
==
InsnType
.
CHECK_CAST
)
{
ArgType
castType
=
(
ArgType
)
((
IndexInsnNode
)
insn
).
getIndex
();
insn
.
getResult
().
getTypedVar
().
forceSetType
(
castType
);
break
;
}
}
}
}
private
void
visitBlocks
(
MethodNode
mth
)
{
private
static
void
visitBlocks
(
MethodNode
mth
)
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
BlockRegState
state
=
new
BlockRegState
(
mth
);
...
...
@@ -94,7 +93,7 @@ public class TypeResolver extends AbstractVisitor {
}
}
private
boolean
connectEdges
(
MethodNode
mth
,
BlockNode
from
,
BlockNode
to
,
boolean
back
)
{
private
static
boolean
connectEdges
(
MethodNode
mth
,
BlockNode
from
,
BlockNode
to
,
boolean
back
)
{
BlockRegState
end
=
from
.
getEndState
();
BlockRegState
start
=
to
.
getStartState
();
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/CheckTypeVisitor.java
View file @
3c84975a
...
...
@@ -8,12 +8,11 @@ import jadx.core.utils.ErrorsCounter;
public
class
CheckTypeVisitor
{
public
static
void
visit
(
MethodNode
mth
,
InsnNode
insn
)
{
if
(
insn
.
getResult
()
!=
null
)
{
if
(
!
insn
.
getResult
().
getType
().
isTypeKnown
())
{
if
(
insn
.
getResult
()
!=
null
&&
!
insn
.
getResult
().
getType
().
isTypeKnown
())
{
error
(
"Wrong return type"
,
mth
,
insn
);
return
;
}
}
for
(
InsnArg
arg
:
insn
.
getArguments
())
{
if
(!
arg
.
getType
().
isTypeKnown
())
{
...
...
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
View file @
3c84975a
...
...
@@ -51,6 +51,9 @@ public class BlockUtils {
}
public
static
boolean
isBackEdge
(
BlockNode
from
,
BlockNode
to
)
{
if
(
to
==
null
)
{
return
false
;
}
if
(
from
.
getCleanSuccessors
().
contains
(
to
))
{
return
false
;
// already checked
}
...
...
@@ -69,16 +72,6 @@ public class BlockUtils {
}
}
public
static
BlockNode
canMergeNextBlock
(
BlockNode
block
)
{
BlockNode
next
=
getNextBlock
(
block
);
if
(
next
!=
null
)
{
if
(
next
.
getIDom
()
==
block
)
{
return
next
;
}
}
return
null
;
}
/**
* Check if instruction contains in block (use == for comparison, not equals)
*/
...
...
@@ -118,7 +111,7 @@ public class BlockUtils {
return
bs
;
}
public
static
List
<
BlockNode
>
bit
s
etToBlocks
(
MethodNode
mth
,
BitSet
bs
)
{
public
static
List
<
BlockNode
>
bit
S
etToBlocks
(
MethodNode
mth
,
BitSet
bs
)
{
List
<
BlockNode
>
blocks
=
new
ArrayList
<
BlockNode
>(
bs
.
cardinality
());
for
(
int
i
=
bs
.
nextSetBit
(
0
);
i
>=
0
;
i
=
bs
.
nextSetBit
(
i
+
1
))
{
BlockNode
block
=
mth
.
getBasicBlocks
().
get
(
i
);
...
...
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
View file @
3c84975a
...
...
@@ -16,7 +16,7 @@ public class ErrorsCounter {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ErrorsCounter
.
class
);
private
static
final
Set
<
Object
>
ERROR_NODES
=
new
HashSet
<
Object
>();
private
static
int
errorsCount
=
0
;
private
static
int
errorsCount
;
public
static
int
getErrorCount
()
{
return
errorsCount
;
...
...
jadx-core/src/main/java/jadx/core/utils/InsnUtils.java
View file @
3c84975a
...
...
@@ -46,7 +46,7 @@ public class InsnUtils {
if
(
index
instanceof
String
)
{
return
"\""
+
index
+
"\""
;
}
else
{
return
" "
+
index
.
toString
()
;
return
" "
+
index
;
}
}
}
jadx-core/src/main/java/jadx/core/utils/RegionUtils.java
View file @
3c84975a
...
...
@@ -77,7 +77,6 @@ public class RegionUtils {
if
(
container
==
region
)
{
return
true
;
}
if
(
container
instanceof
IRegion
)
{
IRegion
r
=
(
IRegion
)
container
;
...
...
@@ -92,12 +91,11 @@ public class RegionUtils {
return
true
;
}
}
if
(
tb
.
getFinalBlock
()
!=
null
)
{
if
(
isRegionContainsRegion
(
tb
.
getFinalBlock
(),
region
))
{
if
(
tb
.
getFinalBlock
()
!=
null
&&
isRegionContainsRegion
(
tb
.
getFinalBlock
(),
region
))
{
return
true
;
}
}
}
if
(
isRegionContainsRegion
(
b
,
region
))
{
return
true
;
}
...
...
jadx-core/src/test/java/jadx/api/InternalJadxTest.java
View file @
3c84975a
package
jadx
.
api
;
import
jadx.core.Jadx
;
import
jadx.core.dex.attributes.AttributeFlag
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.visitors.DepthTraverser
;
...
...
@@ -19,6 +20,7 @@ import java.util.jar.JarEntry;
import
java.util.jar.JarOutputStream
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
junit
.
framework
.
Assert
.
assertFalse
;
import
static
junit
.
framework
.
Assert
.
assertNotNull
;
import
static
junit
.
framework
.
Assert
.
fail
;
...
...
@@ -65,6 +67,7 @@ public abstract class InternalJadxTest {
for
(
IDexTreeVisitor
visitor
:
passes
)
{
DepthTraverser
.
visit
(
visitor
,
cls
);
}
assertFalse
(
cls
.
getAttributes
().
contains
(
AttributeFlag
.
INCONSISTENT_CODE
));
return
cls
;
}
catch
(
Exception
e
)
{
fail
(
e
.
getMessage
());
...
...
jadx-core/src/test/java/jadx/tests/internal/inline/TestSyntheticInline.java
0 → 100644
View file @
3c84975a
package
jadx
.
tests
.
internal
.
inline
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestSyntheticInline
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
int
f
;
private
int
func
()
{
return
-
1
;
}
public
class
A
{
public
int
getF
()
{
return
f
;
}
public
void
setF
(
int
v
)
{
f
=
v
;
}
public
int
callFunc
()
{
return
func
();
}
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
not
(
containsString
(
"synthetic"
)));
assertThat
(
code
,
not
(
containsString
(
"access$"
)));
assertThat
(
code
,
not
(
containsString
(
"x0"
)));
assertThat
(
code
,
containsString
(
"return f;"
));
assertThat
(
code
,
containsString
(
"return func();"
));
assertThat
(
code
,
containsString
(
"f = v;"
));
}
}
jadx-gui/src/main/java/jadx/gui/treemodel/JClass.java
View file @
3c84975a
...
...
@@ -45,20 +45,19 @@ public class JClass extends JNode {
if
(!
loaded
)
{
cls
.
decompile
();
loaded
=
true
;
update
Childs
();
update
();
}
}
@Override
public
synchronized
void
updateChilds
()
{
public
synchronized
void
update
()
{
removeAllChildren
();
if
(!
loaded
)
{
add
(
new
TextNode
(
NLS
.
str
(
"tree.loading"
)));
}
else
{
for
(
JavaClass
javaClass
:
cls
.
getInnerClasses
())
{
JClass
child
=
new
JClass
(
javaClass
,
this
);
add
(
child
);
child
.
updateChilds
();
JClass
innerCls
=
new
JClass
(
javaClass
,
this
);
add
(
innerCls
);
innerCls
.
update
();
}
for
(
JavaField
f
:
cls
.
getFields
())
{
add
(
new
JField
(
f
,
this
));
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JField.java
View file @
3c84975a
...
...
@@ -28,10 +28,6 @@ public class JField extends JNode {
}
@Override
public
void
updateChilds
()
{
}
@Override
public
JClass
getJParent
()
{
return
jParent
;
}
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java
View file @
3c84975a
...
...
@@ -30,10 +30,6 @@ public class JMethod extends JNode {
}
@Override
public
void
updateChilds
()
{
}
@Override
public
JClass
getJParent
()
{
return
jParent
;
}
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java
View file @
3c84975a
...
...
@@ -16,7 +16,5 @@ public abstract class JNode extends DefaultMutableTreeNode {
public
abstract
int
getLine
();
public
abstract
void
updateChilds
();
public
abstract
Icon
getIcon
();
}
jadx-gui/src/main/java/jadx/gui/treemodel/JPackage.java
View file @
3c84975a
...
...
@@ -25,7 +25,7 @@ public class JPackage extends JNode implements Comparable<JPackage> {
for
(
JavaClass
javaClass
:
javaClasses
)
{
classes
.
add
(
new
JClass
(
javaClass
));
}
update
Childs
();
update
();
}
public
JPackage
(
String
name
)
{
...
...
@@ -33,15 +33,14 @@ public class JPackage extends JNode implements Comparable<JPackage> {
this
.
classes
=
new
ArrayList
<
JClass
>(
1
);
}
@Override
public
void
updateChilds
()
{
public
void
update
()
{
removeAllChildren
();
for
(
JPackage
pkg
:
innerPackages
)
{
pkg
.
update
Childs
();
pkg
.
update
();
add
(
pkg
);
}
for
(
JClass
cls
:
classes
)
{
cls
.
update
Childs
();
cls
.
update
();
add
(
cls
);
}
}
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
View file @
3c84975a
...
...
@@ -27,11 +27,10 @@ public class JRoot extends JNode {
public
JRoot
(
JadxWrapper
wrapper
)
{
this
.
wrapper
=
wrapper
;
update
Childs
();
update
();
}
@Override
public
void
updateChilds
()
{
public
void
update
()
{
removeAllChildren
();
if
(
flatPackages
)
{
for
(
JavaPackage
pkg
:
wrapper
.
getPackages
())
{
...
...
@@ -41,7 +40,7 @@ public class JRoot extends JNode {
// build packages hierarchy
List
<
JPackage
>
rootPkgs
=
getHierarchyPackages
(
wrapper
.
getPackages
());
for
(
JPackage
jPackage
:
rootPkgs
)
{
jPackage
.
update
Childs
();
jPackage
.
update
();
add
(
jPackage
);
}
}
...
...
@@ -88,7 +87,7 @@ public class JRoot extends JNode {
}
// use identity set for collect inner packages
Set
<
JPackage
>
innerPackages
=
Collections
.
newSetFromMap
(
new
IdentityHashMap
<
JPackage
,
Boolean
>());
Set
<
JPackage
>
innerPackages
=
Collections
.
newSetFromMap
(
new
IdentityHashMap
<
JPackage
,
Boolean
>());
for
(
JPackage
pkg
:
pkgMap
.
values
())
{
innerPackages
.
addAll
(
pkg
.
getInnerPackages
());
}
...
...
@@ -131,7 +130,7 @@ public class JRoot extends JNode {
public
void
setFlatPackages
(
boolean
flatPackages
)
{
if
(
this
.
flatPackages
!=
flatPackages
)
{
this
.
flatPackages
=
flatPackages
;
update
Childs
();
update
();
}
}
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/TextNode.java
View file @
3c84975a
...
...
@@ -20,10 +20,6 @@ public class TextNode extends JNode {
}
@Override
public
void
updateChilds
()
{
}
@Override
public
Icon
getIcon
()
{
return
null
;
}
...
...
jadx-gui/src/main/java/jadx/gui/utils/Utils.java
View file @
3c84975a
...
...
@@ -67,10 +67,18 @@ public class Utils {
icon
=
def
;
}
OverlayIcon
overIcon
=
new
OverlayIcon
(
icon
);
if
(
af
.
isFinal
())
overIcon
.
add
(
ICON_FINAL
);
if
(
af
.
isStatic
())
overIcon
.
add
(
ICON_STATIC
);
if
(
af
.
isAbstract
())
overIcon
.
add
(
ICON_ABSTRACT
);
if
(
af
.
isNative
())
overIcon
.
add
(
ICON_NATIVE
);
if
(
af
.
isFinal
())
{
overIcon
.
add
(
ICON_FINAL
);
}
if
(
af
.
isStatic
())
{
overIcon
.
add
(
ICON_STATIC
);
}
if
(
af
.
isAbstract
())
{
overIcon
.
add
(
ICON_ABSTRACT
);
}
if
(
af
.
isNative
())
{
overIcon
.
add
(
ICON_NATIVE
);
}
return
overIcon
;
}
}
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