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
f72abb28
Commit
f72abb28
authored
Mar 22, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add test methods for load and check classes from smali files
parent
2c072539
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
19 deletions
+56
-19
IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+17
-7
SmaliTest.java
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
+36
-7
TestSyntheticMthRename.java
.../jadx/tests/integration/inner/TestSyntheticMthRename.java
+1
-3
TestBadMethodAccessModifiers.java
...ests/integration/others/TestBadMethodAccessModifiers.java
+2
-2
No files found.
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
View file @
f72abb28
...
...
@@ -91,9 +91,21 @@ public abstract class IntegrationTest extends TestUtils {
}
public
ClassNode
getClassNodeFromFile
(
File
file
,
String
clsName
)
{
JadxDecompiler
d
=
loadFiles
(
Collections
.
singletonList
(
file
));
RootNode
root
=
JadxInternalAccess
.
getRoot
(
d
);
ClassNode
cls
=
root
.
searchClassByName
(
clsName
);
assertThat
(
"Class not found: "
+
clsName
,
cls
,
notNullValue
());
assertThat
(
clsName
,
is
(
cls
.
getClassInfo
().
getFullName
()));
decompileAndCheckCls
(
d
,
cls
);
return
cls
;
}
protected
JadxDecompiler
loadFiles
(
List
<
File
>
inputFiles
)
{
JadxDecompiler
d
=
null
;
try
{
args
.
setInputFiles
(
Collections
.
singletonList
(
file
)
);
args
.
setInputFiles
(
inputFiles
);
d
=
new
JadxDecompiler
(
args
);
d
.
load
();
}
catch
(
Exception
e
)
{
...
...
@@ -102,11 +114,10 @@ public abstract class IntegrationTest extends TestUtils {
}
RootNode
root
=
JadxInternalAccess
.
getRoot
(
d
);
insertResources
(
root
);
return
d
;
}
ClassNode
cls
=
root
.
searchClassByName
(
clsName
);
assertThat
(
"Class not found: "
+
clsName
,
cls
,
notNullValue
());
assertThat
(
clsName
,
is
(
cls
.
getClassInfo
().
getFullName
()));
protected
void
decompileAndCheckCls
(
JadxDecompiler
d
,
ClassNode
cls
)
{
if
(
unloadCls
)
{
decompile
(
d
,
cls
);
}
else
{
...
...
@@ -119,8 +130,7 @@ public abstract class IntegrationTest extends TestUtils {
checkCode
(
cls
);
compile
(
cls
);
runAutoCheck
(
clsName
);
return
cls
;
runAutoCheck
(
cls
.
getClassInfo
().
getFullName
());
}
private
void
insertResources
(
RootNode
root
)
{
...
...
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
View file @
f72abb28
...
...
@@ -6,11 +6,16 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.jetbrains.annotations.Nullable
;
import
org.jf.smali.Smali
;
import
org.jf.smali.SmaliOptions
;
import
jadx.api.JadxDecompiler
;
import
jadx.core.dex.nodes.ClassNode
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
abstract
class
SmaliTest
extends
IntegrationTest
{
private
static
final
String
SMALI_TESTS_PROJECT
=
"jadx-core"
;
...
...
@@ -24,6 +29,10 @@ public abstract class SmaliTest extends IntegrationTest {
return
getClassNodeFromFile
(
outDex
,
clsName
);
}
protected
ClassNode
getClassNodeFromSmali
(
String
clsName
)
{
return
getClassNodeFromSmali
(
clsName
,
clsName
);
}
protected
ClassNode
getClassNodeFromSmaliWithPath
(
String
path
,
String
clsName
)
{
return
getClassNodeFromSmali
(
path
+
File
.
separatorChar
+
clsName
,
clsName
);
}
...
...
@@ -32,17 +41,37 @@ public abstract class SmaliTest extends IntegrationTest {
return
getClassNodeFromSmali
(
pkg
+
File
.
separatorChar
+
clsName
,
pkg
+
'.'
+
clsName
);
}
protected
ClassNode
getClassNodeFromSmaliFiles
(
String
pkg
,
String
testName
,
String
clsName
,
String
...
smaliFileNames
)
{
protected
ClassNode
getClassNodeFromSmaliFiles
(
String
pkg
,
String
testName
,
String
clsName
)
{
File
outDex
=
createTempFile
(
".dex"
);
List
<
File
>
smaliFiles
=
Arrays
.
stream
(
smaliFileNames
)
.
map
(
file
->
getSmaliFile
(
pkg
+
File
.
separatorChar
+
testName
+
File
.
separatorChar
+
file
))
.
collect
(
Collectors
.
toList
());
compileSmali
(
outDex
,
smaliFiles
);
compileSmali
(
outDex
,
collectSmaliFiles
(
pkg
,
testName
));
return
getClassNodeFromFile
(
outDex
,
pkg
+
"."
+
clsName
);
}
protected
ClassNode
getClassNodeFromSmali
(
String
clsName
)
{
return
getClassNodeFromSmali
(
clsName
,
clsName
);
protected
JadxDecompiler
loadSmaliFile
(
String
pkg
,
String
smaliFileName
)
{
File
outDex
=
createTempFile
(
".dex"
);
compileSmali
(
outDex
,
Collections
.
singletonList
(
getSmaliFile
(
pkg
+
File
.
separatorChar
+
smaliFileName
)));
return
loadFiles
(
Collections
.
singletonList
(
outDex
));
}
protected
JadxDecompiler
loadSmaliFiles
(
String
pkg
,
String
testNameDir
)
{
File
outDex
=
createTempFile
(
".dex"
);
compileSmali
(
outDex
,
collectSmaliFiles
(
pkg
,
testNameDir
));
return
loadFiles
(
Collections
.
singletonList
(
outDex
));
}
private
List
<
File
>
collectSmaliFiles
(
String
pkg
,
@Nullable
String
testDir
)
{
String
smaliFilesDir
;
if
(
testDir
==
null
)
{
smaliFilesDir
=
pkg
+
File
.
separatorChar
;
}
else
{
smaliFilesDir
=
pkg
+
File
.
separatorChar
+
testDir
+
File
.
separatorChar
;
}
File
smaliDir
=
new
File
(
SMALI_TESTS_DIR
,
smaliFilesDir
);
String
[]
smaliFileNames
=
smaliDir
.
list
((
dir
,
name
)
->
name
.
endsWith
(
".smali"
));
assertThat
(
"Smali files not found"
,
smaliFileNames
,
notNullValue
());
return
Arrays
.
stream
(
smaliFileNames
)
.
map
(
file
->
new
File
(
smaliDir
,
file
))
.
collect
(
Collectors
.
toList
());
}
private
static
File
getSmaliFile
(
String
baseName
)
{
...
...
jadx-core/src/test/java/jadx/tests/integration/inner/TestSyntheticMthRename.java
View file @
f72abb28
...
...
@@ -33,9 +33,7 @@ public class TestSyntheticMthRename extends SmaliTest {
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNodeFromSmaliFiles
(
"inner"
,
"TestSyntheticMthRename"
,
"TestCls"
,
"TestCls"
,
"TestCls$I"
,
"TestCls$A"
);
ClassNode
cls
=
getClassNodeFromSmaliFiles
(
"inner"
,
"TestSyntheticMthRename"
,
"TestCls"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"public String call(Runnable... p) {"
));
...
...
jadx-core/src/test/java/jadx/tests/integration/others/TestBadMethodAccessModifiers.java
View file @
f72abb28
...
...
@@ -24,10 +24,10 @@ public class TestBadMethodAccessModifiers extends SmaliTest {
}
}
*/
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNodeFromSmaliFiles
(
"others"
,
"TestBadMethodAccessModifiers"
,
"TestCls"
,
"TestCls$A"
,
"TestCls$B"
,
"TestCls"
);
ClassNode
cls
=
getClassNodeFromSmaliFiles
(
"others"
,
"TestBadMethodAccessModifiers"
,
"TestCls"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"protected void test() {"
)));
...
...
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