From 14348d570e89547f864d42e7a2fd99e0a55b2e66 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Wed, 9 Jun 2010 01:45:14 +0000 Subject: [PATCH] Add support for the new dey36 odex header git-svn-id: https://smali.googlecode.com/svn/trunk@725 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../src/main/java/org/jf/dexlib/DexFile.java | 31 +++++++++++-------- .../main/java/org/jf/dexlib/OdexHeader.java | 21 ++++++++----- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/dexlib/src/main/java/org/jf/dexlib/DexFile.java b/dexlib/src/main/java/org/jf/dexlib/DexFile.java index a88b145d..df9fa1ae 100644 --- a/dexlib/src/main/java/org/jf/dexlib/DexFile.java +++ b/dexlib/src/main/java/org/jf/dexlib/DexFile.java @@ -175,6 +175,7 @@ public class DexFile */ private boolean isOdex = false; + private OdexHeader odexHeader; private OdexDependencies odexDependencies; private int dataOffset; @@ -332,25 +333,21 @@ public class DexFile } byte[] dexMagic, odexMagic; + boolean isDex = false; + this.isOdex = false; - dexMagic = org.jf.dexlib.HeaderItem.MAGIC; - odexMagic = OdexHeader.MAGIC; - - boolean isDex = true; - this.isOdex = true; - for (int i=0; i<8; i++) { - if (magic[i] != dexMagic[i]) { - isDex = false; - } - if (magic[i] != odexMagic[i]) { - isOdex = false; - } + if (Arrays.equals(magic, HeaderItem.MAGIC)) { + isDex = true; + } else if (Arrays.equals(magic, OdexHeader.MAGIC_35)) { + isOdex = true; + } else if (Arrays.equals(magic, OdexHeader.MAGIC_36)) { + isOdex = true; } if (isOdex) { byte[] odexHeaderBytes = FileUtils.readStream(inputStream, 40); Input odexHeaderIn = new ByteArrayInput(odexHeaderBytes); - OdexHeader odexHeader = new OdexHeader(odexHeaderIn); + odexHeader = new OdexHeader(odexHeaderIn); int dependencySkip = odexHeader.depsOffset - odexHeader.dexOffset - odexHeader.dexLength; if (dependencySkip < 0) { @@ -536,6 +533,14 @@ public class DexFile return odexDependencies; } + /** + * @return An OdexHeader object containing the information from the odex header in this dex file, or null if there + * is no odex header + */ + public OdexHeader getOdexHeader() { + return odexHeader; + } + /** * Get a boolean value indicating whether items in this dex file should be * written back out "in-place", or whether the normal layout logic should be diff --git a/dexlib/src/main/java/org/jf/dexlib/OdexHeader.java b/dexlib/src/main/java/org/jf/dexlib/OdexHeader.java index ff363853..afc8f0b1 100644 --- a/dexlib/src/main/java/org/jf/dexlib/OdexHeader.java +++ b/dexlib/src/main/java/org/jf/dexlib/OdexHeader.java @@ -30,13 +30,15 @@ package org.jf.dexlib; import org.jf.dexlib.Util.Input; +import java.util.Arrays; + public class OdexHeader { /** - * the file format magic number, represented as the - * low-order bytes of a string + * the possible file format magic numbers, represented as the low-order bytes of a string. */ - public static final byte[] MAGIC = new byte[] {0x64, 0x65, 0x79, 0x0A, 0x30, 0x33, 0x35, 0x00};//"dey\n035" + '\0'; + public static final byte[] MAGIC_35 = new byte[] {0x64, 0x65, 0x79, 0x0A, 0x30, 0x33, 0x35, 0x00}; //"dey\n035" + '\0'; + public static final byte[] MAGIC_36 = new byte[] {0x64, 0x65, 0x79, 0x0A, 0x30, 0x33, 0x36, 0x00}; //"dey\n036" + '\0'; public final byte[] magic; public final int dexOffset; @@ -47,13 +49,17 @@ public class OdexHeader { public final int auxLength; public final int flags; + public final int version; + public OdexHeader(Input in) { magic = in.readBytes(8); - for (int i=0; i<8; i++) { - if (MAGIC[i] != magic[i]) { - throw new RuntimeException("The magic value is not the expected value"); - } + if (Arrays.equals(MAGIC_35, magic)) { + version = 35; + } else if (Arrays.equals(MAGIC_36, magic)) { + version = 36; + } else { + throw new RuntimeException("The magic value is not one of the expected values"); } dexOffset = in.readInt(); @@ -65,5 +71,4 @@ public class OdexHeader { flags = in.readInt(); in.readInt(); //padding } - }