Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
4a92275a
J
jadx
项目概览
keyescgm
/
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,发现更多精彩内容 >>
提交
4a92275a
编写于
3月 29, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: allow use Eclipse compiler in tests (#536)
上级
6fca311d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
74 addition
and
77 deletion
+74
-77
build.gradle
build.gradle
+2
-0
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+44
-53
jadx-core/src/test/java/jadx/tests/api/compiler/StaticCompiler.java
...src/test/java/jadx/tests/api/compiler/StaticCompiler.java
+23
-20
jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill3.java
...st/java/jadx/tests/integration/arrays/TestArrayFill3.java
+5
-4
未找到文件。
build.gradle
浏览文件 @
4a92275a
...
...
@@ -43,6 +43,8 @@ allprojects {
testImplementation
'org.junit.jupiter:junit-jupiter-api:5.4.1'
testRuntimeOnly
'org.junit.jupiter:junit-jupiter-engine:5.4.1'
testCompile
'org.eclipse.jdt.core.compiler:ecj:4.6.1'
}
test
{
...
...
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
浏览文件 @
4a92275a
package
jadx.tests.api
;
import
jadx.api.JadxArgs
;
import
jadx.api.JadxDecompiler
;
import
jadx.api.JadxInternalAccess
;
import
jadx.core.ProcessClass
;
import
jadx.core.codegen.CodeGen
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.AttrList
;
import
jadx.core.dex.attributes.IAttributeNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.RootNode
;
import
jadx.core.dex.visitors.DepthTraversal
;
import
jadx.core.dex.visitors.IDexTreeVisitor
;
import
jadx.core.xmlgen.ResourceStorage
;
import
jadx.core.xmlgen.entry.ResourceEntry
;
import
jadx.tests.api.compiler.DynamicCompiler
;
import
jadx.tests.api.compiler.StaticCompiler
;
import
jadx.tests.api.utils.TestUtils
;
import
org.junit.jupiter.api.BeforeEach
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
...
...
@@ -21,26 +42,6 @@ import java.util.concurrent.TimeUnit;
import
java.util.concurrent.TimeoutException
;
import
java.util.jar.JarOutputStream
;
import
jadx.api.JadxArgs
;
import
jadx.api.JadxDecompiler
;
import
jadx.api.JadxInternalAccess
;
import
jadx.core.ProcessClass
;
import
jadx.core.codegen.CodeGen
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.AttrList
;
import
jadx.core.dex.attributes.IAttributeNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.RootNode
;
import
jadx.core.dex.visitors.DepthTraversal
;
import
jadx.core.dex.visitors.IDexTreeVisitor
;
import
jadx.core.xmlgen.ResourceStorage
;
import
jadx.core.xmlgen.entry.ResourceEntry
;
import
jadx.tests.api.compiler.DynamicCompiler
;
import
jadx.tests.api.compiler.StaticCompiler
;
import
jadx.tests.api.utils.TestUtils
;
import
static
jadx
.
core
.
utils
.
files
.
FileUtils
.
addFileToJar
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
...
...
@@ -58,30 +59,38 @@ public abstract class IntegrationTest extends TestUtils {
private
static
final
String
TEST_DIRECTORY
=
"src/test/java"
;
private
static
final
String
TEST_DIRECTORY2
=
"jadx-core/"
+
TEST_DIRECTORY
;
private
static
final
String
OUT_DIR
=
"test-out-tmp"
;
/**
* Run auto check method if defined:
* <pre>
* public void check() {}
* </pre>
*/
p
ublic
static
final
String
CHECK_METHOD_NAME
=
"check"
;
p
rivate
static
final
String
CHECK_METHOD_NAME
=
"check"
;
protected
JadxArgs
args
;
protected
boolean
deleteTmpFiles
=
true
;
protected
boolean
withDebugInfo
=
true
;
protected
boolean
unloadCls
=
true
;
protected
boolean
deleteTmpFiles
;
protected
boolean
withDebugInfo
;
protected
boolean
unloadCls
;
protected
boolean
compile
;
protected
boolean
useEclipseCompiler
;
protected
Map
<
Integer
,
String
>
resMap
=
Collections
.
emptyMap
();
protected
String
outDir
=
"test-out-tmp"
;
protected
boolean
compile
=
true
;
private
DynamicCompiler
dynamicCompiler
;
public
IntegrationTest
()
{
@BeforeEach
public
void
init
()
{
this
.
deleteTmpFiles
=
true
;
this
.
unloadCls
=
true
;
this
.
withDebugInfo
=
true
;
this
.
compile
=
true
;
this
.
useEclipseCompiler
=
false
;
this
.
resMap
=
Collections
.
emptyMap
();
args
=
new
JadxArgs
();
args
.
setOutDir
(
new
File
(
outDir
));
args
.
setOutDir
(
new
File
(
OUT_DIR
));
args
.
setShowInconsistentCode
(
true
);
args
.
setThreadsCount
(
1
);
args
.
setSkipResources
(
true
);
...
...
@@ -377,28 +386,6 @@ public abstract class IntegrationTest extends TestUtils {
throw
new
IOException
(
"Failed to create temp directory"
);
}
private
List
<
File
>
getClassFilesWithInners
(
Class
<?>
cls
)
{
List
<
File
>
list
=
new
ArrayList
<>();
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
list
;
}
private
List
<
File
>
compileClass
(
Class
<?>
cls
)
throws
IOException
{
String
clsFullName
=
cls
.
getName
();
String
rootClsName
;
...
...
@@ -418,7 +405,7 @@ public abstract class IntegrationTest extends TestUtils {
File
outTmp
=
createTempDir
(
"jadx-tmp-classes"
);
outTmp
.
deleteOnExit
();
List
<
File
>
files
=
StaticCompiler
.
compile
(
compileFileList
,
outTmp
,
withDebugInfo
);
List
<
File
>
files
=
StaticCompiler
.
compile
(
compileFileList
,
outTmp
,
withDebugInfo
,
useEclipseCompiler
);
files
.
forEach
(
File:
:
deleteOnExit
);
// remove classes which are parents for test class
String
clsName
=
clsFullName
.
substring
(
clsFullName
.
lastIndexOf
(
'.'
)
+
1
);
...
...
@@ -442,6 +429,10 @@ public abstract class IntegrationTest extends TestUtils {
this
.
withDebugInfo
=
false
;
}
protected
void
useEclipseCompiler
()
{
this
.
useEclipseCompiler
=
true
;
}
protected
void
setFallback
()
{
this
.
args
.
setFallbackMode
(
true
);
}
...
...
jadx-core/src/test/java/jadx/tests/api/compiler/StaticCompiler.java
浏览文件 @
4a92275a
package
jadx.tests.api.compiler
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
jadx.core.utils.files.FileUtils
;
import
org.eclipse.jdt.internal.compiler.tool.EclipseCompiler
;
import
javax.tools.FileObject
;
import
javax.tools.ForwardingJavaFileManager
;
...
...
@@ -17,18 +11,28 @@ import javax.tools.JavaFileObject;
import
javax.tools.SimpleJavaFileObject
;
import
javax.tools.StandardJavaFileManager
;
import
javax.tools.ToolProvider
;
import
jadx.core.utils.files.FileUtils
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
public
class
StaticCompiler
{
private
static
final
List
<
String
>
COMMON_ARGS
=
Arrays
.
asList
(
"-source 1.8 -target 1.8"
.
split
(
" "
));
public
static
List
<
File
>
compile
(
List
<
File
>
files
,
File
outDir
,
boolean
includeDebugInfo
)
throws
IOException
{
JavaCompiler
compiler
=
ToolProvider
.
getSystemJavaCompiler
();
if
(
compiler
==
null
)
{
throw
new
IllegalStateException
(
"Can not find compiler, please use JDK instead"
);
public
static
List
<
File
>
compile
(
List
<
File
>
files
,
File
outDir
,
boolean
includeDebugInfo
,
boolean
useEclipseCompiler
)
throws
IOException
{
JavaCompiler
compiler
;
if
(
useEclipseCompiler
)
{
compiler
=
new
EclipseCompiler
();
}
else
{
compiler
=
ToolProvider
.
getSystemJavaCompiler
();
if
(
compiler
==
null
)
{
throw
new
IllegalStateException
(
"Can not find compiler, please use JDK instead"
);
}
}
StandardJavaFileManager
fileManager
=
compiler
.
getStandardFileManager
(
null
,
null
,
null
);
Iterable
<?
extends
JavaFileObject
>
compilationUnits
=
fileManager
.
getJavaFileObjectsFromFiles
(
files
);
...
...
@@ -48,8 +52,8 @@ public class StaticCompiler {
}
private
static
class
StaticFileManager
extends
ForwardingJavaFileManager
<
StandardJavaFileManager
>
{
private
List
<
File
>
files
=
new
ArrayList
<>();
private
File
outDir
;
private
final
List
<
File
>
files
=
new
ArrayList
<>();
private
final
File
outDir
;
protected
StaticFileManager
(
StandardJavaFileManager
fileManager
,
File
outDir
)
{
super
(
fileManager
);
...
...
@@ -57,8 +61,7 @@ public class StaticCompiler {
}
@Override
public
JavaFileObject
getJavaFileForOutput
(
Location
location
,
String
className
,
JavaFileObject
.
Kind
kind
,
FileObject
sibling
)
throws
IOException
{
public
JavaFileObject
getJavaFileForOutput
(
Location
location
,
String
className
,
JavaFileObject
.
Kind
kind
,
FileObject
sibling
)
{
if
(
kind
==
JavaFileObject
.
Kind
.
CLASS
)
{
File
file
=
new
File
(
outDir
,
className
.
replace
(
'.'
,
'/'
)
+
".class"
);
files
.
add
(
file
);
...
...
@@ -73,7 +76,7 @@ public class StaticCompiler {
}
private
static
class
ClassFileObject
extends
SimpleJavaFileObject
{
private
File
file
;
private
final
File
file
;
protected
ClassFileObject
(
File
file
,
Kind
kind
)
{
super
(
file
.
toURI
(),
kind
);
...
...
jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill3.java
浏览文件 @
4a92275a
package
jadx.tests.integration.arrays
;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
...
...
@@ -18,11 +18,12 @@ public class TestArrayFill3 extends IntegrationTest {
}
@Test
@NotYetImplemented
public
void
test
()
{
useEclipseCompiler
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"return new byte[]"
));
assertThat
(
code
,
containsString
(
"return new byte[]
{0, 1, 2}
"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录