Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
f72abb28
J
jadx
项目概览
2301_76393173
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f72abb28
编写于
3月 22, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: add test methods for load and check classes from smali files
上级
2c072539
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
56 addition
and
19 deletion
+56
-19
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+17
-7
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
+36
-7
jadx-core/src/test/java/jadx/tests/integration/inner/TestSyntheticMthRename.java
.../jadx/tests/integration/inner/TestSyntheticMthRename.java
+1
-3
jadx-core/src/test/java/jadx/tests/integration/others/TestBadMethodAccessModifiers.java
...ests/integration/others/TestBadMethodAccessModifiers.java
+2
-2
未找到文件。
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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() {"
)));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录