Skip to content

Commit 3267f70

Browse files
committed
#11 DEX format - parse items
1 parent eb16e5e commit 3267f70

File tree

73 files changed

+804
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+804
-152
lines changed

BinaryInternalsViewer/src/main/java/org/freeinternals/biv/plugin/DefaultFileFormat.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import org.freeinternals.commonlib.core.FileFormat;
1010
import java.io.File;
1111
import java.io.IOException;
12+
import javax.swing.Icon;
1213
import javax.swing.tree.DefaultMutableTreeNode;
1314
import org.freeinternals.commonlib.core.FileFormatException;
15+
import org.freeinternals.commonlib.ui.UITool;
1416

1517
/**
1618
*
@@ -23,13 +25,18 @@ public DefaultFileFormat(final File file) throws IOException, FileFormatExceptio
2325
super(file);
2426
}
2527

28+
29+
@Override
30+
@SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule
31+
public void generateTreeNode(DefaultMutableTreeNode parentNode) {
32+
}
2633
@Override
2734
public String getContentTabName() {
2835
return "Binary Data";
2936
}
3037

3138
@Override
32-
@SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule
33-
public void generateTreeNode(DefaultMutableTreeNode parentNode) {
39+
public Icon getIcon() {
40+
return UITool.icon4BinaryFile();
3441
}
3542
}

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

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
package org.freeinternals.commonlib.ui;
88

99
import java.awt.BorderLayout;
10+
import java.util.HashMap;
11+
import java.util.Map;
1012
import javax.swing.Icon;
1113
import javax.swing.ImageIcon;
1214
import javax.swing.JDialog;
1315
import javax.swing.JFrame;
1416
import javax.swing.JPanel;
15-
import javax.swing.UIManager;
1617
import javax.swing.tree.DefaultMutableTreeNode;
1718
import org.freeinternals.commonlib.core.BytesTool;
1819

@@ -58,14 +59,49 @@ public static void generateTreeNodeDiff(
5859
diffStr)));
5960
}
6061

62+
private static final Map<String, Icon> iconCache = new HashMap<>();
63+
private static Icon icon(String url) {
64+
return iconCache.computeIfAbsent(url, k -> new ImageIcon(UITool.class.getResource(url)));
65+
}
66+
67+
/**
68+
* Icon for binary file.
69+
*
70+
* @return Icon for binary file
71+
* @see <a href="https://icons8.com/icon/38992/binary-file">Binary File</a> icon by <a href="https://icons8.com">Icons8</a>
72+
*/
73+
public static Icon icon4BinaryFile() {
74+
return icon("/image/icons8-binary-file-20.png");
75+
}
76+
77+
/**
78+
* Icon for bytes.
79+
*
80+
* @return Icon for bytes
81+
* @see <a href="https://icons8.com/icon/62371/scart">Scart</a> icon by <a href="https://icons8.com">Icons8</a>
82+
*/
83+
public static Icon icon4Bytes() {
84+
return icon("/image/icons8-scart-16.png");
85+
}
86+
87+
/**
88+
* Icon for checksum.
89+
*
90+
* @return Icon for checksum
91+
* @see <a href="https://icons8.com/icon/sz8cPVwzLrMP/check-mark">Check Mark</a> icon by <a href="https://icons8.com">Icons8</a>
92+
*/
93+
public static Icon icon4Checksum() {
94+
return icon("/image/icons8-check-mark-16.png");
95+
}
96+
6197
/**
6298
* Icon for counter.
6399
*
64100
* @return Icon for counter
65101
* @see <a href="https://icons8.com/icon/2U6ROkjIrXIA/abacus">Abacus</a> icon by <a href="https://icons8.com">Icons8</a>
66102
*/
67103
public static Icon icon4Counter() {
68-
return new ImageIcon(UITool.class.getResource("/image/icons8-abacus-16.png"));
104+
return icon("/image/icons8-abacus-16.png");
69105
}
70106

