Skip to content

Commit 5c19ccc

Browse files
committed
#11 DEX format - parse items - encoded_value in progress
1 parent e94712f commit 5c19ccc

34 files changed

+829
-128
lines changed

CommonLib/src/main/java/org/freeinternals/commonlib/ui/UITool.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public static Icon icon4Annotations() {
8080
return icon("/image/icons8-bookmark-16.png");
8181
}
8282

83+
/**
84+
* Icon for array.
85+
*
86+
* @return Icon for array
87+
* @see <a href="https://icons8.com/icon/78816/view-array">View Array</a> icon by <a href="https://icons8.com">Icons8</a>
88+
*/
89+
public static Icon icon4Array() {
90+
return icon("/image/icons8-view-array-16.png");
91+
}
92+
8393
/**
8494
* Icon for binary file.
8595
*
@@ -253,7 +263,7 @@ public static Icon icon4Size() {
253263
}
254264

255265
/**
256-
* Icon for tag.
266+
* Icon for Tag or Type.
257267
*
258268
* @return tag icon
259269
* @see <a href="https://icons8.com/icon/pmzH4rF8Lrv9/tag">Tag</a> icon by
Loading

FormatDEX/src/main/java/org/freeinternals/format/dex/DexFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* DEXFile.java June 14, 2015, 22:20
2+
* DexFile.java June 14, 2015, 22:20
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -223,7 +223,7 @@ public DexFile(File file) throws IOException, FileFormatException {
223223
stream.flyTo(this.header.class_defs_off.intValue());
224224
this.class_defs = new class_def_item[this.header.class_defs_size.intValue()];
225225
for (int i = 0; i < this.class_defs.length; i++) {
226-
this.class_defs[i] = new class_def_item(stream);
226+
this.class_defs[i] = new class_def_item(stream, this);
227227

228228
if (this.class_defs[i].interfaces_off.value != 0) {
229229
todoData.put(this.class_defs[i].interfaces_off.value, type_list.class);

FormatDEX/src/main/java/org/freeinternals/format/dex/GenerateTreeNodeDexFile.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
1515
* Interface for generating tree node for {@link DexFile}.
1616
*
1717
* @author Amos Shi
18+
*
19+
* <pre>
20+
* java:S115 - Constant name does not follow naming conventions --- We respect the DEX spec name instead
21+
* </pre>
1822
*/
23+
@SuppressWarnings({"java:S115"})
1924
public interface GenerateTreeNodeDexFile {
2025
static final ResourceBundle MESSAGES = ResourceBundle.getBundle(JTreeDexFile.class.getPackageName() + ".MessagesBundle", Locale.ROOT);
2126
static final String FORMAT_STRING_STRING = "%s - %s";
2227

28+
static final String msg_annotation_set_item = "msg_annotation_set_item";
29+
2330
void generateTreeNode(final DefaultMutableTreeNode parentNode, final DexFile dexFile);
2431

2532
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_byte.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexbyte.java June 17, 2015, 21:32
2+
* Type_byte.java June 17, 2015, 21:32
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -38,4 +38,9 @@ public class Type_byte {
3838
protected Type_byte(byte b) {
3939
this.value = b;
4040
}
41+
42+
@Override
43+
public String toString() {
44+
return String.format("0x%s | %d | %c", Integer.toHexString(this.value).toUpperCase(), this.value, this.value);
45+
}
4146
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_int.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexint.java June 17, 2015, 21:38
2+
* Type_int.java June 17, 2015, 21:38
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -8,7 +8,7 @@
88

99
/**
1010
* 32-bit signed int, little-endian.
11-
*
11+
*
1212
* @author Amos Shi
1313
* @see
1414
* <a href="https://source.android.com/devices/tech/dalvik/dex-format.html">
@@ -24,7 +24,7 @@ public class Type_int {
2424
* Length of the type in bytes.
2525
*/
2626
public static final int LENGTH = 4;
27-
27+
2828
/**
2929
* Value of the DEX <code>int</code>.
3030
*/
@@ -33,4 +33,9 @@ public class Type_int {
3333
protected Type_int(int i) {
3434
this.value = i;
3535
}
36+
37+
@Override
38+
public String toString() {
39+
return String.format("0x%s | %,d", Integer.toHexString(this.value).toUpperCase(), this.value);
40+
}
3641
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_long.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexlong.java June 17, 2015, 21:39
2+
* Type_long.java June 17, 2015, 21:39
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -33,4 +33,9 @@ public class Type_long {
3333
protected Type_long(long l) {
3434
this.value = l;
3535
}
36+
37+
@Override
38+
public String toString() {
39+
return String.format("0x%s | %,d", Long.toHexString(this.value).toUpperCase(), this.value);
40+
}
3641
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_short.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexshort.java June 17, 2015, 21:36
2+
* Type_short.java June 17, 2015, 21:36
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -37,6 +37,6 @@ protected Type_short(short s) {
3737

3838
@Override
3939
public String toString() {
40-
return "0x" + Long.toHexString(this.value).toUpperCase() + " | " + String.format("%,d", this.value);
40+
return String.format("0x%s | %,d", Integer.toHexString(this.value).toUpperCase(), this.value);
4141
}
4242
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_sleb128.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexsleb128.java June 17, 2015, 21:41
2+
* Type_sleb128.java June 17, 2015, 21:41
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -34,4 +34,9 @@ protected Type_sleb128(int v, int l) {
3434
this.value = v;
3535
this.length = l;
3636
}
37+
38+
@Override
39+
public String toString() {
40+
return String.format("length=%d value=0x%s | %,d", this.length, Integer.toHexString(this.value).toUpperCase(), this.value);
41+
}
3742
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_ubyte.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexubyte.java June 17, 2015, 21:32
2+
* Type_ubyte.java June 17, 2015, 21:32
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -35,9 +35,14 @@ protected Type_ubyte(int i) {
3535
this.value = i;
3636
}
3737

38+
@Override
39+
public String toString() {
40+
return String.format("0x%s | %d", Integer.toHexString(this.value).toUpperCase(), this.value);
41+
}
42+
3843
/**
3944
* Get string for <code>ubyte</code> array.
40-
*
45+
*
4146
* @param bytes <code>ubyte</code> array
4247
* @return String value
4348
*/

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_uint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexuint.java June 17, 2015, 21:39
2+
* Type_uint.java June 17, 2015, 21:39
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -61,6 +61,6 @@ public String toString() {
6161
* @return The String for <code>l</code>
6262
*/
6363
public static String toString(long l) {
64-
return "0x" + Long.toHexString(l).toUpperCase() + " | " + String.format("%,d", l);
64+
return String.format("0x%s | %,d", Long.toHexString(l).toUpperCase(), l);
6565
}
6666
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_uleb128.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexuleb128.java June 17, 2015, 21:42
2+
* Type_uleb128.java June 17, 2015, 21:42
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -34,4 +34,9 @@ protected Type_uleb128(int v, int l) {
3434
this.value = v;
3535
this.length = l;
3636
}
37+
38+
@Override
39+
public String toString() {
40+
return String.format("length=%d value=0x%s | %,d", this.length, Integer.toHexString(this.value).toUpperCase(), this.value);
41+
}
3742
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_uleb128p1.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexuleb128p1.java June 17, 2015, 21:42
2+
* Type_uleb128p1.java June 17, 2015, 21:42
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -8,7 +8,7 @@
88

99
/**
1010
* Unsigned LEB128 plus 1, variable-length.
11-
*
11+
*
1212
* @author Amos Shi
1313
* @see
1414
* <a href="https://source.android.com/devices/tech/dalvik/dex-format.html">
@@ -34,4 +34,9 @@ protected Type_uleb128p1(int v, int l) {
3434
this.value = v;
3535
this.length = l;
3636
}
37+
38+
@Override
39+
public String toString() {
40+
return String.format("length=%d value=0x%s | %,d", this.length, Integer.toHexString(this.value).toUpperCase(), this.value);
41+
}
3742
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_ulong.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexulong.java June 17, 2015, 21:40
2+
* Type_ulong.java June 17, 2015, 21:40
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -36,4 +36,12 @@ public class Type_ulong {
3636
protected Type_ulong(BigInteger bi) {
3737
this.value = bi;
3838
}
39+
40+
@Override
41+
public String toString() {
42+
return String.format("0x%s | %s | %,d",
43+
this.value.toString(16).toUpperCase(),
44+
this.value.toString(),
45+
this.value.longValue());
46+
}
3947
}

FormatDEX/src/main/java/org/freeinternals/format/dex/Type_ushort.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* dexushort.java June 17, 2015, 21:37
2+
* Type_ushort.java June 17, 2015, 21:37
33
*
44
* Copyright 2015, FreeInternals.org. All rights reserved.
55
* Use is subject to license terms.
@@ -34,9 +34,9 @@ public class Type_ushort {
3434
protected Type_ushort(int i) {
3535
this.value = i;
3636
}
37-
37+
3838
@Override
3939
public String toString() {
40-
return "0x" + Long.toHexString(this.value).toUpperCase() + " | " + String.format("%,d", this.value);
41-
}
40+
return String.format("0x%s | %,d", Long.toHexString(this.value).toUpperCase(), this.value);
41+
}
4242
}

0 commit comments

Comments
 (0)