{"record":{"id":"a4a7d61586f22c65","repo":"pxb1988/dex2jar","slug":"magic-unsupported","errorCode":null,"errorMessage":"Magic unsupported.","messagePattern":"Magic unsupported\\.","errorType":"exception","errorClass":"DexException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java","lineNumber":164,"sourceCode":"    /**\r\n     * read dex from a {@link ByteBuffer}.\r\n     * \r\n     * @param in\r\n     */\r\n    public DexFileReader(ByteBuffer in) {\r\n        in.position(0);\r\n        in = in.asReadOnlyBuffer().order(ByteOrder.BIG_ENDIAN);\r\n        int magic = in.getInt() & 0xFFFFFF00;\r\n\r\n        final int MAGIC_DEX = 0x6465780A & 0xFFFFFF00;// hex for 'dex ', ignore the 0A\r\n        final int MAGIC_ODEX = 0x6465790A & 0xFFFFFF00;// hex for 'dey ', ignore the 0A\r\n\r\n        if (magic == MAGIC_DEX) {\r\n            // ok\r\n        } else if (magic == MAGIC_ODEX) {\r\n            throw new DexException(\"Odex unsupported.\");\r\n        } else {\r\n            throw new DexException(\"Magic unsupported.\");\r\n        }\r\n        int version = in.getInt() >> 8;\r\n        if (version < DEX_035 || version > DEX_040) {\r\n            System.err.println(\"Unknown DEX version. Trying anyway...\");\r\n        }\r\n        this.dex_version = version;\r\n        in.order(ByteOrder.LITTLE_ENDIAN);\r\n\r\n        // skip uint checksum\r\n        // and 20 bytes signature\r\n        // and uint file_size\r\n        // and uint header_size 0x70\r\n        skip(in, 4 + 20 + 4 + 4);\r\n\r\n        int endian_tag = in.getInt();\r\n        if (endian_tag != ENDIAN_CONSTANT) {\r\n            throw new DexException(\"Endian_tag unsupported\");\r\n        }\r","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nDexFileReader reader = new DexFileReader(new File(\"app.apk\")); // throws Magic unsupported\n// after\ntry (ZipFile apk = new ZipFile(\"app.apk\")) {\n    ZipEntry dex = apk.getEntry(\"classes.dex\");\n    DexFileReader reader = new DexFileReader(apk.getInputStream(dex));\n}","handlingStrategy":"validation","validationCode":"static boolean looksLikeDex(byte[] data) {\n    byte[] magic = {'d','e','x','\\n'};\n    if (data == null || data.length < 8) return false;\n    for (int i = 0; i < 4; i++) if (data[i] != magic[i]) return false;\n    return data[7] == 0;\n}\n// call looksLikeDex(bytes) before new DexFileReader(bytes)","typeGuard":"static boolean isDexFile(java.io.File f) throws java.io.IOException {\n    try (java.io.RandomAccessFile raf = new java.io.RandomAccessFile(f, \"r\")) {\n        byte[] h = new byte[8];\n        if (raf.read(h) != 8) return false;\n        return h[0]=='d' && h[1]=='e' && h[2]=='x' && h[3]=='\\n' && h[7]==0;\n    }\n}","tryCatchPattern":"try {\n    DexFileReader reader = new DexFileReader(file);\n    // ...\n} catch (DexException e) {\n    if (e.getMessage().contains(\"Magic unsupported\")) {\n        throw new IllegalArgumentException(\"Not a DEX file: \" + file, e);\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["dex","file-format","magic-header"],"backgroundTag":"invalid-argument-format","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}