71107
/**
@@ -75,7 +111,27 @@ public static Icon icon4Counter() {
75111
* @see <a href="https://icons8.com/icon/38933/apk">APK</a> icon by <a href="https://icons8.com">Icons8</a>
76112
*/
77113
public static Icon icon4Dex() {
78-
return new ImageIcon(UITool.class.getResource("/image/icons8-apk-20.png"));
114+
return icon("/image/icons8-apk-20.png");
115+
}
116+
117+
/**
118+
* Icon for endian.
119+
*
120+
* @return Icon for endian
121+
* @see <a href="https://icons8.com/icon/Xf1Gx1HbxVsm/up-down-arrow">Up Down Arrow</a> icon by <a href="https://icons8.com">Icons8</a>
122+
*/
123+
public static Icon icon4Endian() {
124+
return icon("/image/icons8-up-down-arrow-16.png");
125+
}
126+
127+
/**
128+
* Icon for length.
129+
*
130+
* @return Icon for length
131+
* @see <a href="https://icons8.com/icon/44699/length">Length</a> icon by <a href="https://icons8.com">Icons8</a>
132+
*/
133+
public static Icon icon4Length() {
134+
return icon("/image/icons8-length-16.png");
79135
}
80136

81137
/**
@@ -84,7 +140,17 @@ public static Icon icon4Dex() {
84140
* @return Icon for Java
85141
*/
86142
public static Icon icon4Java() {
87-
return new ImageIcon(UITool.class.getResource("/image/icons8-java-20.png"));
143+
return icon("/image/icons8-java-20.png");
144+
}
145+
146+
/**
147+
* Icon for Offset / Location / Index.
148+
*
149+
* @return Icon for Offset
150+
* @see <a href="https://icons8.com/icon/2gsR2g07AQvu/map-pin">Map Pin</a> icon by <a href="https://icons8.com">Icons8</a>
151+
*/
152+
public static Icon icon4Offset() {
153+
return icon("/image/icons8-map-pin-16.png");
88154
}
89155

90156
/**
@@ -94,7 +160,7 @@ public static Icon icon4Java() {
94160
* @see <a href="https://icons8.com/icon/q8t3iE9rg6YF/magic-wand">Magic Wand</a> icon by <a href="https://icons8.com">Icons8</a>
95161
*/
96162
public static Icon icon4Magic() {
97-
return new ImageIcon(UITool.class.getResource("/image/icons8-magic-wand-16.png"));
163+
return icon("/image/icons8-magic-wand-16.png");
98164
}
99165

100166
/**
@@ -106,7 +172,38 @@ public static Icon icon4Magic() {
106172
* by <a href="https://icons8.com">Icons8</a>
107173
*/
108174
public static Icon icon4Shortcut() {
109-
return new ImageIcon(UITool.class.getResource("/image/icons8-shortcut-16.png"));
175+
return icon("/image/icons8-shortcut-16.png");
176+
}
177+
178+
/**
179+
* Icon for signature.
180+
*
181+
* @return Icon for signature
182+
* @see <a href="https://icons8.com/icon/bmicUxC0XDNt/signature">Signature</a> icon by <a href="https://icons8.com">Icons8</a>
183+
*/
184+
public static Icon icon4Signature() {
185+
return icon("/image/icons8-signature-16.png");
186+
}
187+
188+
/**
189+
* Icon for Size.
190+
*
191+
* @return Shortcut icon
192+
* @see <a href="https://icons8.com/icon/d8VomliGByyY/page-size">Page Size</a> icon by <a href="https://icons8.com">Icons8</a>
193+
*/
194+
public static Icon icon4Size() {
195+
return icon("/image/icons8-page-size-16.png");
196+
}
197+
198+
199+
/**
200+
* Icon for tag.
201+
*
202+
* @return tag icon
203+
* @see <a href="https://icons8.com/icon/pmzH4rF8Lrv9/tag">Tag</a> icon by <a href="https://icons8.com">Icons8</a>
204+
*/
205+
public static Icon icon4Tag() {
206+
return icon("/image/icons8-tag-16.png");
110207
}
111208

