Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
c97678a4
Commit
c97678a4
authored
Aug 05, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: make ErrorsCounter non static
parent
2ad73927
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
69 additions
and
64 deletions
+69
-64
JadxCLI.java
jadx-cli/src/main/java/jadx/cli/JadxCLI.java
+12
-17
JadxCLIArgs.java
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
+3
-2
DefaultJadxArgs.java
jadx-core/src/main/java/jadx/api/DefaultJadxArgs.java
+7
-0
IJadxArgs.java
jadx-core/src/main/java/jadx/api/IJadxArgs.java
+4
-0
JadxDecompiler.java
jadx-core/src/main/java/jadx/api/JadxDecompiler.java
+21
-8
Consts.java
jadx-core/src/main/java/jadx/core/Consts.java
+0
-2
NameGen.java
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
+1
-1
RootNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
+6
-0
ErrorsCounter.java
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
+14
-14
TestAPI.groovy
jadx-core/src/test/groovy/jadx/tests/TestAPI.groovy
+1
-20
No files found.
jadx-cli/src/main/java/jadx/cli/JadxCLI.java
View file @
c97678a4
package
jadx
.
cli
;
import
jadx.api.JadxDecompiler
;
import
jadx.core.utils.ErrorsCounter
;
import
jadx.core.utils.exceptions.JadxException
;
import
java.io.File
;
...
...
@@ -12,33 +11,29 @@ import org.slf4j.LoggerFactory;
public
class
JadxCLI
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
JadxCLI
.
class
);
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
JadxException
{
try
{
JadxCLIArgs
jadxArgs
=
new
JadxCLIArgs
();
if
(
processArgs
(
jadxArgs
,
args
))
{
processAndSave
(
jadxArgs
);
}
}
catch
(
JadxException
e
)
{
LOG
.
error
(
e
.
getMessage
()
);
}
catch
(
Throwable
e
)
{
LOG
.
error
(
"jadx error: "
+
e
.
getMessage
(),
e
);
System
.
exit
(
1
);
}
}
static
void
processAndSave
(
JadxCLIArgs
jadxArgs
)
throws
JadxException
{
try
{
JadxDecompiler
jadx
=
new
JadxDecompiler
(
jadxArgs
);
jadx
.
loadFiles
(
jadxArgs
.
getInput
());
jadx
.
setOutputDir
(
jadxArgs
.
getOutDir
());
jadx
.
save
();
}
catch
(
Throwable
e
)
{
throw
new
JadxException
(
"jadx error: "
+
e
.
getMessage
(),
e
);
JadxDecompiler
jadx
=
new
JadxDecompiler
(
jadxArgs
);
jadx
.
setOutputDir
(
jadxArgs
.
getOutDir
());
jadx
.
loadFiles
(
jadxArgs
.
getInput
());
jadx
.
save
();
if
(
jadx
.
getErrorsCount
()
!=
0
)
{
jadx
.
printErrorsReport
();
LOG
.
error
(
"finished with errors"
);
}
else
{
LOG
.
info
(
"done"
);
}
if
(
ErrorsCounter
.
getErrorCount
()
!=
0
)
{
ErrorsCounter
.
printReport
();
throw
new
JadxException
(
"finished with errors"
);
}
LOG
.
info
(
"done"
);
}
static
boolean
processArgs
(
JadxCLIArgs
jadxArgs
,
String
[]
args
)
throws
JadxException
{
...
...
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
View file @
c97678a4
package
jadx
.
cli
;
import
jadx.api.IJadxArgs
;
import
jadx.
core.Consts
;
import
jadx.
api.JadxDecompiler
;
import
jadx.core.utils.exceptions.JadxException
;
import
java.io.File
;
...
...
@@ -105,7 +105,7 @@ public final class JadxCLIArgs implements IJadxArgs {
// print usage in not sorted fields order (by default its sorted by description)
PrintStream
out
=
System
.
out
;
out
.
println
();
out
.
println
(
"jadx - dex to java decompiler, version: "
+
Consts
.
JADX_VERSION
);
out
.
println
(
"jadx - dex to java decompiler, version: "
+
JadxDecompiler
.
getVersion
()
);
out
.
println
();
out
.
println
(
"usage: jadx [options] "
+
jc
.
getMainParameterDescription
());
out
.
println
(
"options:"
);
...
...
@@ -148,6 +148,7 @@ public final class JadxCLIArgs implements IJadxArgs {
return
input
;
}
@Override
public
File
getOutDir
()
{
return
outputDir
;
}
...
...
jadx-core/src/main/java/jadx/api/DefaultJadxArgs.java
View file @
c97678a4
package
jadx
.
api
;
import
java.io.File
;
public
class
DefaultJadxArgs
implements
IJadxArgs
{
@Override
public
File
getOutDir
()
{
return
new
File
(
"jadx-output"
);
}
@Override
public
int
getThreadsCount
()
{
return
Runtime
.
getRuntime
().
availableProcessors
();
}
...
...
jadx-core/src/main/java/jadx/api/IJadxArgs.java
View file @
c97678a4
package
jadx
.
api
;
import
java.io.File
;
public
interface
IJadxArgs
{
File
getOutDir
();
int
getThreadsCount
();
boolean
isCFGOutput
();
...
...
jadx-core/src/main/java/jadx/api/JadxDecompiler.java
View file @
c97678a4
...
...
@@ -7,7 +7,6 @@ import jadx.core.dex.nodes.ClassNode;
import
jadx.core.dex.nodes.RootNode
;
import
jadx.core.dex.visitors.IDexTreeVisitor
;
import
jadx.core.dex.visitors.SaveCode
;
import
jadx.core.utils.ErrorsCounter
;
import
jadx.core.utils.exceptions.DecodeException
;
import
jadx.core.utils.exceptions.JadxException
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
...
...
@@ -57,12 +56,13 @@ public final class JadxDecompiler {
private
List
<
JavaClass
>
classes
;
public
JadxDecompiler
()
{
this
.
args
=
new
DefaultJadxArgs
();
init
();
this
(
new
DefaultJadxArgs
());
}
public
JadxDecompiler
(
IJadxArgs
jadxArgs
)
{
this
.
args
=
jadxArgs
;
this
.
outDir
=
jadxArgs
.
getOutDir
();
reset
();
init
();
}
...
...
@@ -72,17 +72,20 @@ public final class JadxDecompiler {
}
void
init
()
{
reset
();
if
(
outDir
==
null
)
{
outDir
=
new
File
(
"jadx-output"
);
outDir
=
new
DefaultJadxArgs
().
getOutDir
(
);
}
this
.
passes
=
Jadx
.
getPassesList
(
args
,
outDir
);
}
void
reset
()
{
ClassInfo
.
clearCache
();
ErrorsCounter
.
reset
();
classes
=
null
;
root
=
null
;
}
public
static
String
getVersion
()
{
return
Jadx
.
getVersion
();
}
public
void
loadFile
(
File
file
)
throws
JadxException
{
...
...
@@ -182,7 +185,17 @@ public final class JadxDecompiler {
}
public
int
getErrorsCount
()
{
return
ErrorsCounter
.
getErrorCount
();
if
(
root
==
null
)
{
return
0
;
}
return
root
.
getErrorsCounter
().
getErrorCount
();
}
public
void
printErrorsReport
()
{
if
(
root
==
null
)
{
return
;
}
root
.
getErrorsCounter
().
printReport
();
}
void
parse
()
throws
DecodeException
{
...
...
@@ -214,6 +227,6 @@ public final class JadxDecompiler {
@Override
public
String
toString
()
{
return
"jadx decompiler
"
;
return
"jadx decompiler
"
+
getVersion
()
;
}
}
jadx-core/src/main/java/jadx/core/Consts.java
View file @
c97678a4
package
jadx
.
core
;
public
class
Consts
{
public
static
final
String
JADX_VERSION
=
Jadx
.
getVersion
();
public
static
final
boolean
DEBUG
=
false
;
public
static
final
String
CLASS_OBJECT
=
"java.lang.Object"
;
...
...
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
View file @
c97678a4
...
...
@@ -172,7 +172,7 @@ public class NameGen {
}
}
p
ublic
static
String
getAliasForObject
(
String
name
)
{
p
rivate
static
String
getAliasForObject
(
String
name
)
{
return
OBJ_ALIAS
.
get
(
name
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
View file @
c97678a4
...
...
@@ -3,6 +3,7 @@ package jadx.core.dex.nodes;
import
jadx.core.clsp.ClspGraph
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.utils.ErrorsCounter
;
import
jadx.core.utils.exceptions.DecodeException
;
import
jadx.core.utils.files.InputFile
;
...
...
@@ -14,6 +15,7 @@ import java.util.Map;
public
class
RootNode
{
private
final
Map
<
String
,
ClassNode
>
names
=
new
HashMap
<
String
,
ClassNode
>();
private
final
ErrorsCounter
errorsCounter
=
new
ErrorsCounter
();
private
List
<
DexNode
>
dexNodes
;
public
void
load
(
List
<
InputFile
>
dexFiles
)
throws
DecodeException
{
...
...
@@ -101,4 +103,8 @@ public class RootNode {
String
fullName
=
cls
.
getFullName
();
return
searchClassByName
(
fullName
);
}
public
ErrorsCounter
getErrorsCounter
()
{
return
errorsCounter
;
}
}
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
View file @
c97678a4
...
...
@@ -20,20 +20,20 @@ import org.slf4j.LoggerFactory;
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
;
private
final
Set
<
Object
>
errorNodes
=
new
HashSet
<
Object
>();
private
int
errorsCount
;
public
static
int
getErrorCount
()
{
public
int
getErrorCount
()
{
return
errorsCount
;
}
public
static
void
reset
()
{
ERROR_NODES
.
clear
();
public
void
reset
()
{
errorNodes
.
clear
();
errorsCount
=
0
;
}
private
static
void
addError
(
IAttributeNode
node
,
String
msg
,
Throwable
e
)
{
ERROR_NODES
.
add
(
node
);
private
void
addError
(
IAttributeNode
node
,
String
msg
,
Throwable
e
)
{
errorNodes
.
add
(
node
);
errorsCount
++;
if
(
e
!=
null
)
{
...
...
@@ -53,13 +53,13 @@ public class ErrorsCounter {
public
static
String
classError
(
ClassNode
cls
,
String
errorMsg
,
Throwable
e
)
{
String
msg
=
formatErrorMsg
(
cls
,
errorMsg
);
addError
(
cls
,
msg
,
e
);
cls
.
dex
().
root
().
getErrorsCounter
().
addError
(
cls
,
msg
,
e
);
return
msg
;
}
public
static
String
methodError
(
MethodNode
mth
,
String
errorMsg
,
Throwable
e
)
{
String
msg
=
formatErrorMsg
(
mth
,
errorMsg
);
addError
(
mth
,
msg
,
e
);
mth
.
dex
().
root
().
getErrorsCounter
().
addError
(
mth
,
msg
,
e
);
return
msg
;
}
...
...
@@ -67,10 +67,10 @@ public class ErrorsCounter {
return
methodError
(
mth
,
errorMsg
,
null
);
}
public
static
void
printReport
()
{
public
void
printReport
()
{
if
(
getErrorCount
()
>
0
)
{
LOG
.
error
(
getErrorCount
()
+
" errors occured in following nodes:"
);
List
<
Object
>
nodes
=
new
ArrayList
<
Object
>(
ERROR_NODES
);
List
<
Object
>
nodes
=
new
ArrayList
<
Object
>(
errorNodes
);
Collections
.
sort
(
nodes
,
new
Comparator
<
Object
>()
{
@Override
public
int
compare
(
Object
o1
,
Object
o2
)
{
...
...
@@ -92,7 +92,7 @@ public class ErrorsCounter {
return
msg
+
" in method: "
+
mth
;
}
private
static
String
formatException
(
Throwable
e
)
{
private
String
formatException
(
Throwable
e
)
{
if
(
e
==
null
||
e
.
getMessage
()
==
null
)
{
return
""
;
}
else
{
...
...
@@ -100,11 +100,11 @@ public class ErrorsCounter {
}
}
public
static
String
formatErrorMsg
(
ClassNode
cls
,
String
msg
,
Throwable
e
)
{
public
String
formatErrorMsg
(
ClassNode
cls
,
String
msg
,
Throwable
e
)
{
return
formatErrorMsg
(
cls
,
msg
)
+
formatException
(
e
);
}
public
static
String
formatErrorMsg
(
MethodNode
mth
,
String
msg
,
Throwable
e
)
{
public
String
formatErrorMsg
(
MethodNode
mth
,
String
msg
,
Throwable
e
)
{
return
formatErrorMsg
(
mth
,
msg
)
+
formatException
(
e
);
}
}
jadx-core/src/test/groovy/jadx/tests/TestAPI.groovy
View file @
c97678a4
package
jadx.tests
import
jadx.api.JadxDecompiler
import
jadx.api.IJadxArgs
import
jadx.core.dex.nodes.MethodNode
import
jadx.core.utils.ErrorsCounter
import
jadx.api.JadxDecompiler
import
jadx.core.utils.exceptions.JadxException
import
jadx.core.utils.exceptions.JadxRuntimeException
import
spock.lang.Specification
...
...
@@ -67,20 +64,4 @@ class TestAPI extends Specification {
expect:
new
JadxDecompiler
().
getErrorsCount
()
==
0
}
def
"get errors count after one more init"
()
{
setup:
new
JadxDecompiler
()
def
mth
=
Mock
(
MethodNode
)
when:
ErrorsCounter
.
methodError
(
mth
,
""
)
def
d
=
new
JadxDecompiler
()
then:
d
.
getErrorsCount
()
==
0
}
def
"decompiler toString()"
()
{
expect:
new
JadxDecompiler
().
toString
()
==
"jadx decompiler"
}
}
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