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
55fc4983
Commit
55fc4983
authored
Mar 27, 2019
by
Ahmed Ashour
Committed by
skylot
Mar 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use Path instead of File (PR #527)
parent
ba6dd081
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
21 deletions
+29
-21
DeobfPresets.java
jadx-core/src/main/java/jadx/core/deobf/DeobfPresets.java
+16
-13
Deobfuscator.java
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
+6
-0
RenameVisitor.java
...e/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
+7
-8
No files found.
jadx-core/src/main/java/jadx/core/deobf/DeobfPresets.java
View file @
55fc4983
package
jadx
.
core
.
deobf
;
import
java.io.File
;
import
static
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
;
import
java.io.IOException
;
import
java.nio.charset.Charset
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.io.FileUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -19,16 +22,16 @@ import jadx.core.dex.info.MethodInfo;
class
DeobfPresets
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
DeobfPresets
.
class
);
private
static
final
String
MAP_FILE_CHARSET
=
"UTF-8"
;
private
static
final
Charset
MAP_FILE_CHARSET
=
UTF_8
;
private
final
Deobfuscator
deobfuscator
;
private
final
File
deobfMapFile
;
private
final
Path
deobfMapFile
;
private
final
Map
<
String
,
String
>
clsPresetMap
=
new
HashMap
<>();
private
final
Map
<
String
,
String
>
fldPresetMap
=
new
HashMap
<>();
private
final
Map
<
String
,
String
>
mthPresetMap
=
new
HashMap
<>();
public
DeobfPresets
(
Deobfuscator
deobfuscator
,
File
deobfMapFile
)
{
public
DeobfPresets
(
Deobfuscator
deobfuscator
,
Path
deobfMapFile
)
{
this
.
deobfuscator
=
deobfuscator
;
this
.
deobfMapFile
=
deobfMapFile
;
}
...
...
@@ -37,12 +40,12 @@ class DeobfPresets {
* Loads deobfuscator presets
*/
public
void
load
()
{
if
(!
deobfMapFile
.
exists
(
))
{
if
(!
Files
.
exists
(
deobfMapFile
))
{
return
;
}
LOG
.
info
(
"Loading obfuscation map from: {}"
,
deobfMapFile
.
getAbsoluteFile
());
LOG
.
info
(
"Loading obfuscation map from: {}"
,
deobfMapFile
.
toAbsolutePath
());
try
{
List
<
String
>
lines
=
File
Utils
.
read
Lines
(
deobfMapFile
,
MAP_FILE_CHARSET
);
List
<
String
>
lines
=
File
s
.
readAll
Lines
(
deobfMapFile
,
MAP_FILE_CHARSET
);
for
(
String
l
:
lines
)
{
l
=
l
.
trim
();
if
(
l
.
isEmpty
()
||
l
.
startsWith
(
"#"
))
{
...
...
@@ -65,7 +68,7 @@ class DeobfPresets {
}
}
}
catch
(
IOException
e
)
{
LOG
.
error
(
"Failed to load deobfuscation map file '{}'"
,
deobfMapFile
.
get
AbsolutePath
(),
e
);
LOG
.
error
(
"Failed to load deobfuscation map file '{}'"
,
deobfMapFile
.
to
AbsolutePath
(),
e
);
}
}
...
...
@@ -79,18 +82,18 @@ class DeobfPresets {
public
void
save
(
boolean
forceSave
)
{
try
{
if
(
deobfMapFile
.
exists
(
))
{
if
(
Files
.
exists
(
deobfMapFile
))
{
if
(
forceSave
)
{
dumpMapping
();
}
else
{
LOG
.
warn
(
"Deobfuscation map file '{}' exists. Use command line option '--deobf-rewrite-cfg' to rewrite it"
,
deobfMapFile
.
get
AbsolutePath
());
deobfMapFile
.
to
AbsolutePath
());
}
}
else
{
dumpMapping
();
}
}
catch
(
IOException
e
)
{
LOG
.
error
(
"Failed to load deobfuscation map file '{}'"
,
deobfMapFile
.
get
AbsolutePath
(),
e
);
LOG
.
error
(
"Failed to load deobfuscation map file '{}'"
,
deobfMapFile
.
to
AbsolutePath
(),
e
);
}
}
...
...
@@ -122,7 +125,7 @@ class DeobfPresets {
list
.
add
(
String
.
format
(
"m %s = %s"
,
mth
.
getRawFullId
(),
mth
.
getAlias
()));
}
Collections
.
sort
(
list
);
File
Utils
.
writeLines
(
deobfMapFile
,
MAP_FILE_CHARSET
,
list
);
File
s
.
write
(
deobfMapFile
,
list
,
MAP_FILE_CHARSET
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Deobfuscation map file saved as: {}"
,
deobfMapFile
);
}
...
...
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
View file @
55fc4983
package
jadx
.
core
.
deobf
;
import
java.io.File
;
import
java.nio.file.Path
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
...
...
@@ -62,7 +63,12 @@ public class Deobfuscator {
private
int
fldIndex
=
0
;
private
int
mthIndex
=
0
;
@Deprecated
public
Deobfuscator
(
JadxArgs
args
,
@NotNull
List
<
DexNode
>
dexNodes
,
File
deobfMapFile
)
{
this
(
args
,
dexNodes
,
deobfMapFile
.
toPath
());
}
public
Deobfuscator
(
JadxArgs
args
,
@NotNull
List
<
DexNode
>
dexNodes
,
Path
deobfMapFile
)
{
this
.
args
=
args
;
this
.
dexNodes
=
dexNodes
;
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
View file @
55fc4983
package
jadx
.
core
.
dex
.
visitors
;
import
java.
io.File
;
import
java.
nio.file.Path
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.apache.commons.io.FilenameUtils
;
import
jadx.api.JadxArgs
;
import
jadx.core.Consts
;
import
jadx.core.deobf.Deobfuscator
;
...
...
@@ -33,13 +31,14 @@ public class RenameVisitor extends AbstractVisitor {
return
;
}
InputFile
firstInputFile
=
dexNodes
.
get
(
0
).
getDexFile
().
getInputFile
();
String
firstInputFileName
=
firstInputFile
.
getFile
().
getAbsolutePath
();
String
inputPath
=
FilenameUtils
.
getFullPathNoEndSeparator
(
firstInputFileName
);
String
inputName
=
FilenameUtils
.
getBaseName
(
firstInputFileName
);
Path
inputFilePath
=
firstInputFile
.
getFile
().
toPath
();
String
inputName
=
inputFilePath
.
getFileName
().
toString
();
inputName
=
inputName
.
substring
(
0
,
inputName
.
lastIndexOf
(
'.'
));
File
deobfMapFile
=
new
File
(
inputPath
,
inputName
+
".jobf"
);
Path
deobfMapPath
=
inputFilePath
.
getParent
().
resolve
(
inputName
+
".jobf"
);
JadxArgs
args
=
root
.
getArgs
();
deobfuscator
=
new
Deobfuscator
(
args
,
dexNodes
,
deobfMap
File
);
deobfuscator
=
new
Deobfuscator
(
args
,
dexNodes
,
deobfMap
Path
);
boolean
deobfuscationOn
=
args
.
isDeobfuscationOn
();
if
(
deobfuscationOn
)
{
deobfuscator
.
execute
();
...
...
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