Skip to content

Commit

Permalink
#11 DEX format - parse items
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Aug 18, 2021
1 parent eb16e5e commit 3267f70
Show file tree
Hide file tree
Showing 73 changed files with 804 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import org.freeinternals.commonlib.core.FileFormat;
import java.io.File;
import java.io.IOException;
import javax.swing.Icon;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormatException;
import org.freeinternals.commonlib.ui.UITool;

/**
*
Expand All @@ -23,13 +25,18 @@ public DefaultFileFormat(final File file) throws IOException, FileFormatExceptio
super(file);
}


@Override
@SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule
public void generateTreeNode(DefaultMutableTreeNode parentNode) {
}
@Override
public String getContentTabName() {
return "Binary Data";
}

@Override
@SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule
public void generateTreeNode(DefaultMutableTreeNode parentNode) {
public Icon getIcon() {
return UITool.icon4BinaryFile();
}
}
111 changes: 104 additions & 7 deletions CommonLib/src/main/java/org/freeinternals/commonlib/ui/UITool.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
package org.freeinternals.commonlib.ui;

import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.Map;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.BytesTool;

Expand Down Expand Up @@ -58,14 +59,49 @@ public static void generateTreeNodeDiff(
diffStr)));
}

private static final Map<String, Icon> iconCache = new HashMap<>();
private static Icon icon(String url) {
return iconCache.computeIfAbsent(url, k -> new ImageIcon(UITool.class.getResource(url)));
}

/**
* Icon for binary file.
*
* @return Icon for binary file
* @see <a href="https://icons8.com/icon/38992/binary-file">Binary File</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4BinaryFile() {
return icon("/image/icons8-binary-file-20.png");
}

/**
* Icon for bytes.
*
* @return Icon for bytes
* @see <a href="https://icons8.com/icon/62371/scart">Scart</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Bytes() {
return icon("/image/icons8-scart-16.png");
}

/**
* Icon for checksum.
*
* @return Icon for checksum
* @see <a href="https://icons8.com/icon/sz8cPVwzLrMP/check-mark">Check Mark</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Checksum() {
return icon("/image/icons8-check-mark-16.png");
}

/**
* Icon for counter.
*
* @return Icon for counter
* @see <a href="https://icons8.com/icon/2U6ROkjIrXIA/abacus">Abacus</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Counter() {
return new ImageIcon(UITool.class.getResource("/image/icons8-abacus-16.png"));
return icon("/image/icons8-abacus-16.png");
}

/**
Expand All @@ -75,7 +111,27 @@ public static Icon icon4Counter() {
* @see <a href="https://icons8.com/icon/38933/apk">APK</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Dex() {
return new ImageIcon(UITool.class.getResource("/image/icons8-apk-20.png"));
return icon("/image/icons8-apk-20.png");
}

/**
* Icon for endian.
*
* @return Icon for endian
* @see <a href="https://icons8.com/icon/Xf1Gx1HbxVsm/up-down-arrow">Up Down Arrow</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Endian() {
return icon("/image/icons8-up-down-arrow-16.png");
}

/**
* Icon for length.
*
* @return Icon for length
* @see <a href="https://icons8.com/icon/44699/length">Length</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Length() {
return icon("/image/icons8-length-16.png");
}

/**
Expand All @@ -84,7 +140,17 @@ public static Icon icon4Dex() {
* @return Icon for Java
*/
public static Icon icon4Java() {
return new ImageIcon(UITool.class.getResource("/image/icons8-java-20.png"));
return icon("/image/icons8-java-20.png");
}

