pxb1988/dex2jar · error · DexException
Magic unsupported.
Error message
Magic unsupported.
What it means
DexFileReader validates the 8-byte magic header of a .dex/.odex file when opening it. This DexException is thrown when the magic matches neither the DEX nor the ODEX signature, meaning the input stream is not a recognized Dalvik executable container at all. It fires from the public DexFileReader constructor, so any attempt to open a non-dex file fails immediately.
Solutions
- Verify the input is actually a DEX file: unzip APKs and pass the extracted classes.dex, not the APK itself
- Check the first 8 bytes of the file manually (hexdump -C file | head) and confirm they read 'dex\n035\0' or similar
- Re-download or re-export the file — truncation/corruption is a frequent cause
- Confirm you are not passing an .odex if your build only accepts plain dex (odex has its own distinct message)
Example fix
// before
DexFileReader reader = new DexFileReader(new File("app.apk")); // throws Magic unsupported
// after
try (ZipFile apk = new ZipFile("app.apk")) {
ZipEntry dex = apk.getEntry("classes.dex");
DexFileReader reader = new DexFileReader(apk.getInputStream(dex));
} Defensive patterns
Strategy: validation
Validate before calling
static boolean looksLikeDex(byte[] data) {
byte[] magic = {'d','e','x','\n'};
if (data == null || data.length < 8) return false;
for (int i = 0; i < 4; i++) if (data[i] != magic[i]) return false;
return data[7] == 0;
}
// call looksLikeDex(bytes) before new DexFileReader(bytes) Type guard
static boolean isDexFile(java.io.File f) throws java.io.IOException {
try (java.io.RandomAccessFile raf = new java.io.RandomAccessFile(f, "r")) {
byte[] h = new byte[8];
if (raf.read(h) != 8) return false;
return h[0]=='d' && h[1]=='e' && h[2]=='x' && h[3]=='\n' && h[7]==0;
}
} Try / catch
try {
DexFileReader reader = new DexFileReader(file);
// ...
} catch (DexException e) {
if (e.getMessage().contains("Magic unsupported")) {
throw new IllegalArgumentException("Not a DEX file: " + file, e);
}
throw e;
} Prevention
- Extract classes.dex from APKs before passing to DexFileReader
- Verify the first bytes ('dex\n0xx\0') before opening
- Check file size > 112 (header) — truncated files fail magic or later checks
- Never rename non-dex files to .dex and expect them to parse
When it happens
Trigger: Calling new DexFileReader(InputStream) or DexFileReader(byte[]) with a file whose first 8 bytes are not MAGIC_DEX ("dex\n035\0" family) or MAGIC_ODEX — e.g. a .jar, a plain APK's resources, a truncated file, or a text file renamed to .dex.
Common situations: Passing an APK path where a classes.dex path is expected; feeding a .class file to the dex reader by mistake; a download corrupted or truncated so the header is garbage; picking the wrong entry out of a zip archive.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Odex unsupported.
- Endian_tag unsupported
- The source file is not a .dex or .zip file
- the src file not a .dex or zip file
- Encountered RESTART_LOCAL on new v
AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08).
Data as JSON: /api/errors/a4a7d61586f22c65.
Report an issue: GitHub.
Appendix: source
Thrown at dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java:164
/**
* read dex from a {@link ByteBuffer}.
*
* @param in
*/
public DexFileReader(ByteBuffer in) {
in.position(0);
in = in.asReadOnlyBuffer().order(ByteOrder.BIG_ENDIAN);
int magic = in.getInt() & 0xFFFFFF00;
final int MAGIC_DEX = 0x6465780A & 0xFFFFFF00;// hex for 'dex ', ignore the 0A
final int MAGIC_ODEX = 0x6465790A & 0xFFFFFF00;// hex for 'dey ', ignore the 0A
if (magic == MAGIC_DEX) {
// ok
} else if (magic == MAGIC_ODEX) {
throw new DexException("Odex unsupported.");
} else {
throw new DexException("Magic unsupported.");
}
int version = in.getInt() >> 8;
if (version < DEX_035 || version > DEX_040) {
System.err.println("Unknown DEX version. Trying anyway...");
}
this.dex_version = version;
in.order(ByteOrder.LITTLE_ENDIAN);
// skip uint checksum
// and 20 bytes signature
// and uint file_size
// and uint header_size 0x70
skip(in, 4 + 20 + 4 + 4);
int endian_tag = in.getInt();
if (endian_tag != ENDIAN_CONSTANT) {
throw new DexException("Endian_tag unsupported");
}
View on GitHub (pinned to b5bda4fb49)