diff --git a/BinaryInternalsViewer/pom.xml b/BinaryInternalsViewer/pom.xml
index 7e5992e..ce29584 100644
--- a/BinaryInternalsViewer/pom.xml
+++ b/BinaryInternalsViewer/pom.xml
@@ -40,7 +40,7 @@
${project.groupId}
freeinternals.format.dex
- 0.2
+ 0.7
${project.groupId}
diff --git a/FormatDEX/pom.xml b/FormatDEX/pom.xml
index 46f35c0..e25ee39 100644
--- a/FormatDEX/pom.xml
+++ b/FormatDEX/pom.xml
@@ -7,7 +7,7 @@
3.0
freeinternals.format.dex
- 0.2
+ 0.7
jar
freeinternals :: FormatDEX
diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java
index 45e3068..bfcb5b4 100644
--- a/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java
+++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/PosDataInputStreamDex.java
@@ -290,6 +290,30 @@ public Type_uleb128p1 Dex_uleb128p1() throws IOException, FileFormatException {
return new Type_uleb128p1(uleb128.value - 1, uleb128.length);
}
+ public Double readDouble(int length) throws IOException{
+ System.out.println(this.getClass().getSimpleName() + " VALUE_DOUBLE value_arg " + (length - 1) + " at 0x" + Integer.toHexString(this.getPos()) + " - to implment");
+
+ byte[] raw = new byte[length];
+ int rb = this.read(raw);
+ if (rb != length) {
+ throw new IOException(String.format("Cannot read enough bytes for double. expected=%d readbytes=%d", length, rb));
+ }
+
+ return Double.MAX_VALUE;
+ }
+
+ public Float readFloat(int length) throws IOException{
+ System.out.println(this.getClass().getSimpleName() + " VALUE_FLOAT value_arg " + (length -1) + " at 0x" + Integer.toHexString(this.getPos()) + " - to implment");
+
+ byte[] raw = new byte[length];
+ int rb = this.read(raw);
+ if (rb != length) {
+ throw new IOException(String.format("Cannot read enough bytes for float. expected=%d readbytes=%d", length, rb));
+ }
+
+ return Float.MIN_VALUE;
+ }
+
/**
* Read 3-byte int.
*/
@@ -329,90 +353,141 @@ private int readInt3InLittleEndian() throws IOException {
}
private long readLong5() throws IOException {
- final byte[] readBuffer = new byte[BYTE_LENGTH_8];
- super.readFully(readBuffer, 3, BYTE_LENGTH_5);
-
- // TODO
- return (((long) readBuffer[BYTE_OFFSET_7] << SHIFT_56)
- | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
- | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
- | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
- | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
- | ((readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
- | ((readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
- | ((readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ final byte[] readBuffer = new byte[BYTE_LENGTH_5];
+ super.readFully(readBuffer);
+
+ if ((readBuffer[BYTE_OFFSET_4] & 0x80) > 0) {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong5 NEGATIVE----");
+ return (0xFFFFFF0000000000L
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255)));
+ } else {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong5 POSITIVE----");
+ return ( ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255)));
+ }
}
+
private long readLong5InLittleEndian() throws IOException {
- final byte[] readBuffer = new byte[BYTE_LENGTH_8];
- super.readFully(readBuffer, 3, BYTE_LENGTH_5);
-
- // TODO
- return (((long) readBuffer[BYTE_OFFSET_7] << SHIFT_56)
- | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
- | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
- | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
- | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
- | ((readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
- | ((readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
- | ((readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ final byte[] readBuffer = new byte[BYTE_LENGTH_5];
+ super.readFully(readBuffer);
+
+ if ((readBuffer[BYTE_OFFSET_4] & 0x80) > 0) {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong5InLittleEndian NEGATIVE----");
+ return (0xFFFFFF0000000000L
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ } else {
+ return ( ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ }
}
private long readLong6() throws IOException {
- final byte[] readBuffer = new byte[BYTE_LENGTH_8];
- super.readFully(readBuffer, 2, BYTE_LENGTH_6);
-
- // TODO
- return (((long) readBuffer[BYTE_OFFSET_7] << SHIFT_56)
- | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
- | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
- | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
- | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
- | ((readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
- | ((readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
- | ((readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ final byte[] readBuffer = new byte[BYTE_LENGTH_6];
+ super.readFully(readBuffer);
+
+ if ((readBuffer[BYTE_OFFSET_5] & 0x80) > 0) {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong6 NEGATIVE----");
+ return (0xFFFF000000000000L
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255)));
+ } else {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong6 POSITIVE----");
+ return ( ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255)));
+ }
}
private long readLong6InLittleEndian() throws IOException {
- final byte[] readBuffer = new byte[BYTE_LENGTH_8];
- super.readFully(readBuffer, 2, BYTE_LENGTH_6);
-
- // TODO
- return (((long) readBuffer[BYTE_OFFSET_7] << SHIFT_56)
- | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
- | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
- | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
- | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
- | ((readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
- | ((readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
- | ((readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ final byte[] readBuffer = new byte[BYTE_LENGTH_6];
+ super.readFully(readBuffer);
+
+ if ((readBuffer[BYTE_OFFSET_5] & 0x80) > 0) {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong6InLittleEndian NEGATIVE----");
+ return (0xFFFF000000000000L
+ | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ } else {
+ return ( ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ }
}
private long readLong7() throws IOException {
- final byte[] readBuffer = new byte[BYTE_LENGTH_8];
- super.readFully(readBuffer, 1, BYTE_LENGTH_7);
-
- // TODO
- return (((long) readBuffer[BYTE_OFFSET_7] << SHIFT_56)
- | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
- | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
- | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
- | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
- | ((readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
- | ((readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
- | ((readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ final byte[] readBuffer = new byte[BYTE_LENGTH_7];
+ super.readFully(readBuffer);
+
+ if ((readBuffer[BYTE_OFFSET_6] & 0x80) > 0) {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong7 NEGATIVE----");
+ return (0xFF00000000000000L
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255) << SHIFT_48)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255)));
+ } else {
+ System.out.println("TODO test case at 0x" + Integer.toHexString(this.getPos()) + " ------------------- to verify ---- readLong7 POSITIVE----");
+ return ( ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255) << SHIFT_48)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255)));
+ }
}
private long readLong7InLittleEndian() throws IOException {
- final byte[] readBuffer = new byte[BYTE_LENGTH_8];
- super.readFully(readBuffer, 1, BYTE_LENGTH_7);
-
- // TODO
- return (((long) readBuffer[BYTE_OFFSET_7] << SHIFT_56)
- | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
- | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
- | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
- | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
- | ((readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
- | ((readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
- | ((readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ final byte[] readBuffer = new byte[BYTE_LENGTH_7];
+ super.readFully(readBuffer);
+
+ if ((readBuffer[BYTE_OFFSET_6] & 0x80) > 0) {
+ return (0xFF00000000000000L
+ | ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
+ | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ } else {
+ return ( ((long) (readBuffer[BYTE_OFFSET_6] & BYTE_MAX_255) << SHIFT_48)
+ | ((long) (readBuffer[BYTE_OFFSET_5] & BYTE_MAX_255) << SHIFT_40)
+ | ((long) (readBuffer[BYTE_OFFSET_4] & BYTE_MAX_255) << SHIFT_32)
+ | ((long) (readBuffer[BYTE_OFFSET_3] & BYTE_MAX_255) << SHIFT_24)
+ | ((long) (readBuffer[BYTE_OFFSET_2] & BYTE_MAX_255) << SHIFT_16)
+ | ((long) (readBuffer[BYTE_OFFSET_1] & BYTE_MAX_255) << SHIFT_8)
+ | ((long) (readBuffer[BYTE_OFFSET_0] & BYTE_MAX_255)));
+ }
}
/**
diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_value.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_value.java
index 5cf3e9b..e9c0246 100644
--- a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_value.java
+++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_value.java
@@ -93,10 +93,10 @@ public class encoded_value extends FileComponent implements GenerateTreeNodeDexF
this.union_value_long = this.read_long(stream, this.value_arg);
break;
case VALUE_FLOAT:
- this.union_value_float = this.read_float(stream, this.value_arg);
+ this.union_value_float = stream.readFloat(this.value_arg + 1);
break;
case VALUE_DOUBLE:
- this.union_value_double = this.read_double(stream, this.value_arg);
+ this.union_value_double = stream.readDouble(this.value_arg + 1);
break;
case VALUE_METHOD_TYPE:
this.union_value_method_type = this.read_uint(stream, this.value_arg);
@@ -231,7 +231,6 @@ private Type_long read_long(final PosDataInputStreamDex stream, final int arg) t
case 4:
case 5:
case 6:
- System.out.println(this.getClass().getSimpleName() + " : read_long for bytes 5/6/7 at 0x" + Integer.toHexString(stream.getPos()).toUpperCase() + " ======= to verify =======");
result = stream.Dex_long(arg + 1);
break;
@@ -250,38 +249,6 @@ private Type_long read_long(final PosDataInputStreamDex stream, final int arg) t
return result;
}
- private Float read_float(final PosDataInputStreamDex stream, final int arg) throws IOException{
- Float result = Float.MIN_VALUE; // TODO convert the bytes to float
-
- if (arg != 3) {
- System.out.println(this.getClass().getSimpleName() + " VALUE_FLOAT value_arg is not 3 but " + this.value_arg + " at 0x" + Integer.toHexString(stream.getPos()) + " - to implment");
- }
-
- byte[] raw = new byte[arg + 1];
- int rb = stream.read(raw);
- if (rb != arg + 1) {
- throw new IOException(String.format("Cannot read enough bytes for float. expected=%d readbytes=%d", arg + 1, rb));
- }
-
- return result;
- }
-
- private Double read_double(final PosDataInputStreamDex stream, final int arg) throws IOException{
- Double result = Double.MAX_VALUE; // TODO convert the bytes to double
-
- if (arg != 7) {
- System.out.println(this.getClass().getSimpleName() + " VALUE_DOUBLE value_arg is not 7 but " + this.value_arg + " at 0x" + Integer.toHexString(stream.getPos()) + " - to implment");
- }
-
- byte[] raw = new byte[arg + 1];
- int rb = stream.read(raw);
- if (rb != arg + 1) {
- throw new IOException(String.format("Cannot read enough bytes for double. expected=%d readbytes=%d", arg + 1, rb));
- }
-
- return result;
- }
-
private Type_short read_short(final PosDataInputStreamDex stream, final int arg) throws FileFormatException, IOException{
Type_short result = null;
switch (arg) {