Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
c3f7a049
Commit
c3f7a049
authored
Jul 08, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ignore incorrect dex files in apk (#700)
parent
3eee83c2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
20 deletions
+69
-20
InputFile.java
jadx-core/src/main/java/jadx/core/utils/files/InputFile.java
+32
-20
InputFileTest.java
...re/src/test/java/jadx/core/utils/files/InputFileTest.java
+37
-0
app-with-fake-dex.apk
...ore/src/test/resources/test-samples/app-with-fake-dex.apk
+0
-0
No files found.
jadx-core/src/main/java/jadx/core/utils/files/InputFile.java
View file @
c3f7a049
...
...
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
com.android.dex.Dex
;
import
com.android.dex.DexException
;
import
jadx.core.utils.AsmUtils
;
import
jadx.core.utils.exceptions.DecodeException
;
...
...
@@ -52,7 +53,7 @@ public class InputFile {
String
fileName
=
file
.
getName
();
if
(
fileName
.
endsWith
(
".dex"
))
{
addDexFile
(
fileName
,
new
Dex
(
file
),
file
.
toPath
());
addDexFile
(
fileName
,
file
.
toPath
());
return
;
}
if
(
fileName
.
endsWith
(
".smali"
))
{
...
...
@@ -60,12 +61,12 @@ public class InputFile {
SmaliOptions
options
=
new
SmaliOptions
();
options
.
outputDexFile
=
output
.
toAbsolutePath
().
toString
();
Smali
.
assemble
(
options
,
file
.
getAbsolutePath
());
addDexFile
(
""
,
new
Dex
(
output
.
toFile
())
,
output
);
addDexFile
(
fileName
,
output
);
return
;
}
if
(
fileName
.
endsWith
(
".class"
))
{
for
(
Path
path
:
loadFromClassFile
(
file
))
{
addDexFile
(
path
);
addDexFile
(
fileName
,
path
);
}
return
;
}
...
...
@@ -80,7 +81,7 @@ public class InputFile {
}
if
(
fileName
.
endsWith
(
".jar"
))
{
for
(
Path
path
:
loadFromJar
(
file
.
toPath
()))
{
addDexFile
(
path
);
addDexFile
(
fileName
,
path
);
}
return
;
}
...
...
@@ -96,18 +97,6 @@ public class InputFile {
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
{
int
index
=
0
;
try
(
ZipFile
zf
=
new
ZipFile
(
file
))
{
...
...
@@ -127,9 +116,8 @@ public class InputFile {
||
entryName
.
endsWith
(
instantRunDexSuffix
))
{
switch
(
ext
)
{
case
".dex"
:
Path
path
=
makeDexBuf
(
entryName
,
inputStream
);
if
(
path
!=
null
)
{
addDexFile
(
entryName
,
path
);
Path
path
=
copyToTmpDex
(
entryName
,
inputStream
);
if
(
addDexFile
(
entryName
,
path
))
{
index
++;
}
break
;
...
...
@@ -163,8 +151,32 @@ public class InputFile {
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
private
Path
makeDexBuf
(
String
entryName
,
InputStream
inputStream
)
{
private
Path
copyToTmpDex
(
String
entryName
,
InputStream
inputStream
)
{
try
{
Path
path
=
FileUtils
.
createTempFile
(
".dex"
);
Files
.
copy
(
inputStream
,
path
,
StandardCopyOption
.
REPLACE_EXISTING
);
...
...
jadx-core/src/test/java/jadx/core/utils/files/InputFileTest.java
0 → 100644
View file @
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
View file @
c3f7a049
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment