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
e4f4de6c
Commit
e4f4de6c
authored
Apr 04, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix imports for inner classes
parent
e6aa85e0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
44 deletions
+50
-44
ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+42
-32
ClassInfo.java
jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
+4
-3
RenameVisitor.java
...e/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
+4
-5
TestAnonymousClass2.java
...ava/jadx/tests/integration/inner/TestAnonymousClass2.java
+0
-2
TestAnonymousClass4.java
...ava/jadx/tests/integration/inner/TestAnonymousClass4.java
+0
-2
No files found.
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
View file @
e4f4de6c
...
...
@@ -462,44 +462,44 @@ public class ClassGen {
if
(
fallback
)
{
return
fullName
;
}
fullName
=
extClsInfo
.
getFullName
();
String
shortName
=
extClsInfo
.
getShortName
();
if
(
extClsInfo
.
getPackage
().
equals
(
"java.lang"
)
&&
extClsInfo
.
getParentClass
()
==
null
)
{
return
shortName
;
}
else
{
// don't add import if this class inner for current class
if
(
isClassInnerFor
(
extClsInfo
,
useCls
))
{
return
shortName
;
}
// don't add import if this class from same package
if
(
extClsInfo
.
getPackage
().
equals
(
useCls
.
getPackage
())
&&
!
extClsInfo
.
isInner
())
{
return
shortName
;
}
// don't add import if class not public (must be accessed using inheritance)
ClassNode
classNode
=
cls
.
dex
().
resolveClass
(
extClsInfo
);
if
(
classNode
!=
null
&&
!
classNode
.
getAccessFlags
().
isPublic
())
{
return
shortName
;
}
if
(
searchCollision
(
cls
.
dex
(),
useCls
,
extClsInfo
))
{
return
fullName
;
}
if
(
extClsInfo
.
getPackage
().
equals
(
useCls
.
getPackage
()))
{
fullName
=
extClsInfo
.
getNameWithoutPackage
();
}
for
(
ClassInfo
importCls
:
getImports
())
{
if
(!
importCls
.
equals
(
extClsInfo
)
&&
importCls
.
getShortName
().
equals
(
shortName
))
{
if
(
extClsInfo
.
isInner
())
{
String
parent
=
useClassInternal
(
useCls
,
extClsInfo
.
getParentClass
().
getAlias
());
return
parent
+
"."
+
shortName
;
}
else
{
return
fullName
;
}
}
if
(
isClassInnerFor
(
useCls
,
extClsInfo
))
{
return
shortName
;
}
if
(
isBothClassesInOneTopClass
(
useCls
,
extClsInfo
))
{
return
shortName
;
}
// don't add import if this class from same package
if
(
extClsInfo
.
getPackage
().
equals
(
useCls
.
getPackage
())
&&
!
extClsInfo
.
isInner
())
{
return
shortName
;
}
// don't add import if class not public (must be accessed using inheritance)
ClassNode
classNode
=
cls
.
dex
().
resolveClass
(
extClsInfo
);
if
(
classNode
!=
null
&&
!
classNode
.
getAccessFlags
().
isPublic
())
{
return
shortName
;
}
if
(
searchCollision
(
cls
.
dex
(),
useCls
,
extClsInfo
))
{
return
fullName
;
}
if
(
extClsInfo
.
getPackage
().
equals
(
useCls
.
getPackage
()))
{
fullName
=
extClsInfo
.
getNameWithoutPackage
();
}
for
(
ClassInfo
importCls
:
getImports
())
{
if
(!
importCls
.
equals
(
extClsInfo
)
&&
importCls
.
getShortName
().
equals
(
shortName
))
{
if
(
extClsInfo
.
isInner
())
{
String
parent
=
useClassInternal
(
useCls
,
extClsInfo
.
getParentClass
().
getAlias
());
return
parent
+
"."
+
shortName
;
}
else
{
return
fullName
;
}
}
addImport
(
extClsInfo
);
return
shortName
;
}
addImport
(
extClsInfo
);
return
shortName
;
}
private
void
addImport
(
ClassInfo
classInfo
)
{
...
...
@@ -518,6 +518,16 @@ public class ClassGen {
}
}
private
static
boolean
isBothClassesInOneTopClass
(
ClassInfo
useCls
,
ClassInfo
extClsInfo
)
{
ClassInfo
a
=
useCls
.
getTopParentClass
();
ClassInfo
b
=
extClsInfo
.
getTopParentClass
();
if
(
a
!=
null
)
{
return
a
.
equals
(
b
);
}
// useCls - is a top class
return
useCls
.
equals
(
b
);
}
private
static
boolean
isClassInnerFor
(
ClassInfo
inner
,
ClassInfo
parent
)
{
if
(
inner
.
isInner
())
{
ClassInfo
p
=
inner
.
getParentClass
();
...
...
jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
View file @
e4f4de6c
...
...
@@ -95,12 +95,13 @@ public final class ClassInfo {
parentClass
=
null
;
}
this
.
name
=
clsName
;
this
.
fullName
=
makeFullClsName
(
clsName
);
this
.
fullName
=
makeFullClsName
(
clsName
,
false
);
}
public
String
makeFullClsName
(
String
shortName
)
{
public
String
makeFullClsName
(
String
shortName
,
boolean
raw
)
{
if
(
parentClass
!=
null
)
{
return
parentClass
.
fullName
+
"."
+
shortName
;
String
innerSep
=
raw
?
"$"
:
"."
;
return
parentClass
.
makeFullClsName
(
parentClass
.
getShortName
(),
raw
)
+
innerSep
+
shortName
;
}
return
pkg
.
isEmpty
()
?
shortName
:
pkg
+
"."
+
shortName
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
View file @
e4f4de6c
...
...
@@ -32,10 +32,9 @@ public class RenameVisitor extends AbstractVisitor {
if
(
deobfuscationOn
)
{
// TODO: check classes for case sensitive names (issue #24)
deobfuscator
.
execute
();
}
else
{
for
(
ClassNode
classNode
:
root
.
getClasses
(
true
))
{
checkClassName
(
classNode
);
}
}
for
(
ClassNode
classNode
:
root
.
getClasses
(
true
))
{
checkClassName
(
classNode
);
}
}
...
...
@@ -60,7 +59,7 @@ public class RenameVisitor extends AbstractVisitor {
newShortName
=
"C"
+
clsName
;
}
if
(
newShortName
!=
null
)
{
classInfo
.
rename
(
cls
.
dex
(),
classInfo
.
makeFullClsName
(
newShortName
));
classInfo
.
rename
(
cls
.
dex
(),
classInfo
.
makeFullClsName
(
newShortName
,
true
));
}
}
...
...
jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass2.java
View file @
e4f4de6c
...
...
@@ -3,7 +3,6 @@ package jadx.tests.integration.inner;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
...
...
@@ -48,7 +47,6 @@ public class TestAnonymousClass2 extends IntegrationTest {
}
@Test
@Ignore
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
...
...
jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass4.java
View file @
e4f4de6c
...
...
@@ -3,7 +3,6 @@ package jadx.tests.integration.inner;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
...
...
@@ -33,7 +32,6 @@ public class TestAnonymousClass4 extends IntegrationTest {
}
@Test
@Ignore
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
...
...
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