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
2eddbb91
Commit
2eddbb91
authored
Mar 26, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: move class renaming code from ClassInfo to RenameVisitor
parent
a2513240
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
28 deletions
+62
-28
ClsSet.java
jadx-core/src/main/java/jadx/core/clsp/ClsSet.java
+1
-1
ClassInfo.java
jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
+6
-11
ClassNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
+27
-7
RootNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
+5
-5
RenameVisitor.java
...e/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
+23
-4
No files found.
jadx-core/src/main/java/jadx/core/clsp/ClsSet.java
View file @
2eddbb91
...
...
@@ -96,7 +96,7 @@ public class ClsSet {
private
static
NClass
getCls
(
String
fullName
,
Map
<
String
,
NClass
>
names
)
{
NClass
id
=
names
.
get
(
fullName
);
if
(
id
==
null
&&
!
names
.
containsKey
(
fullName
))
{
LOG
.
warn
(
"Class not found: {}"
,
fullName
);
LOG
.
debug
(
"Class not found: {}"
,
fullName
);
}
return
id
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
View file @
2eddbb91
package
jadx
.
core
.
dex
.
info
;
import
jadx.core.Consts
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.nodes.DexNode
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
...
...
@@ -95,19 +94,15 @@ public final class ClassInfo {
}
else
{
parentClass
=
null
;
}
char
firstChar
=
clsName
.
charAt
(
0
);
if
(
Character
.
isDigit
(
firstChar
))
{
clsName
=
Consts
.
ANONYMOUS_CLASS_PREFIX
+
clsName
;
}
else
if
(
firstChar
==
'$'
)
{
clsName
=
"_"
+
clsName
;
}
this
.
name
=
clsName
;
this
.
fullName
=
makeFullClsName
(
clsName
);
}
public
String
makeFullClsName
(
String
shortName
)
{
if
(
parentClass
!=
null
)
{
this
.
fullName
=
parentClass
.
fullName
+
"."
+
clsName
;
}
else
{
this
.
fullName
=
pkg
.
isEmpty
()
?
clsName
:
pkg
+
"."
+
clsName
;
return
parentClass
.
fullName
+
"."
+
shortName
;
}
return
pkg
.
isEmpty
()
?
shortName
:
pkg
+
"."
+
shortName
;
}
public
String
getFullPath
()
{
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
View file @
2eddbb91
...
...
@@ -112,13 +112,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
int
sfIdx
=
cls
.
getSourceFileIndex
();
if
(
sfIdx
!=
DexNode
.
NO_INDEX
)
{
String
fileName
=
dex
.
getString
(
sfIdx
);
if
(
clsInfo
!=
null
&&
!
clsInfo
.
getFullName
().
contains
(
fileName
.
replace
(
".java"
,
""
))
&&
!
fileName
.
equals
(
"SourceFile"
)
&&
!
fileName
.
equals
(
"\""
))
{
this
.
addAttr
(
new
SourceFileAttr
(
fileName
));
LOG
.
debug
(
"Class '{}' compiled from '{}'"
,
this
,
fileName
);
}
addSourceFilenameAttr
(
fileName
);
}
// restore original access flags from dalvik annotation if present
...
...
@@ -225,6 +219,32 @@ public class ClassNode extends LineAttrNode implements ILoadable {
}
}
private
void
addSourceFilenameAttr
(
String
fileName
)
{
if
(
fileName
==
null
)
{
return
;
}
if
(
fileName
.
endsWith
(
".java"
))
{
fileName
=
fileName
.
substring
(
0
,
fileName
.
length
()
-
5
);
}
if
(
fileName
.
isEmpty
()
||
fileName
.
equals
(
"SourceFile"
)
||
fileName
.
equals
(
"\""
))
{
return
;
}
if
(
clsInfo
!=
null
)
{
String
name
=
clsInfo
.
getShortName
();
if
(
fileName
.
equals
(
name
))
{
return
;
}
if
(
fileName
.
contains
(
"$"
)
&&
fileName
.
endsWith
(
"$"
+
name
))
{
return
;
}
}
this
.
addAttr
(
new
SourceFileAttr
(
fileName
));
LOG
.
debug
(
"Class '{}' compiled from '{}'"
,
this
,
fileName
);
}
@Override
public
void
load
()
{
for
(
MethodNode
mth
:
getMethods
())
{
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
View file @
2eddbb91
...
...
@@ -137,11 +137,11 @@ public class RootNode {
public
List
<
ClassNode
>
getClasses
(
boolean
includeInner
)
{
List
<
ClassNode
>
classes
=
new
ArrayList
<
ClassNode
>();
for
(
DexNode
dex
Node
:
dexNodes
)
{
for
(
ClassNode
cls
:
dexNode
.
getClasses
()
)
{
if
(
includeInner
)
{
classes
.
add
(
cls
);
}
else
{
for
(
DexNode
dex
:
dexNodes
)
{
if
(
includeInner
)
{
classes
.
addAll
(
dex
.
getClasses
());
}
else
{
for
(
ClassNode
cls
:
dex
.
getClasses
())
{
if
(!
cls
.
getClassInfo
().
isInner
())
{
classes
.
add
(
cls
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
View file @
2eddbb91
package
jadx
.
core
.
dex
.
visitors
;
import
jadx.api.IJadxArgs
;
import
jadx.core.Consts
;
import
jadx.core.codegen.TypeGen
;
import
jadx.core.deobf.Deobfuscator
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.info.FieldInfo
;
import
jadx.core.dex.info.MethodInfo
;
import
jadx.core.dex.instructions.args.ArgType
;
...
...
@@ -17,11 +19,8 @@ import java.io.File;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.jetbrains.annotations.NotNull
;
public
class
RenameVisitor
extends
AbstractVisitor
{
@NotNull
private
Deobfuscator
deobfuscator
;
@Override
...
...
@@ -29,9 +28,14 @@ public class RenameVisitor extends AbstractVisitor {
IJadxArgs
args
=
root
.
getArgs
();
File
deobfMapFile
=
new
File
(
args
.
getOutDir
(),
"deobf_map.jobf"
);
deobfuscator
=
new
Deobfuscator
(
args
,
root
.
getDexNodes
(),
deobfMapFile
);
if
(
args
.
isDeobfuscationOn
())
{
boolean
deobfuscationOn
=
args
.
isDeobfuscationOn
();
if
(
deobfuscationOn
)
{
// TODO: check classes for case sensitive names (issue #24)
deobfuscator
.
execute
();
}
else
{
for
(
ClassNode
classNode
:
root
.
getClasses
(
true
))
{
checkClassName
(
classNode
);
}
}
}
...
...
@@ -45,6 +49,21 @@ public class RenameVisitor extends AbstractVisitor {
return
false
;
}
private
void
checkClassName
(
ClassNode
cls
)
{
ClassInfo
classInfo
=
cls
.
getClassInfo
();
String
clsName
=
classInfo
.
getAlias
().
getShortName
();
String
newShortName
=
null
;
char
firstChar
=
clsName
.
charAt
(
0
);
if
(
Character
.
isDigit
(
firstChar
))
{
newShortName
=
Consts
.
ANONYMOUS_CLASS_PREFIX
+
clsName
;
}
else
if
(
firstChar
==
'$'
)
{
newShortName
=
"C"
+
clsName
;
}
if
(
newShortName
!=
null
)
{
classInfo
.
rename
(
cls
.
dex
(),
classInfo
.
makeFullClsName
(
newShortName
));
}
}
private
void
checkFields
(
ClassNode
cls
)
{
Set
<
String
>
names
=
new
HashSet
<
String
>();
for
(
FieldNode
field
:
cls
.
getFields
())
{
...
...
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