Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_39073359
jadx
提交
c3f7a049
J
jadx
项目概览
qq_39073359
/
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,发现更多精彩内容 >>
提交
c3f7a049
编写于
7月 08, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: ignore incorrect dex files in apk (#700)
上级
3eee83c2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
20 deletion
+69
-20
jadx-core/src/main/java/jadx/core/utils/files/InputFile.java
jadx-core/src/main/java/jadx/core/utils/files/InputFile.java
+32
-20
jadx-core/src/test/java/jadx/core/utils/files/InputFileTest.java
...re/src/test/java/jadx/core/utils/files/InputFileTest.java
+37
-0
jadx-core/src/test/resources/test-samples/app-with-fake-dex.apk
...ore/src/test/resources/test-samples/app-with-fake-dex.apk
+0
-0
未找到文件。
jadx-core/src/main/java/jadx/core/utils/files/InputFile.java
浏览文件 @
c3f7a049
...
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
...
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.android.dex.Dex
;
import
com.android.dex.Dex
;
import
com.android.dex.DexException
;
import
jadx.core.utils.AsmUtils
;
import
jadx.core.utils.AsmUtils
;
import
jadx.core.utils.exceptions.DecodeException
;
import
jadx.core.utils.exceptions.DecodeException
;
...
@@ -52,7 +53,7 @@ public class InputFile {
...
@@ -52,7 +53,7 @@ public class InputFile {
String
fileName
=
file
.
getName
();
String
fileName
=
file
.
getName
();
if
(
fileName
.
endsWith
(
".dex"
))
{
if
(
fileName
.
endsWith
(
".dex"
))
{
addDexFile
(
fileName
,
new
Dex
(
file
),
file
.
toPath
());
addDexFile
(
fileName
,
file
.
toPath
());
return
;
return
;
}
}
if
(
fileName
.
endsWith
(
".smali"
))
{
if
(
fileName
.
endsWith
(
".smali"
))
{
...
@@ -60,12 +61,12 @@ public class InputFile {
...
@@ -60,12 +61,12 @@ public class InputFile {
SmaliOptions
options
=
new
SmaliOptions
();
SmaliOptions
options
=
new
SmaliOptions
();
options
.
outputDexFile
=
output
.
toAbsolutePath
().
toString
();
options
.
outputDexFile
=
output
.
toAbsolutePath
().
toString
();
Smali
.
assemble
(
options
,
file
.
getAbsolutePath
());
Smali
.
assemble
(
options
,
file
.
getAbsolutePath
());
addDexFile
(
""
,
new
Dex
(
output
.
toFile
())
,
output
);
addDexFile
(
fileName
,
output
);
return
;
return
;
}
}
if
(
fileName
.
endsWith
(
".class"
))
{
if
(
fileName
.
endsWith
(
".class"
))
{
for
(
Path
path
:
loadFromClassFile
(
file
))
{
for
(
Path
path
:
loadFromClassFile
(
file
))
{
addDexFile
(
path
);
addDexFile
(
fileName
,
path
);
}
}
return
;
return
;
}
}
...
@@ -80,7 +81,7 @@ public class InputFile {
...
@@ -80,7 +81,7 @@ public class InputFile {
}
}
if
(
fileName
.
endsWith
(
".jar"
))
{
if
(
fileName
.
endsWith
(
".jar"
))
{
for
(
Path
path
:
loadFromJar
(
file
.
toPath
()))
{
for
(
Path
path
:
loadFromJar
(
file
.
toPath
()))
{
addDexFile
(
path
);
addDexFile
(
fileName
,
path
);
}
}
return
;
return
;
}
}
...
@@ -96,18 +97,6 @@ public class InputFile {
...
@@ -96,18 +97,6 @@ public class InputFile {
LOG
.
warn
(
"No dex files found in {}"
,
file
);
LOG
.
warn
(
"No dex files found in {}"
,
file
);
}
}
private
void
addDexFile
(
Path
path
)
throws
IOException
{
addDexFile
(
path
.
getFileName
().
toString
(),
path
);
}
private
void
addDexFile
(
String
fileName
,
Path
path
)
throws
IOException
{
addDexFile
(
fileName
,
new
Dex
(
Files
.
readAllBytes
(
path
)),
path
);
}
private
void
addDexFile
(
String
fileName
,
Dex
dexBuf
,
Path
path
)
{
dexFiles
.
add
(
new
DexFile
(
this
,
fileName
,
dexBuf
,
path
));
}
private
boolean
loadFromZip
(
String
ext
)
throws
IOException
,
DecodeException
{
private
boolean
loadFromZip
(
String
ext
)
throws
IOException
,
DecodeException
{
int
index
=
0
;
int
index
=
0
;
try
(
ZipFile
zf
=
new
ZipFile
(
file
))
{
try
(
ZipFile
zf
=
new
ZipFile
(
file
))
{
...
@@ -127,9 +116,8 @@ public class InputFile {
...
@@ -127,9 +116,8 @@ public class InputFile {
||
entryName
.
endsWith
(
instantRunDexSuffix
))
{
||
entryName
.
endsWith
(
instantRunDexSuffix
))
{
switch
(
ext
)
{
switch
(
ext
)
{
case
".dex"
:
case
".dex"
:
Path
path
=
makeDexBuf
(
entryName
,
inputStream
);
Path
path
=
copyToTmpDex
(
entryName
,
inputStream
);
if
(
path
!=
null
)
{
if
(
addDexFile
(
entryName
,
path
))
{
addDexFile
(
entryName
,
path
);
index
++;
index
++;
}
}
break
;
break
;
...
@@ -163,8 +151,32 @@ public class InputFile {
...
@@ -163,8 +151,32 @@ public class InputFile {
return
index
>
0
;
return
index
>
0
;
}
}
private
boolean
addDexFile
(
String
entryName
,
@Nullable
Path
filePath
)
{
if
(
filePath
==
null
)
{
return
false
;
}
Dex
dexBuf
=
loadDexBufFromPath
(
filePath
,
entryName
);
if
(
dexBuf
==
null
)
{
return
false
;
}
dexFiles
.
add
(
new
DexFile
(
this
,
entryName
,
dexBuf
,
filePath
));
return
true
;
}
@Nullable
private
Dex
loadDexBufFromPath
(
Path
path
,
String
entryName
)
{
try
{
return
new
Dex
(
Files
.
readAllBytes
(
path
));
}
catch
(
DexException
e
)
{
LOG
.
error
(
"Failed to load dex file: {}, error: {}"
,
entryName
,
e
.
getMessage
());
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Failed to load dex file: {}, error: {}"
,
entryName
,
e
.
getMessage
(),
e
);
}
return
null
;
}
@Nullable
@Nullable
private
Path
makeDexBuf
(
String
entryName
,
InputStream
inputStream
)
{
private
Path
copyToTmpDex
(
String
entryName
,
InputStream
inputStream
)
{
try
{
try
{
Path
path
=
FileUtils
.
createTempFile
(
".dex"
);
Path
path
=
FileUtils
.
createTempFile
(
".dex"
);
Files
.
copy
(
inputStream
,
path
,
StandardCopyOption
.
REPLACE_EXISTING
);
Files
.
copy
(
inputStream
,
path
,
StandardCopyOption
.
REPLACE_EXISTING
);
...
...
jadx-core/src/test/java/jadx/core/utils/files/InputFileTest.java
0 → 100644
浏览文件 @
c3f7a049
package
jadx.core.utils.files
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.utils.exceptions.DecodeException
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
class
InputFileTest
{
private
static
final
String
TEST_SAMPLES_DIR
=
"test-samples/"
;
@Test
public
void
testApkWithFakeDex
()
throws
IOException
,
DecodeException
{
File
sample
=
getFileFromSampleDir
(
"app-with-fake-dex.apk"
);
List
<
InputFile
>
list
=
new
ArrayList
<>();
InputFile
.
addFilesFrom
(
sample
,
list
,
false
);
assertThat
(
list
,
hasSize
(
1
));
InputFile
inputFile
=
list
.
get
(
0
);
assertThat
(
inputFile
.
getDexFiles
(),
hasSize
(
1
));
}
private
static
File
getFileFromSampleDir
(
String
fileName
)
{
URL
resource
=
InputFileTest
.
class
.
getClassLoader
().
getResource
(
TEST_SAMPLES_DIR
+
fileName
);
assertThat
(
resource
,
notNullValue
());
String
pathStr
=
resource
.
getFile
();
return
new
File
(
pathStr
);
}
}
jadx-core/src/test/resources/test-samples/app-with-fake-dex.apk
0 → 100644
浏览文件 @
c3f7a049
文件已添加
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录