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
36cfc9d1
Commit
36cfc9d1
authored
Nov 12, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core tests: add inner classes in internal tests
parent
b2f189b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
19 deletions
+60
-19
InternalJadxTest.java
jadx-core/src/test/java/jadx/api/InternalJadxTest.java
+28
-19
TestInnerClass.java
...ore/src/test/java/jadx/tests/internal/TestInnerClass.java
+32
-0
No files found.
jadx-core/src/test/java/jadx/api/InternalJadxTest.java
View file @
36cfc9d1
...
...
@@ -11,7 +11,9 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarOutputStream
;
...
...
@@ -74,33 +76,39 @@ public abstract class InternalJadxTest {
}
public
File
getJarForClass
(
Class
<?>
cls
)
throws
IOException
{
File
classFile
=
getClassFile
(
cls
);
String
shortClsFileName
=
cls
.
getName
().
replace
(
'.'
,
'/'
)
+
".class"
;
String
path
=
cls
.
getPackage
().
getName
().
replace
(
'.'
,
'/'
);
List
<
File
>
list
=
getClassFilesWithInners
(
cls
)
;
File
temp
=
File
.
createTempFile
(
"jadx-tmp-"
,
System
.
nanoTime
()
+
".jar"
);
JarOutputStream
jo
=
new
JarOutputStream
(
new
FileOutputStream
(
temp
));
add
(
classFile
,
shortClsFileName
,
jo
);
for
(
File
file
:
list
)
{
add
(
file
,
path
+
"/"
+
file
.
getName
(),
jo
);
}
jo
.
close
();
temp
.
deleteOnExit
();
return
temp
;
}
private
File
getClassFile
(
Class
<?>
cls
)
{
String
path
=
cutPackage
(
cls
)
+
".class"
;
URL
resource
=
cls
.
getResource
(
path
);
if
(
resource
==
null
)
{
fail
(
"Class file not found: "
+
path
);
}
if
(!
"file"
.
equalsIgnoreCase
(
resource
.
getProtocol
()))
{
fail
(
"Class is not stored in a file."
);
private
List
<
File
>
getClassFilesWithInners
(
Class
<?>
cls
)
{
List
<
File
>
list
=
new
ArrayList
<
File
>();
String
pkgName
=
cls
.
getPackage
().
getName
();
URL
pkgResource
=
ClassLoader
.
getSystemClassLoader
().
getResource
(
pkgName
.
replace
(
'.'
,
'/'
));
if
(
pkgResource
!=
null
)
{
try
{
String
clsName
=
cls
.
getName
();
File
directory
=
new
File
(
pkgResource
.
toURI
());
String
[]
files
=
directory
.
list
();
for
(
String
file
:
files
)
{
String
fullName
=
pkgName
+
"."
+
file
;
if
(
fullName
.
startsWith
(
clsName
))
{
list
.
add
(
new
File
(
directory
,
file
));
}
}
}
catch
(
URISyntaxException
e
)
{
fail
(
e
.
getMessage
());
}
}
return
new
File
(
resource
.
getPath
());
}
private
String
cutPackage
(
Class
<?>
cls
)
{
String
longName
=
cls
.
getName
();
String
pkg
=
cls
.
getPackage
().
getName
();
return
longName
.
substring
(
pkg
.
length
()
+
1
,
longName
.
length
());
return
list
;
}
private
void
add
(
File
source
,
String
entryName
,
JarOutputStream
target
)
throws
IOException
{
...
...
@@ -114,8 +122,9 @@ public abstract class InternalJadxTest {
byte
[]
buffer
=
new
byte
[
1024
];
while
(
true
)
{
int
count
=
in
.
read
(
buffer
);
if
(
count
==
-
1
)
if
(
count
==
-
1
)
{
break
;
}
target
.
write
(
buffer
,
0
,
count
);
}
target
.
closeEntry
();
...
...
jadx-core/src/test/java/jadx/tests/internal/TestInnerClass.java
0 → 100644
View file @
36cfc9d1
package
jadx
.
tests
.
internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestInnerClass
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
class
Inner
{
public
class
Inner2
{
}
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"Inner"
));
assertThat
(
code
,
containsString
(
"Inner2"
));
// assertThat(code, not(containsString("this$0")));
// assertThat(code, not(containsString("super()")));
// assertThat(code, not(containsString("/* synthetic */")));
}
}
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