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
aa8a7c03
Unverified
Commit
aa8a7c03
authored
Mar 26, 2019
by
skylot
Committed by
GitHub
Mar 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style: enforce strict style rules with editorconfig (PR #510)
parent
36ee994e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
561 additions
and
561 deletions
+561
-561
.editorconfig
.editorconfig
+22
-0
build.gradle
build.gradle
+105
-92
JadxCLIArgs.java
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
+1
-1
logback.xml
jadx-cli/src/main/resources/logback.xml
+11
-13
JadxArgs.java
jadx-core/src/main/java/jadx/api/JadxArgs.java
+1
-2
NotYetImplemented.java
jadx-core/src/test/java/jadx/NotYetImplemented.java
+4
-4
TestImportGenericMap.java
...jadx/tests/integration/generics/TestImportGenericMap.java
+13
-14
logback.xml
jadx-core/src/test/resources/logback.xml
+8
-8
JPackage.java
jadx-gui/src/main/java/jadx/gui/treemodel/JPackage.java
+3
-5
MainWindow.java
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
+20
-47
LineNumbers.java
jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
+226
-226
NLS.java
jadx-gui/src/main/java/jadx/gui/utils/NLS.java
+108
-108
build.gradle
jadx-samples/build.gradle
+25
-25
TestInitializers.java
...-samples/src/main/java/jadx/samples/TestInitializers.java
+10
-11
TestInner3.java
jadx-samples/src/main/java/jadx/samples/TestInner3.java
+4
-5
No files found.
.editorconfig
0 → 100644
View file @
aa8a7c03
# EditorConfig is awesome: https://EditorConfig.org
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
[*.xml]
indent_size = 1
[*.yml]
indent_style = space
indent_size = 2
[*.bat]
end_of_line = crlf
build.gradle
View file @
aa8a7c03
plugins
{
id
'org.sonarqube'
version
'2.7'
id
'com.github.ben-manes.versions'
version
'0.21.0'
id
'org.sonarqube'
version
'2.7'
id
'com.github.ben-manes.versions'
version
'0.21.0'
id
'org.ec4j.editorconfig'
version
'0.0.3'
}
ext
.
jadxVersion
=
System
.
getenv
(
'JADX_VERSION'
)
?:
"dev"
...
...
@@ -8,125 +9,137 @@ version = jadxVersion
println
(
"jadx version: ${jadxVersion}"
)
allprojects
{
apply
plugin:
'java'
apply
plugin:
'groovy'
apply
plugin:
'jacoco'
version
=
jadxVersion
tasks
.
withType
(
JavaCompile
)
{
sourceCompatibility
=
JavaVersion
.
VERSION_1_8
targetCompatibility
=
JavaVersion
.
VERSION_1_8
if
(!
"$it"
.
contains
(
':jadx-samples:'
))
{
options
.
compilerArgs
<<
'-Xlint'
<<
'-Xlint:unchecked'
<<
'-Xlint:deprecation'
}
}
compileJava
{
options
.
encoding
=
"UTF-8"
}
jar
{
version
=
jadxVersion
manifest
{
mainAttributes
(
'jadx-version'
:
jadxVersion
)
}
}
dependencies
{
compile
'org.slf4j:slf4j-api:1.7.26'
testCompile
'ch.qos.logback:logback-classic:1.2.3'
testCompile
'org.hamcrest:hamcrest-library:2.1'
testCompile
'org.mockito:mockito-core:2.25.1'
testImplementation
'org.junit.jupiter:junit-jupiter-api:5.4.1'
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.4.1'
}
test
{
useJUnitPlatform
()
}
repositories
{
mavenLocal
()
mavenCentral
()
jcenter
()
google
()
}
jacoco
{
toolVersion
=
"0.8.2"
}
jacocoTestReport
{
reports
{
xml
.
enabled
=
true
html
.
enabled
=
true
}
}
apply
plugin:
'java'
apply
plugin:
'groovy'
apply
plugin:
'jacoco'
version
=
jadxVersion
tasks
.
withType
(
JavaCompile
)
{
sourceCompatibility
=
JavaVersion
.
VERSION_1_8
targetCompatibility
=
JavaVersion
.
VERSION_1_8
if
(!
"$it"
.
contains
(
':jadx-samples:'
))
{
options
.
compilerArgs
<<
'-Xlint'
<<
'-Xlint:unchecked'
<<
'-Xlint:deprecation'
}
}
compileJava
{
options
.
encoding
=
"UTF-8"
}
jar
{
version
=
jadxVersion
manifest
{
mainAttributes
(
'jadx-version'
:
jadxVersion
)
}
}
dependencies
{
compile
'org.slf4j:slf4j-api:1.7.26'
testCompile
'ch.qos.logback:logback-classic:1.2.3'
testCompile
'org.hamcrest:hamcrest-library:2.1'
testCompile
'org.mockito:mockito-core:2.25.1'
testImplementation
'org.junit.jupiter:junit-jupiter-api:5.4.1'
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.4.1'
}
test
{
useJUnitPlatform
()
}
repositories
{
mavenLocal
()
mavenCentral
()
jcenter
()
google
()
}
jacoco
{
toolVersion
=
"0.8.2"
}
jacocoTestReport
{
reports
{
xml
.
enabled
=
true
html
.
enabled
=
true
}
}
}
sonarqube
{
properties
{
property
'sonar.exclusions'
,
'**/jadx/samples/**/*,**/test-app/**/*'
property
'sonar.coverage.exclusions'
,
'**/jadx/gui/**/*'
}
properties
{
property
'sonar.exclusions'
,
'**/jadx/samples/**/*,**/test-app/**/*'
property
'sonar.coverage.exclusions'
,
'**/jadx/gui/**/*'
}
}
editorconfig
{
excludes
=
[
'gradle/'
,
'jadx-test-app/test-app'
// ignore issues in submodule
,
'**/out/'
// IntelliJ Idea build dirs
,
'**/certificate-test/'
// binary test files (.RSA)
,
'**/*.svg'
,
'**/*.arsc'
]
}
dependencyUpdates
.
resolutionStrategy
=
{
componentSelection
{
rules
->
rules
.
all
{
ComponentSelection
selection
->
boolean
rejected
=
[
'alpha'
,
'beta'
,
'rc'
,
'cr'
,
'm'
,
'atlassian'
].
any
{
qualifier
->
selection
.
candidate
.
version
==~
/(?i).*[.-]${qualifier}[.\d-]*/
}
if
(
rejected
)
{
selection
.
reject
(
'Release candidate'
)
}
}
}
componentSelection
{
rules
->
rules
.
all
{
ComponentSelection
selection
->
boolean
rejected
=
[
'alpha'
,
'beta'
,
'rc'
,
'cr'
,
'm'
,
'atlassian'
].
any
{
qualifier
->
selection
.
candidate
.
version
==~
/(?i).*[.-]${qualifier}[.\d-]*/
}
if
(
rejected
)
{
selection
.
reject
(
'Release candidate'
)
}
}
}
}
task
copyArtifacts
(
type:
Sync
,
dependsOn:
[
'jadx-cli:installDist'
,
'jadx-gui:installDist'
])
{
destinationDir
file
(
"$buildDir/jadx"
)
[
'jadx-cli'
,
'jadx-gui'
].
each
{
from
tasks
.
getByPath
(
":${it}:installDist"
).
destinationDir
}
destinationDir
file
(
"$buildDir/jadx"
)
[
'jadx-cli'
,
'jadx-gui'
].
each
{
from
tasks
.
getByPath
(
":${it}:installDist"
).
destinationDir
}
}
task
pack
(
type:
Zip
,
dependsOn:
copyArtifacts
)
{
destinationDir
buildDir
archiveName
"jadx-${jadxVersion}.zip"
from
copyArtifacts
.
destinationDir
destinationDir
buildDir
archiveName
"jadx-${jadxVersion}.zip"
from
copyArtifacts
.
destinationDir
}
task
copyExe
(
type:
Copy
,
dependsOn:
'jadx-gui:createExe'
)
{
group
'jadx'
description
=
'Copy exe to build dir'
destinationDir
buildDir
from
tasks
.
getByPath
(
'jadx-gui:createExe'
).
outputs
include
'*.exe'
group
'jadx'
description
=
'Copy exe to build dir'
destinationDir
buildDir
from
tasks
.
getByPath
(
'jadx-gui:createExe'
).
outputs
include
'*.exe'
}
task
dist
(
dependsOn:
[
pack
,
copyExe
])
{
group
'jadx'
description
=
'Build jadx distribution zip'
group
'jadx'
description
=
'Build jadx distribution zip'
}
task
samples
(
dependsOn:
'jadx-samples:samples'
)
{
group
'jadx'
group
'jadx'
}
task
testAppCheck
(
dependsOn:
'jadx-test-app:testAppCheck'
)
{
group
'jadx'
group
'jadx'
}
task
cleanBuildDir
(
type:
Delete
)
{
group
'jadx'
delete
buildDir
group
'jadx'
delete
buildDir
}
build
.
dependsOn
(
dist
,
samples
)
check
.
dependsOn
editorconfigCheck
test
.
dependsOn
(
samples
)
clean
.
dependsOn
(
cleanBuildDir
)
jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
View file @
aa8a7c03
...
...
@@ -125,7 +125,7 @@ public class JadxCLIArgs {
}
if
(
verbose
)
{
ch
.
qos
.
logback
.
classic
.
Logger
rootLogger
=
(
ch
.
qos
.
logback
.
classic
.
Logger
)
LoggerFactory
.
getLogger
(
Logger
.
ROOT_LOGGER_NAME
);
(
ch
.
qos
.
logback
.
classic
.
Logger
)
LoggerFactory
.
getLogger
(
Logger
.
ROOT_LOGGER_NAME
);
// remove INFO ThresholdFilter
Appender
<
ILoggingEvent
>
appender
=
rootLogger
.
getAppender
(
"STDOUT"
);
if
(
appender
!=
null
)
{
...
...
jadx-cli/src/main/resources/logback.xml
View file @
aa8a7c03
<configuration>
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
INFO
</level>
</filter>
<encoder>
<pattern>
%-5level - %msg%n
</pattern>
</encoder>
</appender>
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
INFO
</level>
</filter>
<encoder>
<pattern>
%-5level - %msg%n
</pattern>
</encoder>
</appender>
<root
level=
"DEBUG"
>
<appender-ref
ref=
"STDOUT"
/>
</root>
<root
level=
"DEBUG"
>
<appender-ref
ref=
"STDOUT"
/>
</root>
</configuration>
jadx-core/src/main/java/jadx/api/JadxArgs.java
View file @
aa8a7c03
...
...
@@ -137,7 +137,7 @@ public class JadxArgs {
public
boolean
isDebugInfo
()
{
return
debugInfo
;
}
public
void
setDebugInfo
(
boolean
debugInfo
)
{
this
.
debugInfo
=
debugInfo
;
}
...
...
@@ -257,5 +257,4 @@ public class JadxArgs {
sb
.
append
(
'}'
);
return
sb
.
toString
();
}
}
jadx-core/src/test/java/jadx/NotYetImplemented.java
View file @
aa8a7c03
...
...
@@ -7,14 +7,14 @@ import java.lang.annotation.Target;
/**
* Indicates a test which is known to fail.
*
*
* <p>This would cause a failure to be considered as success and a success as failure,
* with the benefit of updating the related issue when it has been resolved even unintentionally.</p>
*
*
* <p>To have an effect, the test class must be annotated with:
*
*
* <code>
*
@ExtendWith(NotYetImplementedExtension.class)
* @ExtendWith(NotYetImplementedExtension.class)
* </code>
* </p>
*/
...
...
jadx-core/src/test/java/jadx/tests/integration/generics/TestImportGenericMap.java
View file @
aa8a7c03
package
jadx
.
tests
.
integration
.
generics
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
public
class
TestImportGenericMap
extends
IntegrationTest
{
@Test
...
...
@@ -25,16 +25,15 @@ public class TestImportGenericMap extends IntegrationTest {
final
class
SuperClass
<
O
extends
SuperClass
.
ToImport
>
{
interface
ToImport
{
}
interface
NotToImport
{
}
interface
ToImport
{
}
static
final
class
Class1
<
C
extends
NotToImport
>
{
}
interface
NotToImport
{
}
public
<
C
extends
NotToImport
>
SuperClass
(
Class1
<
C
>
zzf
)
{
}
static
final
class
Class1
<
C
extends
NotToImport
>
{
}
}
\ No newline at end of file
public
<
C
extends
NotToImport
>
SuperClass
(
Class1
<
C
>
zzf
)
{
}
}
jadx-core/src/test/resources/logback.xml
View file @
aa8a7c03
<configuration>
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
%d{HH:mm:ss} %-5level - %msg%n
</pattern>
</encoder>
</appender>
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
%d{HH:mm:ss} %-5level - %msg%n
</pattern>
</encoder>
</appender>
<root
level=
"DEBUG"
>
<appender-ref
ref=
"STDOUT"
/>
</root>
<root
level=
"DEBUG"
>
<appender-ref
ref=
"STDOUT"
/>
</root>
</configuration>
jadx-gui/src/main/java/jadx/gui/treemodel/JPackage.java
View file @
aa8a7c03
package
jadx
.
gui
.
treemodel
;
import
javax.swing.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.swing.Icon
;
import
javax.swing.ImageIcon
;
import
org.jetbrains.annotations.NotNull
;
import
jadx.api.JavaClass
;
...
...
@@ -47,7 +45,7 @@ public class JPackage extends JNode implements Comparable<JPackage> {
List
<
String
>
excludedPackages
=
wrapper
.
getExcludedPackages
();
this
.
enabled
=
excludedPackages
.
isEmpty
()
||
excludedPackages
.
stream
().
filter
(
p
->
!
p
.
isEmpty
())
.
noneMatch
(
p
->
name
.
equals
(
p
)
||
name
.
startsWith
(
p
+
'.'
));
.
noneMatch
(
p
->
name
.
equals
(
p
)
||
name
.
startsWith
(
p
+
'.'
));
}
public
final
void
update
()
{
...
...
@@ -130,7 +128,7 @@ public class JPackage extends JNode implements Comparable<JPackage> {
public
String
makeLongString
()
{
return
name
;
}
public
boolean
isEnabled
()
{
return
enabled
;
}
...
...
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
View file @
aa8a7c03
package
jadx
.
gui
.
ui
;
import
static
javax
.
swing
.
KeyStroke
.
getKeyStroke
;
import
java.awt.BorderLayout
;
import
java.awt.Component
;
import
java.awt.DisplayMode
;
import
java.awt.Font
;
import
java.awt.GraphicsDevice
;
import
java.awt.GraphicsEnvironment
;
import
javax.swing.*
;
import
javax.swing.event.MenuEvent
;
import
javax.swing.event.MenuListener
;
import
javax.swing.event.TreeExpansionEvent
;
import
javax.swing.event.TreeWillExpandListener
;
import
javax.swing.filechooser.FileNameExtensionFilter
;
import
javax.swing.tree.DefaultMutableTreeNode
;
import
javax.swing.tree.DefaultTreeCellRenderer
;
import
javax.swing.tree.DefaultTreeModel
;
import
javax.swing.tree.TreeNode
;
import
javax.swing.tree.TreePath
;
import
javax.swing.tree.TreeSelectionModel
;
import
java.awt.*
;
import
java.awt.dnd.DnDConstants
;
import
java.awt.dnd.DropTarget
;
import
java.awt.event.ActionEvent
;
...
...
@@ -22,38 +27,6 @@ import java.util.Arrays;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
javax.swing.AbstractAction
;
import
javax.swing.Action
;
import
javax.swing.Box
;
import
javax.swing.ImageIcon
;
import
javax.swing.JCheckBoxMenuItem
;
import
javax.swing.JFileChooser
;
import
javax.swing.JFrame
;
import
javax.swing.JMenu
;
import
javax.swing.JMenuBar
;
import
javax.swing.JMenuItem
;
import
javax.swing.JPanel
;
import
javax.swing.JPopupMenu
;
import
javax.swing.JScrollPane
;
import
javax.swing.JSplitPane
;
import
javax.swing.JToggleButton
;
import
javax.swing.JToolBar
;
import
javax.swing.JTree
;
import
javax.swing.ProgressMonitor
;
import
javax.swing.SwingUtilities
;
import
javax.swing.WindowConstants
;
import
javax.swing.event.MenuEvent
;
import
javax.swing.event.MenuListener
;
import
javax.swing.event.TreeExpansionEvent
;
import
javax.swing.event.TreeWillExpandListener
;
import
javax.swing.filechooser.FileNameExtensionFilter
;
import
javax.swing.tree.DefaultMutableTreeNode
;
import
javax.swing.tree.DefaultTreeCellRenderer
;
import
javax.swing.tree.DefaultTreeModel
;
import
javax.swing.tree.TreeNode
;
import
javax.swing.tree.TreePath
;
import
javax.swing.tree.TreeSelectionModel
;
import
org.fife.ui.rsyntaxtextarea.Theme
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -83,6 +56,8 @@ import jadx.gui.utils.Link;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.Utils
;
import
static
javax
.
swing
.
KeyStroke
.
getKeyStroke
;
@SuppressWarnings
(
"serial"
)
public
class
MainWindow
extends
JFrame
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MainWindow
.
class
);
...
...
@@ -343,10 +318,10 @@ public class MainWindow extends JFrame {
Object
obj
=
tree
.
getLastSelectedPathComponent
();
if
(
obj
instanceof
JPackage
)
{
JPackagePopUp
menu
=
new
JPackagePopUp
((
JPackage
)
obj
);
menu
.
show
(
e
.
getComponent
(),
e
.
getX
(),
e
.
getY
());
menu
.
show
(
e
.
getComponent
(),
e
.
getX
(),
e
.
getY
());
}
}
private
void
syncWithEditor
()
{
ContentPanel
selectedContentPanel
=
tabbedPane
.
getSelectedCodePanel
();
if
(
selectedContentPanel
==
null
)
{
...
...
@@ -608,8 +583,7 @@ public class MainWindow extends JFrame {
public
void
mouseClicked
(
MouseEvent
e
)
{
if
(
SwingUtilities
.
isRightMouseButton
(
e
))
{
treeRightClickAction
(
e
);
}
else
{
}
else
{
treeClickAction
();
}
}
...
...
@@ -780,7 +754,7 @@ public class MainWindow extends JFrame {
public
void
menuCanceled
(
MenuEvent
e
)
{
}
}
private
class
JPackagePopUp
extends
JPopupMenu
{
JMenuItem
excludeItem
=
new
JCheckBoxMenuItem
(
"Exclude"
);
...
...
@@ -791,8 +765,7 @@ public class MainWindow extends JFrame {
String
fullName
=
pkg
.
getFullName
();
if
(
excludeItem
.
isSelected
())
{
wrapper
.
addExcludedPackage
(
fullName
);
}
else
{
}
else
{
wrapper
.
removeExcludedPackage
(
fullName
);
}
reOpenFile
();
...
...
jadx-gui/src/main/java/jadx/gui/ui/codearea/LineNumbers.java
View file @
aa8a7c03
This diff is collapsed.
Click to expand it.
jadx-gui/src/main/java/jadx/gui/utils/NLS.java
View file @
aa8a7c03
package
jadx
.
gui
.
utils
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.MissingResourceException
;
import
java.util.PropertyResourceBundle
;
import
java.util.ResourceBundle
;
import
java.util.Vector
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
public
class
NLS
{
private
static
final
Vector
<
LangLocale
>
i18nLocales
=
new
Vector
<>();
private
static
final
Map
<
LangLocale
,
ResourceBundle
>
i18nMessagesMap
=
new
HashMap
<>();
private
static
final
ResourceBundle
fallbackMessagesMap
;
private
static
final
LangLocale
localLocale
;
// Use these two fields to avoid invoking Map.get() method twice.
private
static
ResourceBundle
localizedMessagesMap
;
private
static
LangLocale
currentLocale
;
static
{
localLocale
=
new
LangLocale
(
Locale
.
getDefault
());
i18nLocales
.
add
(
new
LangLocale
(
"en"
,
"US"
));
// As default language
i18nLocales
.
add
(
new
LangLocale
(
"zh"
,
"CN"
));
i18nLocales
.
add
(
new
LangLocale
(
"es"
,
"ES"
));
i18nLocales
.
forEach
(
NLS:
:
load
);
LangLocale
defLang
=
i18nLocales
.
get
(
0
);
fallbackMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
localizedMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
}
private
NLS
()
{
}
private
static
void
load
(
LangLocale
locale
)
{
ResourceBundle
bundle
;
ClassLoader
classLoader
=
ClassLoader
.
getSystemClassLoader
();
String
resName
=
String
.
format
(
"i18n/Messages_%s.properties"
,
locale
.
get
());
URL
bundleUrl
=
classLoader
.
getResource
(
resName
);
if
(
bundleUrl
==
null
)
{
throw
new
JadxRuntimeException
(
"Locale resource not found: "
+
resName
);
}
try
(
Reader
reader
=
new
InputStreamReader
(
bundleUrl
.
openStream
(),
StandardCharsets
.
UTF_8
))
{
bundle
=
new
PropertyResourceBundle
(
reader
);
}
catch
(
IOException
e
)
{
throw
new
JadxRuntimeException
(
"Failed to load "
+
resName
,
e
);
}
i18nMessagesMap
.
put
(
locale
,
bundle
);
}
public
static
String
str
(
String
key
)
{
try
{
return
localizedMessagesMap
.
getString
(
key
);
}
catch
(
MissingResourceException
e
)
{
return
fallbackMessagesMap
.
getString
(
key
);
// definitely exists
}
}
public
static
String
str
(
String
key
,
LangLocale
locale
)
{
ResourceBundle
bundle
=
i18nMessagesMap
.
get
(
locale
);
if
(
bundle
!=
null
)
{
try
{
return
bundle
.
getString
(
key
);
}
catch
(
MissingResourceException
ignored
)
{
// use fallback string
}
}
return
fallbackMessagesMap
.
getString
(
key
);
// definitely exists
}
public
static
void
setLocale
(
LangLocale
locale
)
{
if
(
i18nMessagesMap
.
containsKey
(
locale
))
{
currentLocale
=
locale
;
}
else
{
currentLocale
=
i18nLocales
.
get
(
0
);
}
localizedMessagesMap
=
i18nMessagesMap
.
get
(
currentLocale
);
}
public
static
Vector
<
LangLocale
>
getI18nLocales
()
{
return
i18nLocales
;
}
public
static
LangLocale
currentLocale
()
{
return
currentLocale
;
}
public
static
LangLocale
defaultLocale
()
{
if
(
i18nMessagesMap
.
containsKey
(
localLocale
))
{
return
localLocale
;
}
// fallback to english if unsupported
return
i18nLocales
.
get
(
0
);
}
}
package
jadx
.
gui
.
utils
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.MissingResourceException
;
import
java.util.PropertyResourceBundle
;
import
java.util.ResourceBundle
;
import
java.util.Vector
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
public
class
NLS
{
private
static
final
Vector
<
LangLocale
>
i18nLocales
=
new
Vector
<>();
private
static
final
Map
<
LangLocale
,
ResourceBundle
>
i18nMessagesMap
=
new
HashMap
<>();
private
static
final
ResourceBundle
fallbackMessagesMap
;
private
static
final
LangLocale
localLocale
;
// Use these two fields to avoid invoking Map.get() method twice.
private
static
ResourceBundle
localizedMessagesMap
;
private
static
LangLocale
currentLocale
;
static
{
localLocale
=
new
LangLocale
(
Locale
.
getDefault
());
i18nLocales
.
add
(
new
LangLocale
(
"en"
,
"US"
));
// As default language
i18nLocales
.
add
(
new
LangLocale
(
"zh"
,
"CN"
));
i18nLocales
.
add
(
new
LangLocale
(
"es"
,
"ES"
));
i18nLocales
.
forEach
(
NLS:
:
load
);
LangLocale
defLang
=
i18nLocales
.
get
(
0
);
fallbackMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
localizedMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
}
private
NLS
()
{
}
private
static
void
load
(
LangLocale
locale
)
{
ResourceBundle
bundle
;
ClassLoader
classLoader
=
ClassLoader
.
getSystemClassLoader
();
String
resName
=
String
.
format
(
"i18n/Messages_%s.properties"
,
locale
.
get
());
URL
bundleUrl
=
classLoader
.
getResource
(
resName
);
if
(
bundleUrl
==
null
)
{
throw
new
JadxRuntimeException
(
"Locale resource not found: "
+
resName
);
}
try
(
Reader
reader
=
new
InputStreamReader
(
bundleUrl
.
openStream
(),
StandardCharsets
.
UTF_8
))
{
bundle
=
new
PropertyResourceBundle
(
reader
);
}
catch
(
IOException
e
)
{
throw
new
JadxRuntimeException
(
"Failed to load "
+
resName
,
e
);
}
i18nMessagesMap
.
put
(
locale
,
bundle
);
}
public
static
String
str
(
String
key
)
{
try
{
return
localizedMessagesMap
.
getString
(
key
);
}
catch
(
MissingResourceException
e
)
{
return
fallbackMessagesMap
.
getString
(
key
);
// definitely exists
}
}
public
static
String
str
(
String
key
,
LangLocale
locale
)
{
ResourceBundle
bundle
=
i18nMessagesMap
.
get
(
locale
);
if
(
bundle
!=
null
)
{
try
{
return
bundle
.
getString
(
key
);
}
catch
(
MissingResourceException
ignored
)
{
// use fallback string
}
}
return
fallbackMessagesMap
.
getString
(
key
);
// definitely exists
}
public
static
void
setLocale
(
LangLocale
locale
)
{
if
(
i18nMessagesMap
.
containsKey
(
locale
))
{
currentLocale
=
locale
;
}
else
{
currentLocale
=
i18nLocales
.
get
(
0
);
}
localizedMessagesMap
=
i18nMessagesMap
.
get
(
currentLocale
);
}
public
static
Vector
<
LangLocale
>
getI18nLocales
()
{
return
i18nLocales
;
}
public
static
LangLocale
currentLocale
()
{
return
currentLocale
;
}
public
static
LangLocale
defaultLocale
()
{
if
(
i18nMessagesMap
.
containsKey
(
localLocale
))
{
return
localLocale
;
}
// fallback to english if unsupported
return
i18nLocales
.
get
(
0
);
}
}
jadx-samples/build.gradle
View file @
aa8a7c03
project
.
ext
{
mainSamplesClass
=
"jadx.samples.RunTests"
samplesJadxSrcDir
=
"${buildDir}/samples-jadx/src"
samplesJadxOutDir
=
"${buildDir}/samples-jadx/output"
mainSamplesClass
=
"jadx.samples.RunTests"
samplesJadxSrcDir
=
"${buildDir}/samples-jadx/src"
samplesJadxOutDir
=
"${buildDir}/samples-jadx/output"
}
dependencies
{
compile
(
project
(
":jadx-core"
))
compile
(
project
(
":jadx-cli"
))
compile
(
project
(
":jadx-core"
))
compile
(
project
(
":jadx-cli"
))
}
compileJava
{
options
.
compilerArgs
<<
'-g:none'
options
.
compilerArgs
<<
'-g:none'
}
task
samplesRun
(
type:
JavaExec
,
dependsOn:
compileJava
)
{
classpath
=
sourceSets
.
main
.
output
main
=
mainSamplesClass
task
samplesRun
(
type:
JavaExec
,
dependsOn:
compileJava
)
{
classpath
=
sourceSets
.
main
.
output
main
=
mainSamplesClass
}
task
samplesJar
(
type:
Jar
,
dependsOn:
samplesRun
)
{
baseName
=
'samples'
from
sourceSets
.
main
.
output
baseName
=
'samples'
from
sourceSets
.
main
.
output
}
task
samplesJadxCreate
(
type:
JavaExec
,
dependsOn:
samplesJar
)
{
classpath
=
sourceSets
.
main
.
output
+
configurations
.
compile
main
=
project
(
":jadx-cli"
).
mainClassName
args
=
[
'-d'
,
samplesJadxSrcDir
,
samplesJar
.
archivePath
]
task
samplesJadxCreate
(
type:
JavaExec
,
dependsOn:
samplesJar
)
{
classpath
=
sourceSets
.
main
.
output
+
configurations
.
compile
main
=
project
(
":jadx-cli"
).
mainClassName
args
=
[
'-d'
,
samplesJadxSrcDir
,
samplesJar
.
archivePath
]
}
task
samplesJadxCompile
(
type:
JavaCompile
,
dependsOn:
samplesJadxCreate
)
{
classpath
=
configurations
.
compile
destinationDir
=
file
samplesJadxOutDir
source
=
samplesJadxSrcDir
options
.
encoding
=
"UTF-8"
task
samplesJadxCompile
(
type:
JavaCompile
,
dependsOn:
samplesJadxCreate
)
{
classpath
=
configurations
.
compile
destinationDir
=
file
samplesJadxOutDir
source
=
samplesJadxSrcDir
options
.
encoding
=
"UTF-8"
}
task
samplesJadxRun
(
type:
JavaExec
,
dependsOn:
samplesJadxCompile
)
{
classpath
=
files
samplesJadxOutDir
main
=
mainSamplesClass
task
samplesJadxRun
(
type:
JavaExec
,
dependsOn:
samplesJadxCompile
)
{
classpath
=
files
samplesJadxOutDir
main
=
mainSamplesClass
}
task
samples
(
dependsOn:
samplesJadxRun
)
{
}
task
cleanGeneratedFiles
(
type:
Delete
)
{
delete
samplesJadxSrcDir
delete
samplesJadxOutDir
delete
samplesJadxSrcDir
delete
samplesJadxOutDir
}
clean
.
dependsOn
cleanGeneratedFiles
jadx-samples/src/main/java/jadx/samples/TestInitializers.java
View file @
aa8a7c03
...
...
@@ -5,14 +5,14 @@ public class TestInitializers extends AbstractTest {
private
static
String
a
;
private
static
int
counter
;
private
A
c_a
;
public
static
class
A
{
public
static
String
a
;
static
{
a
=
"a1"
;
}
public
boolean
z
()
{
return
true
;
}
...
...
@@ -29,11 +29,11 @@ public class TestInitializers extends AbstractTest {
b
=
1
;
}
}
public
B
(
int
_b
)
{
b
=
_b
;
}
public
void
setB
(
int
_b
)
{
b
=
_b
;
}
...
...
@@ -41,11 +41,11 @@ public class TestInitializers extends AbstractTest {
public
int
getB
()
{
return
b
;
}
public
int
getBBB
()
{
return
bbb
;
}
{
bbb
=
123
;
}
...
...
@@ -55,7 +55,7 @@ public class TestInitializers extends AbstractTest {
a
=
"a0"
;
counter
=
0
;
}
{
c_a
=
new
A
();
}
...
...
@@ -90,15 +90,14 @@ public class TestInitializers extends AbstractTest {
assertTrue
((
new
B
()).
getB
()
==
-
1
);
assertTrue
(
counter
==
1
);
B
b3
=
new
B
(
3
);
assertTrue
((
b3
.
getB
()
==
3
)
&&
(
b3
.
getBBB
()
==
123
));
return
true
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestInitializers
().
testRun
();
}
}
jadx-samples/src/main/java/jadx/samples/TestInner3.java
View file @
aa8a7c03
...
...
@@ -5,11 +5,11 @@ public class TestInner3 extends AbstractTest {
private
String
i0
;
public
class
A
{
protected
String
a
;
public
A
()
{
a
=
""
;
a
=
""
;
}
public
String
a
()
{
...
...
@@ -39,7 +39,7 @@ public class TestInner3 extends AbstractTest {
public
String
i
()
{
String
result
=
TestInner3
.
this
.
i0
+
I0
.
this
.
i0
+
I0
.
this
.
i1
+
i0
+
i1
+
i2
;
A
a
=
new
A
()
{
public
String
a
()
{
...
...
@@ -82,5 +82,4 @@ public class TestInner3 extends AbstractTest {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestInner2
().
testRun
();
}
}
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