Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
极致猎手
jadx
提交
444ea9ec
J
jadx
项目概览
极致猎手
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
444ea9ec
编写于
8月 10, 2020
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: load .class files
上级
13609a5c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
99 addition
and
12 deletion
+99
-12
jadx-cli/src/test/java/jadx/cli/TestInput.java
jadx-cli/src/test/java/jadx/cli/TestInput.java
+5
-0
jadx-cli/src/test/resources/samples/HelloWorld.class
jadx-cli/src/test/resources/samples/HelloWorld.class
+0
-0
jadx-core/src/main/java/jadx/api/impl/InMemoryCodeCache.java
jadx-core/src/main/java/jadx/api/impl/InMemoryCodeCache.java
+5
-0
jadx-core/src/main/java/jadx/api/impl/NoOpCodeCache.java
jadx-core/src/main/java/jadx/api/impl/NoOpCodeCache.java
+5
-0
jadx-plugins/jadx-java-convert/build.gradle
jadx-plugins/jadx-java-convert/build.gradle
+2
-0
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertLoader.java
...ava/jadx/plugins/input/javaconvert/JavaConvertLoader.java
+82
-12
未找到文件。
jadx-cli/src/test/java/jadx/cli/TestInput.java
浏览文件 @
444ea9ec
...
...
@@ -33,6 +33,11 @@ public class TestInput {
decompile
(
"smali"
,
"samples/HelloWorld.smali"
);
}
@Test
public
void
testClassInput
()
throws
Exception
{
decompile
(
"class"
,
"samples/HelloWorld.class"
);
}
private
void
decompile
(
String
tmpDirName
,
String
inputSample
)
throws
URISyntaxException
,
IOException
{
StringBuilder
args
=
new
StringBuilder
();
Path
tempDir
=
FileUtils
.
createTempDir
(
tmpDirName
);
...
...
jadx-cli/src/test/resources/samples/HelloWorld.class
0 → 100644
浏览文件 @
444ea9ec
文件已添加
jadx-core/src/main/java/jadx/api/impl/InMemoryCodeCache.java
浏览文件 @
444ea9ec
...
...
@@ -26,4 +26,9 @@ public class InMemoryCodeCache implements ICodeCache {
public
@Nullable
ICodeInfo
get
(
String
clsFullName
)
{
return
storage
.
get
(
clsFullName
);
}
@Override
public
String
toString
()
{
return
"InMemoryCodeCache"
;
}
}
jadx-core/src/main/java/jadx/api/impl/NoOpCodeCache.java
浏览文件 @
444ea9ec
...
...
@@ -21,4 +21,9 @@ public class NoOpCodeCache implements ICodeCache {
public
@Nullable
ICodeInfo
get
(
String
clsFullName
)
{
return
null
;
}
@Override
public
String
toString
()
{
return
"NoOpCodeCache"
;
}
}
jadx-plugins/jadx-java-convert/build.gradle
浏览文件 @
444ea9ec
...
...
@@ -7,4 +7,6 @@ dependencies {
implementation
(
project
(
":jadx-plugins:jadx-dex-input"
))
implementation
(
files
(
'lib/dx-1.16.jar'
))
implementation
'org.ow2.asm:asm:8.0.1'
}
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertLoader.java
浏览文件 @
444ea9ec
package
jadx.plugins.input.javaconvert
;
import
java.io.BufferedInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.file.FileSystems
;
import
java.nio.file.Files
;
import
java.nio.file.LinkOption
;
import
java.nio.file.Path
;
import
java.nio.file.PathMatcher
;
import
java.util.List
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarOutputStream
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.objectweb.asm.ClassReader
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
jadx.api.plugins.utils.ZipSecurity
;
public
class
JavaConvertLoader
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
JavaConvertLoader
.
class
);
public
static
ConvertResult
process
(
List
<
Path
>
input
)
{
ConvertResult
result
=
new
ConvertResult
();
for
(
Path
path
:
input
)
{
if
(
isJavaFile
(
path
))
{
try
{
convert
(
result
,
path
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Failed to convert file: "
+
path
.
toAbsolutePath
(),
e
);
processJars
(
input
,
result
);
processClassFiles
(
input
,
result
);
return
result
;
}
private
static
void
processJars
(
List
<
Path
>
input
,
ConvertResult
result
)
{
PathMatcher
jarMatcher
=
FileSystems
.
getDefault
().
getPathMatcher
(
"glob:**.jar"
);
input
.
stream
()
.
filter
(
path
->
Files
.
isRegularFile
(
path
,
LinkOption
.
NOFOLLOW_LINKS
))
.
filter
(
jarMatcher:
:
matches
)
.
forEach
(
path
->
{
try
{
convertJar
(
result
,
path
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Failed to convert file: "
+
path
.
toAbsolutePath
(),
e
);
}
});
}
private
static
void
processClassFiles
(
List
<
Path
>
input
,
ConvertResult
result
)
{
PathMatcher
jarMatcher
=
FileSystems
.
getDefault
().
getPathMatcher
(
"glob:**.class"
);
List
<
Path
>
clsFiles
=
input
.
stream
()
.
filter
(
path
->
Files
.
isRegularFile
(
path
,
LinkOption
.
NOFOLLOW_LINKS
))
.
filter
(
jarMatcher:
:
matches
)
.
collect
(
Collectors
.
toList
());
if
(
clsFiles
.
isEmpty
())
{
return
;
}
try
{
Path
jarFile
=
Files
.
createTempFile
(
"jadx-"
,
".jar"
);
try
(
JarOutputStream
jo
=
new
JarOutputStream
(
Files
.
newOutputStream
(
jarFile
)))
{
for
(
Path
file
:
clsFiles
)
{
String
clsName
=
getNameFromClassFile
(
file
);
if
(
clsName
==
null
||
!
ZipSecurity
.
isValidZipEntryName
(
clsName
))
{
throw
new
IOException
(
"Can't read class name from file: "
+
file
);
}
addFileToJar
(
jo
,
file
,
clsName
+
".class"
);
}
}
result
.
addTempPath
(
jarFile
);
LOG
.
debug
(
"Packed class files {} into jar {}"
,
clsFiles
,
jarFile
);
convertJar
(
result
,
jarFile
);
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Error process class files"
,
e
);
}
return
result
;
}
private
static
boolean
isJavaFile
(
Path
path
)
{
String
fileName
=
path
.
getFileName
().
toString
();
return
fileName
.
endsWith
(
".jar"
)
||
fileName
.
endsWith
(
".class"
);
public
static
String
getNameFromClassFile
(
Path
file
)
throws
IOException
{
try
(
InputStream
in
=
Files
.
newInputStream
(
file
))
{
ClassReader
classReader
=
new
ClassReader
(
in
);
return
classReader
.
getClassName
();
}
}
private
static
void
convert
(
ConvertResult
result
,
Path
path
)
throws
Exception
{
private
static
void
convert
Jar
(
ConvertResult
result
,
Path
path
)
throws
Exception
{
Path
tempDirectory
=
Files
.
createTempDirectory
(
"jadx-"
);
result
.
addTempPath
(
tempDirectory
);
...
...
@@ -45,10 +91,34 @@ public class JavaConvertLoader {
}
private
static
List
<
Path
>
collectFilesInDir
(
Path
tempDirectory
)
throws
IOException
{
PathMatcher
dexMatcher
=
FileSystems
.
getDefault
().
getPathMatcher
(
"glob:**.dex"
);
try
(
Stream
<
Path
>
pathStream
=
Files
.
walk
(
tempDirectory
,
1
))
{
return
pathStream
.
filter
(
p
->
Files
.
isRegularFile
(
p
,
LinkOption
.
NOFOLLOW_LINKS
))
.
filter
(
dexMatcher:
:
matches
)
.
collect
(
Collectors
.
toList
());
}
}
public
static
void
addFileToJar
(
JarOutputStream
jar
,
Path
source
,
String
entryName
)
throws
IOException
{
try
(
BufferedInputStream
in
=
new
BufferedInputStream
(
Files
.
newInputStream
(
source
)))
{
JarEntry
entry
=
new
JarEntry
(
entryName
);
entry
.
setTime
(
Files
.
getLastModifiedTime
(
source
,
LinkOption
.
NOFOLLOW_LINKS
).
toMillis
());
jar
.
putNextEntry
(
entry
);
copyStream
(
in
,
jar
);
jar
.
closeEntry
();
}
}
public
static
void
copyStream
(
InputStream
input
,
OutputStream
output
)
throws
IOException
{
byte
[]
buffer
=
new
byte
[
8
*
1024
];
while
(
true
)
{
int
count
=
input
.
read
(
buffer
);
if
(
count
==
-
1
)
{
break
;
}
output
.
write
(
buffer
,
0
,
count
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录