Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
418df2fd
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,发现更多精彩内容 >>
未验证
提交
418df2fd
编写于
10月 14, 2021
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests: allow to set target java version, use D8 as fallback converter
上级
cd153c76
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
109 addition
and
9 deletion
+109
-9
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+8
-2
jadx-core/src/test/java/jadx/tests/api/compiler/JavaUtils.java
...core/src/test/java/jadx/tests/api/compiler/JavaUtils.java
+28
-0
jadx-core/src/test/java/jadx/tests/api/compiler/StaticCompiler.java
...src/test/java/jadx/tests/api/compiler/StaticCompiler.java
+12
-5
jadx-plugins/jadx-java-convert/build.gradle
jadx-plugins/jadx-java-convert/build.gradle
+1
-0
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/D8Converter.java
...main/java/jadx/plugins/input/javaconvert/D8Converter.java
+53
-0
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/DxConverter.java
...main/java/jadx/plugins/input/javaconvert/DxConverter.java
+1
-1
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertLoader.java
...ava/jadx/plugins/input/javaconvert/JavaConvertLoader.java
+6
-1
未找到文件。
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
浏览文件 @
418df2fd
...
...
@@ -87,9 +87,11 @@ public abstract class IntegrationTest extends TestUtils {
protected
JadxArgs
args
;
protected
boolean
withDebugInfo
;
protected
boolean
compile
;
protected
boolean
withDebugInfo
;
protected
boolean
useEclipseCompiler
;
private
int
targetJavaVersion
=
8
;
protected
Map
<
Integer
,
String
>
resMap
=
Collections
.
emptyMap
();
private
boolean
allowWarnInCode
;
...
...
@@ -458,7 +460,7 @@ public abstract class IntegrationTest extends TestUtils {
List
<
File
>
compileFileList
=
Collections
.
singletonList
(
file
);
Path
outTmp
=
FileUtils
.
createTempDir
(
"jadx-tmp-classes"
);
List
<
File
>
files
=
StaticCompiler
.
compile
(
compileFileList
,
outTmp
.
toFile
(),
withDebugInfo
,
useEclipseCompiler
);
List
<
File
>
files
=
StaticCompiler
.
compile
(
compileFileList
,
outTmp
.
toFile
(),
withDebugInfo
,
useEclipseCompiler
,
targetJavaVersion
);
files
.
forEach
(
File:
:
deleteOnExit
);
// remove classes which are parents for test class
String
clsName
=
clsFullName
.
substring
(
clsFullName
.
lastIndexOf
(
'.'
)
+
1
);
...
...
@@ -493,6 +495,10 @@ public abstract class IntegrationTest extends TestUtils {
this
.
useEclipseCompiler
=
true
;
}
protected
void
useTargetJavaVersion
(
int
version
)
{
this
.
targetJavaVersion
=
version
;
}
protected
void
setFallback
()
{
disableCompilation
();
this
.
args
.
setFallbackMode
(
true
);
...
...
jadx-core/src/test/java/jadx/tests/api/compiler/JavaUtils.java
0 → 100644
浏览文件 @
418df2fd
package
jadx.tests.api.compiler
;
import
org.apache.commons.lang3.SystemUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
JavaUtils
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
JavaUtils
.
class
);
public
static
final
int
JAVA_VERSION_INT
=
getJavaVersionInt
();
private
static
int
getJavaVersionInt
()
{
String
javaSpecVerStr
=
SystemUtils
.
JAVA_SPECIFICATION_VERSION
;
if
(
javaSpecVerStr
==
null
)
{
LOG
.
warn
(
"Unknown current java specification version, use 8 as fallback"
);
return
8
;
// fallback version
}
if
(
javaSpecVerStr
.
startsWith
(
"1."
))
{
return
Integer
.
parseInt
(
javaSpecVerStr
.
substring
(
2
));
}
return
Integer
.
parseInt
(
javaSpecVerStr
);
}
public
static
boolean
checkJavaVersion
(
int
requiredVersion
)
{
return
JAVA_VERSION_INT
>=
requiredVersion
;
}
}
jadx-core/src/test/java/jadx/tests/api/compiler/StaticCompiler.java
浏览文件 @
418df2fd
...
...
@@ -5,7 +5,6 @@ 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
;
...
...
@@ -24,10 +23,13 @@ import jadx.core.utils.files.FileUtils;
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
,
boolean
useEclipseCompiler
,
int
javaVersion
)
throws
IOException
{
if
(!
JavaUtils
.
checkJavaVersion
(
javaVersion
))
{
throw
new
IllegalArgumentException
(
"Current java version not meet requirement: "
+
"current: "
+
JavaUtils
.
JAVA_VERSION_INT
+
", required: "
+
javaVersion
);
}
public
static
List
<
File
>
compile
(
List
<
File
>
files
,
File
outDir
,
boolean
includeDebugInfo
,
boolean
useEclipseCompiler
)
throws
IOException
{
JavaCompiler
compiler
;
if
(
useEclipseCompiler
)
{
compiler
=
new
EclipseCompiler
();
...
...
@@ -44,7 +46,12 @@ public class StaticCompiler {
List
<
String
>
options
=
new
ArrayList
<>();
options
.
add
(
includeDebugInfo
?
"-g"
:
"-g:none"
);
options
.
addAll
(
COMMON_ARGS
);
String
javaVerStr
=
javaVersion
<=
8
?
"1."
+
javaVersion
:
Integer
.
toString
(
javaVersion
);
options
.
add
(
"-source"
);
options
.
add
(
javaVerStr
);
options
.
add
(
"-target"
);
options
.
add
(
javaVerStr
);
CompilationTask
task
=
compiler
.
getTask
(
null
,
staticFileManager
,
null
,
options
,
null
,
compilationUnits
);
Boolean
result
=
task
.
call
();
fileManager
.
close
();
...
...
jadx-plugins/jadx-java-convert/build.gradle
浏览文件 @
418df2fd
...
...
@@ -7,6 +7,7 @@ dependencies {
implementation
(
project
(
":jadx-plugins:jadx-dex-input"
))
implementation
(
files
(
'lib/dx-1.16.jar'
))
implementation
(
'com.android.tools:r8:2.2.64'
)
implementation
'org.ow2.asm:asm:9.2'
}
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/D8Converter.java
0 → 100644
浏览文件 @
418df2fd
package
jadx.plugins.input.javaconvert
;
import
java.nio.file.Path
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.android.tools.r8.CompilationFailedException
;
import
com.android.tools.r8.CompilationMode
;
import
com.android.tools.r8.D8
;
import
com.android.tools.r8.D8Command
;
import
com.android.tools.r8.Diagnostic
;
import
com.android.tools.r8.DiagnosticsHandler
;
import
com.android.tools.r8.OutputMode
;
public
class
D8Converter
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
D8Converter
.
class
);
public
static
void
run
(
Path
path
,
Path
tempDirectory
)
throws
CompilationFailedException
{
D8Command
d8Command
=
D8Command
.
builder
(
new
LogHandler
())
.
addProgramFiles
(
path
)
.
setOutput
(
tempDirectory
,
OutputMode
.
DexIndexed
)
.
setMode
(
CompilationMode
.
DEBUG
)
.
setMinApiLevel
(
30
)
.
setIntermediate
(
true
)
.
setDisableDesugaring
(
true
)
.
build
();
D8
.
run
(
d8Command
);
}
private
static
class
LogHandler
implements
DiagnosticsHandler
{
@Override
public
void
error
(
Diagnostic
diagnostic
)
{
LOG
.
error
(
"D8 error: {}"
,
format
(
diagnostic
));
}
@Override
public
void
warning
(
Diagnostic
diagnostic
)
{
LOG
.
warn
(
"D8 warning: {}"
,
format
(
diagnostic
));
}
@Override
public
void
info
(
Diagnostic
diagnostic
)
{
LOG
.
info
(
"D8 info: {}"
,
format
(
diagnostic
));
}
public
static
String
format
(
Diagnostic
diagnostic
)
{
return
diagnostic
.
getDiagnosticMessage
()
+
", origin: "
+
diagnostic
.
getOrigin
()
+
", position: "
+
diagnostic
.
getPosition
();
}
}
}
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/DxConverter.java
浏览文件 @
418df2fd
...
...
@@ -43,7 +43,7 @@ public class DxConverter {
throw
new
RuntimeException
(
"dx exception: "
+
e
.
getMessage
(),
e
);
}
if
(
result
!=
0
)
{
throw
new
RuntimeException
(
"Java to dex conversion error, code: "
+
result
+
"
\n
errors: "
+
dxErrors
);
throw
new
RuntimeException
(
"Java to dex conversion error, code: "
+
result
+
"
,
errors: "
+
dxErrors
);
}
}
}
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertLoader.java
浏览文件 @
418df2fd
...
...
@@ -156,7 +156,12 @@ public class JavaConvertLoader {
Path
tempDirectory
=
Files
.
createTempDirectory
(
"jadx-"
);
result
.
addTempPath
(
tempDirectory
);
DxConverter
.
run
(
path
,
tempDirectory
);
try
{
DxConverter
.
run
(
path
,
tempDirectory
);
}
catch
(
Exception
e
)
{
LOG
.
warn
(
"DX convert failed, trying D8"
);
D8Converter
.
run
(
path
,
tempDirectory
);
}
LOG
.
debug
(
"Converted to dex: {}"
,
path
.
toAbsolutePath
());
result
.
addConvertedFiles
(
collectFilesInDir
(
tempDirectory
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录