mirror of
https://github.com/revanced/smali.git
synced 2025-06-13 04:27:38 +02:00
Improve handling of the dex and odex magic values
git-svn-id: https://smali.googlecode.com/svn/trunk@469 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
@ -277,12 +277,8 @@ public class DexFile
|
|||||||
byte[] magic = FileUtils.readFile(file, 0, 8);
|
byte[] magic = FileUtils.readFile(file, 0, 8);
|
||||||
byte[] dexMagic, odexMagic;
|
byte[] dexMagic, odexMagic;
|
||||||
|
|
||||||
try {
|
dexMagic = HeaderItem.MAGIC;
|
||||||
dexMagic = HeaderItem.MAGIC.getBytes("US-ASCII");
|
odexMagic = OdexHeaderItem.MAGIC;
|
||||||
odexMagic = OdexHeaderItem.MAGIC.getBytes("US-ASCII");
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isDex = true;
|
boolean isDex = true;
|
||||||
this.isOdex = true;
|
this.isOdex = true;
|
||||||
@ -306,6 +302,7 @@ public class DexFile
|
|||||||
} else if (isDex) {
|
} else if (isDex) {
|
||||||
in = new ByteArrayInput(FileUtils.readFile(file));
|
in = new ByteArrayInput(FileUtils.readFile(file));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("bad magic value:");
|
sb.append("bad magic value:");
|
||||||
for (int i=0; i<8; i++) {
|
for (int i=0; i<8; i++) {
|
||||||
|
@ -39,7 +39,8 @@ public class HeaderItem extends Item<HeaderItem> {
|
|||||||
* the file format magic number, represented as the
|
* the file format magic number, represented as the
|
||||||
* low-order bytes of a string
|
* low-order bytes of a string
|
||||||
*/
|
*/
|
||||||
public static final String MAGIC = "dex\n035" + '\0';
|
public static final byte[] MAGIC = new byte[] {0x64, 0x65, 0x78, 0x0A, 0x30, 0x33, 0x35, 0x00};//"dex\n035" + '\0';
|
||||||
|
|
||||||
|
|
||||||
/** size of this section, in bytes */
|
/** size of this section, in bytes */
|
||||||
private static final int HEADER_SIZE = 0x70;
|
private static final int HEADER_SIZE = 0x70;
|
||||||
@ -58,17 +59,10 @@ public class HeaderItem extends Item<HeaderItem> {
|
|||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
protected void readItem(Input in, ReadContext readContext) {
|
protected void readItem(Input in, ReadContext readContext) {
|
||||||
byte[] expectedMagic;
|
|
||||||
try {
|
|
||||||
expectedMagic = MAGIC.getBytes("US-ASCII");
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] readMagic = in.readBytes(8);
|
byte[] readMagic = in.readBytes(8);
|
||||||
|
|
||||||
for (int i=0; i<8; i++) {
|
for (int i=0; i<8; i++) {
|
||||||
if (expectedMagic[i] != readMagic[i]) {
|
if (MAGIC[i] != readMagic[i]) {
|
||||||
throw new RuntimeException("The magic value is not the expected value");
|
throw new RuntimeException("The magic value is not the expected value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,15 +139,13 @@ public class HeaderItem extends Item<HeaderItem> {
|
|||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
protected void writeItem(AnnotatedOutput out) {
|
protected void writeItem(AnnotatedOutput out) {
|
||||||
byte[] magic;
|
StringBuilder magicBuilder = new StringBuilder();
|
||||||
try {
|
for (int i=0; i<8; i++) {
|
||||||
magic = MAGIC.getBytes("US-ASCII");
|
magicBuilder.append((char)MAGIC[i]);
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out.annotate("magic: " + Utf8Utils.escapeString(MAGIC));
|
out.annotate("magic: " + Utf8Utils.escapeString(magicBuilder.toString()));
|
||||||
out.write(magic);
|
out.write(MAGIC);
|
||||||
|
|
||||||
out.annotate("checksum");
|
out.annotate("checksum");
|
||||||
out.writeInt(0);
|
out.writeInt(0);
|
||||||
|
@ -38,7 +38,7 @@ public class OdexHeaderItem {
|
|||||||
* the file format magic number, represented as the
|
* the file format magic number, represented as the
|
||||||
* low-order bytes of a string
|
* low-order bytes of a string
|
||||||
*/
|
*/
|
||||||
public static final String MAGIC = "dey\n035" + '\0';
|
public static final byte[] MAGIC = new byte[] {0x64, 0x65, 0x79, 0x0A, 0x30, 0x33, 0x35, 0x00};//"dey\n035" + '\0';
|
||||||
|
|
||||||
public final byte[] magic;
|
public final byte[] magic;
|
||||||
public final int dexOffset;
|
public final int dexOffset;
|
||||||
@ -52,15 +52,8 @@ public class OdexHeaderItem {
|
|||||||
public OdexHeaderItem(Input in) {
|
public OdexHeaderItem(Input in) {
|
||||||
magic = in.readBytes(8);
|
magic = in.readBytes(8);
|
||||||
|
|
||||||
byte[] expectedMagic;
|
|
||||||
try {
|
|
||||||
expectedMagic = MAGIC.getBytes("US-ASCII");
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0; i<8; i++) {
|
for (int i=0; i<8; i++) {
|
||||||
if (expectedMagic[i] != magic[i]) {
|
if (MAGIC[i] != magic[i]) {
|
||||||
throw new RuntimeException("The magic value is not the expected value");
|
throw new RuntimeException("The magic value is not the expected value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user