112209
/**
@@ -117,7 +214,7 @@ public static Icon icon4Shortcut() {
117214
* @see <a href="https://icons8.com/icon/59954/versions">Versions</a> icon by <a href="https://icons8.com">Icons8</a>
118215
*/
119216
public static Icon icon4Versions() {
120-
return new ImageIcon(UITool.class.getResource("/image/icons8-versions-16.png"));
217+
return icon("/image/icons8-versions-16.png");
121218
}
122219

123220
/**
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

FormatCLASS/src/main/java/org/freeinternals/format/classfile/JTreeClassFile.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private void generateConstantPool() {
113113
cp[i].getStartPos(),
114114
1,
115115
"tag: " + cp[i].tag.value,
116+
UITool.icon4Tag(),
116117
GenerateClassfileTreeNode.MESSAGES.getString("msg_cp_tag")
117118
)));
118119
cp[i].generateTreeNode(cpInfoNode, this.classFile);

FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CONSTANT_Class_info.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javax.swing.tree.DefaultMutableTreeNode;
1111
import org.freeinternals.commonlib.core.PosDataInputStream;
1212
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
13+
import org.freeinternals.commonlib.ui.UITool;
1314
import org.freeinternals.format.classfile.ClassFile;
1415
import org.freeinternals.format.classfile.SignatureConvertor;
1516
import org.freeinternals.format.classfile.u2;
@@ -74,7 +75,9 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
7475
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
7576
super.startPos + 1,
7677
2,
77-
"name_index: " + this.name_index.value + " - " + classFile.getCPDescription(this.name_index.value)
78+
"name_index: " + this.name_index.value + " - " + classFile.getCPDescription(this.name_index.value),
79+
UITool.icon4Offset(),
80+
MESSAGES.getString("msg_const_class_name_index")
7881
)));
7982
}
8083
}

FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CONSTANT_Double_info.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.freeinternals.commonlib.core.BytesTool;
1212
import org.freeinternals.commonlib.core.PosDataInputStream;
1313
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
14+
import org.freeinternals.commonlib.ui.UITool;
1415
import org.freeinternals.format.classfile.ClassFile;
1516

1617
/**
@@ -77,12 +78,16 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
7778
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
7879
super.startPos + 1,
7980
4,
80-
"high_bytes - value: " + this.doubleValue + " - " + BytesTool.getByteDataHexView(this.rawData)
81+
"high_bytes - value: " + this.doubleValue + " - " + BytesTool.getByteDataHexView(this.rawData),
82+
UITool.icon4Bytes(),
83+
MESSAGES.getString("msg_const_double_bytes")
8184
)));
8285
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
8386
super.startPos + 5,
8487
4,
85-
"low_bytes"
88+
"low_bytes",
89+
UITool.icon4Bytes(),
90+
MESSAGES.getString("msg_const_double_bytes")
8691
)));
8792
}
8893
}

FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CONSTANT_Dynamic_info.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.freeinternals.commonlib.core.PosDataInputStream;
1212
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
1313
import org.freeinternals.commonlib.core.FileFormatException;
14+
import org.freeinternals.commonlib.ui.UITool;
1415
import org.freeinternals.format.classfile.ClassFile;
1516
import org.freeinternals.format.classfile.u2;
1617

@@ -104,12 +105,15 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
104105
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
105106
startPos + 1,
106107
2,
107-
"bootstrap_method_attr_index: " + this.bootstrap_method_attr_index.value
108+
"bootstrap_method_attr_index: " + this.bootstrap_method_attr_index.value,
109+
MESSAGES.getString("msg_const_dynamic_bootstrap_method_attr_index")
108110
)));
109111
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
110112
startPos + 3,
111113
2,
112-
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value)
114+
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value),
115+
UITool.icon4Offset(),
116+
MESSAGES.getString("msg_const_dynamic_name_and_type_index")
113117
)));
114118
}
115119
}

FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CONSTANT_Fieldref_info.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.freeinternals.commonlib.core.PosDataInputStream;
1414
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
1515
import org.freeinternals.commonlib.core.FileFormatException;
16+
import org.freeinternals.commonlib.ui.UITool;
1617
import org.freeinternals.format.classfile.ClassFile;
1718
import org.freeinternals.format.classfile.SignatureConvertor;
1819

@@ -76,12 +77,16 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
7677
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
7778
super.startPos + 1,
7879
2,
79-
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value)
80+
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value),
81+
UITool.icon4Offset(),
82+
MESSAGES.getString("msg_const_ref_class_index")
8083
)));
8184
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
8285
super.startPos + 3,
8386
2,
84-
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value)
87+
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value),
88+
UITool.icon4Offset(),
89+
MESSAGES.getString("msg_const_ref_name_and_type_index")
8590
)));
8691
}
8792
}

FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CONSTANT_Float_info.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.freeinternals.commonlib.core.BytesTool;
1212
import org.freeinternals.commonlib.core.PosDataInputStream;
1313
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
14+
import org.freeinternals.commonlib.ui.UITool;
1415
import org.freeinternals.format.classfile.ClassFile;
1516

1617
/**
@@ -73,7 +74,9 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
7374
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
7475
this.getStartPos() + 1,
7576
4,
76-
"bytes: " + this.floatValue + " - " + BytesTool.getByteDataHexView(this.rawData)
77+
"bytes: " + this.floatValue + " - " + BytesTool.getByteDataHexView(this.rawData),
78+
UITool.icon4Bytes(),
79+
MESSAGES.getString("msg_const_float_bytes")
7780
)));
7881
}
7982
}

FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CONSTANT_Integer_info.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import org.freeinternals.commonlib.core.BytesTool;
1212
import org.freeinternals.commonlib.core.PosDataInputStream;
1313
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
14+
import org.freeinternals.commonlib.ui.UITool;
1415
import org.freeinternals.format.classfile.ClassFile;
16+
import static org.freeinternals.format.classfile.GenerateClassfileTreeNode.MESSAGES;
1517

1618
/**
1719
* The class for the {@code CONSTANT_Integer_info} structure in constant pool.
@@ -72,7 +74,9 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
7274
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
7375
super.startPos + 1,
7476
4,
75-
"bytes: " + this.integerValue + " - " + BytesTool.getByteDataHexView(this.rawData)
77+
"bytes: " + this.integerValue + " - " + BytesTool.getByteDataHexView(this.rawData),
78+
UITool.icon4Bytes(),
79+
MESSAGES.getString("msg_const_int_bytes")
7680
)));
7781
}
7882
}

FormatCLASS/src/main/java/org/freeinternals/format/classfile/constant/CONSTANT_InterfaceMethodref_info.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javax.swing.tree.DefaultMutableTreeNode;
1111
import org.freeinternals.commonlib.core.PosDataInputStream;
1212
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
13+
import org.freeinternals.commonlib.ui.UITool;
1314
import org.freeinternals.format.classfile.ClassFile;
1415

1516
/**
@@ -58,12 +59,16 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
5859
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
5960
startPos + 1,
6061
2,
61-
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value)
62+
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value),
63+
UITool.icon4Offset(),
64+
MESSAGES.getString("msg_const_ref_class_index")
6265
)));
6366
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
6467
startPos + 3,
6568
2,
66-
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value)
69+
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value),
70+
UITool.icon4Offset(),
71+
MESSAGES.getString("msg_const_ref_name_and_type_index")
6772
)));
6873
}
6974
}

0 commit comments

Comments
 (0)