|
6 | 6 | import java.io.FileInputStream; |
7 | 7 | import java.io.IOException; |
8 | 8 | import java.io.InputStream; |
| 9 | +import java.nio.charset.StandardCharsets; |
9 | 10 | import java.nio.file.Path; |
10 | 11 | import java.util.ArrayList; |
11 | 12 | import java.util.Collection; |
|
18 | 19 | import org.slf4j.LoggerFactory; |
19 | 20 |
|
20 | 21 | import jadx.api.plugins.utils.CommonFileUtils; |
| 22 | +import jadx.core.utils.files.FileUtils; |
21 | 23 | import jadx.plugins.input.dex.sections.DexConsts; |
22 | 24 | import jadx.plugins.input.dex.sections.DexHeaderV41; |
23 | 25 | import jadx.plugins.input.dex.utils.DexCheckSum; |
@@ -69,11 +71,18 @@ private List<DexReader> load(@Nullable File file, InputStream inputStream, Strin |
69 | 71 | if (in.read(magic) != magic.length) { |
70 | 72 | return Collections.emptyList(); |
71 | 73 | } |
72 | | - if (isStartWithBytes(magic, DexConsts.DEX_FILE_MAGIC) || fileName.endsWith(".dex")) { |
| 74 | + if (isStartWithBytes(magic, DexConsts.DEX_FILE_MAGIC)) { |
73 | 75 | in.reset(); |
74 | 76 | byte[] content = readAllBytes(in); |
75 | 77 | return loadDexReaders(fileName, content); |
76 | 78 | } |
| 79 | + if (fileName.endsWith(".dex")) { |
| 80 | + // report invalid magic in '.dex' file |
| 81 | + String hex = FileUtils.bytesToHex(magic); |
| 82 | + String str = new String(magic, StandardCharsets.US_ASCII); |
| 83 | + LOG.warn("Invalid DEX magic: 0x{}(\"{}\") in file: {}", hex, str, fileName); |
| 84 | + return Collections.emptyList(); |
| 85 | + } |
77 | 86 | if (file != null) { |
78 | 87 | // allow only top level zip files |
79 | 88 | if (isStartWithBytes(magic, DexConsts.ZIP_FILE_MAGIC) || CommonFileUtils.isZipFileExt(fileName)) { |
|
0 commit comments