/**
* Icon for Offset / Location / Index.
*
* @return Icon for Offset
* @see <a href="https://icons8.com/icon/2gsR2g07AQvu/map-pin">Map Pin</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Offset() {
return icon("/image/icons8-map-pin-16.png");
}

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

/**
Expand All @@ -106,7 +172,38 @@ public static Icon icon4Magic() {
* by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Shortcut() {
return new ImageIcon(UITool.class.getResource("/image/icons8-shortcut-16.png"));
return icon("/image/icons8-shortcut-16.png");
}

/**
* Icon for signature.
*
* @return Icon for signature
* @see <a href="https://icons8.com/icon/bmicUxC0XDNt/signature">Signature</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Signature() {
return icon("/image/icons8-signature-16.png");
}

/**
* Icon for Size.
*
* @return Shortcut icon
* @see <a href="https://icons8.com/icon/d8VomliGByyY/page-size">Page Size</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Size() {
return icon("/image/icons8-page-size-16.png");
}


/**
* Icon for tag.
*
* @return tag icon
* @see <a href="https://icons8.com/icon/pmzH4rF8Lrv9/tag">Tag</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Tag() {
return icon("/image/icons8-tag-16.png");
}

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

/**
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CommonLib/src/main/resources/image/icons8-tag-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private void generateConstantPool() {
cp[i].getStartPos(),
1,
"tag: " + cp[i].tag.value,
UITool.icon4Tag(),
GenerateClassfileTreeNode.MESSAGES.getString("msg_cp_tag")
)));
cp[i].generateTreeNode(cpInfoNode, this.classFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.classfile.ClassFile;
import org.freeinternals.format.classfile.SignatureConvertor;
import org.freeinternals.format.classfile.u2;
Expand Down Expand Up @@ -74,7 +75,9 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 1,
2,
"name_index: " + this.name_index.value + " - " + classFile.getCPDescription(this.name_index.value)
"name_index: " + this.name_index.value + " - " + classFile.getCPDescription(this.name_index.value),
UITool.icon4Offset(),
MESSAGES.getString("msg_const_class_name_index")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.freeinternals.commonlib.core.BytesTool;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.classfile.ClassFile;

/**
Expand Down Expand Up @@ -77,12 +78,16 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 1,
4,
"high_bytes - value: " + this.doubleValue + " - " + BytesTool.getByteDataHexView(this.rawData)
"high_bytes - value: " + this.doubleValue + " - " + BytesTool.getByteDataHexView(this.rawData),
UITool.icon4Bytes(),
MESSAGES.getString("msg_const_double_bytes")
)));
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 5,
4,
"low_bytes"
"low_bytes",
UITool.icon4Bytes(),
MESSAGES.getString("msg_const_double_bytes")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.classfile.ClassFile;
import org.freeinternals.format.classfile.u2;

Expand Down Expand Up @@ -104,12 +105,15 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 1,
2,
"bootstrap_method_attr_index: " + this.bootstrap_method_attr_index.value
"bootstrap_method_attr_index: " + this.bootstrap_method_attr_index.value,
MESSAGES.getString("msg_const_dynamic_bootstrap_method_attr_index")
)));
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 3,
2,
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value)
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value),
UITool.icon4Offset(),
MESSAGES.getString("msg_const_dynamic_name_and_type_index")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.classfile.ClassFile;
import org.freeinternals.format.classfile.SignatureConvertor;

Expand Down Expand Up @@ -76,12 +77,16 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 1,
2,
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value)
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value),
UITool.icon4Offset(),
MESSAGES.getString("msg_const_ref_class_index")
)));
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 3,
2,
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value)
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value),
UITool.icon4Offset(),
MESSAGES.getString("msg_const_ref_name_and_type_index")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.freeinternals.commonlib.core.BytesTool;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.classfile.ClassFile;

/**
Expand Down Expand Up @@ -73,7 +74,9 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
this.getStartPos() + 1,
4,
"bytes: " + this.floatValue + " - " + BytesTool.getByteDataHexView(this.rawData)
"bytes: " + this.floatValue + " - " + BytesTool.getByteDataHexView(this.rawData),
UITool.icon4Bytes(),
MESSAGES.getString("msg_const_float_bytes")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.freeinternals.commonlib.core.BytesTool;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.classfile.ClassFile;
import static org.freeinternals.format.classfile.GenerateClassfileTreeNode.MESSAGES;

/**
* The class for the {@code CONSTANT_Integer_info} structure in constant pool.
Expand Down Expand Up @@ -72,7 +74,9 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 1,
4,
"bytes: " + this.integerValue + " - " + BytesTool.getByteDataHexView(this.rawData)
"bytes: " + this.integerValue + " - " + BytesTool.getByteDataHexView(this.rawData),
UITool.icon4Bytes(),
MESSAGES.getString("msg_const_int_bytes")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.classfile.ClassFile;

/**
Expand Down Expand Up @@ -58,12 +59,16 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 1,
2,
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value)
"class_index: " + this.class_index.value + " - " + classFile.getCPDescription(this.class_index.value),
UITool.icon4Offset(),
MESSAGES.getString("msg_const_ref_class_index")
)));
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 3,
2,
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value)
"name_and_type_index: " + this.name_and_type_index.value + " - " + classFile.getCPDescription(this.name_and_type_index.value),
UITool.icon4Offset(),
MESSAGES.getString("msg_const_ref_name_and_type_index")
)));
}
}
Loading

0 comments on commit 3267f70

Please sign in to comment.