diff --git a/CommonLib/src/main/java/org/freeinternals/commonlib/ui/GenerateTreeNodeFileFormat.java b/CommonLib/src/main/java/org/freeinternals/commonlib/ui/GenerateTreeNodeFileFormat.java index 3c18225..766cb36 100644 --- a/CommonLib/src/main/java/org/freeinternals/commonlib/ui/GenerateTreeNodeFileFormat.java +++ b/CommonLib/src/main/java/org/freeinternals/commonlib/ui/GenerateTreeNodeFileFormat.java @@ -28,6 +28,10 @@ public interface GenerateTreeNodeFileFormat { */ ResourceBundle getMessages(); + default DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, int startPos, int len, String name, Object value) { + return addNode(parentNode, startPos, len, name, value, null, null); + } + default DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, int startPos, int len, String fieldName, Object value, String msgkey, Icon icon) { JTreeNodeFileComponent fileComp = new JTreeNodeFileComponent( startPos, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/GenerateTreeNodeDexFile.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/GenerateTreeNodeDexFile.java index 69c3bfd..a58e23d 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/GenerateTreeNodeDexFile.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/GenerateTreeNodeDexFile.java @@ -10,6 +10,7 @@ import java.util.Locale; import java.util.ResourceBundle; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.ui.GenerateTreeNodeFileFormat; /** * Interface for generating tree node for {@link DexFile}. @@ -21,12 +22,13 @@ * */ @SuppressWarnings({"java:S115"}) -public interface GenerateTreeNodeDexFile { +public interface GenerateTreeNodeDexFile extends GenerateTreeNodeFileFormat { static final ResourceBundle MESSAGES = ResourceBundle.getBundle(JTreeDexFile.class.getPackageName() + ".MessagesBundle", Locale.ROOT); static final String FORMAT_STRING_STRING = "%s - %s"; - static final String msg_annotation_set_item = "msg_annotation_set_item"; - void generateTreeNode(final DefaultMutableTreeNode parentNode, final DexFile dexFile); - + @Override + default ResourceBundle getMessages() { + return MESSAGES; + } } diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/JTreeDexFile.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/JTreeDexFile.java index de06f5a..174acb7 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/JTreeDexFile.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/JTreeDexFile.java @@ -10,6 +10,7 @@ import java.util.logging.Logger; import javax.swing.Icon; import javax.swing.tree.DefaultMutableTreeNode; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.ui.GenerateTreeNode; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; @@ -30,38 +31,11 @@ public class JTreeDexFile implements GenerateTreeNodeDexFile { JTreeDexFile() { } - protected static DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, int startPos, int len, String name, Object value) { - return addNode(parentNode, startPos, len, name, value, null, null); - } - - protected static DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, int startPos, int len, String name, Object value, Icon icon) { - return addNode(parentNode, startPos, len, name, value, null, icon); - } - - protected static DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, int startPos, int len, String name, Object value, String msgkey) { - return addNode(parentNode, startPos, len, name, value, msgkey, null); - } - - protected static DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, int startPos, int len, String name, Object value, String msgkey, Icon icon) { - JTreeNodeFileComponent fileComp = new JTreeNodeFileComponent( - startPos, - len, - name + ": " + value.toString() - ); - if (msgkey != null) { - fileComp.setDescription(GenerateTreeNodeDexFile.MESSAGES.getString(msgkey)); - } - fileComp.setIcon(icon); - - DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileComp); - parentNode.add(node); - return node; - } - @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; this.generate_magic(parentNode, dexFile); - dexFile.header.generateTreeNode(parentNode); + dexFile.header.generateTreeNode(parentNode, dexFile); this.generate_string_ids(parentNode, dexFile); this.generate_type_ids(parentNode, dexFile); this.generate_proto_ids(parentNode, dexFile); diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_item.java index 0969da4..651e4d9 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_item.java @@ -9,10 +9,10 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -51,7 +51,8 @@ public String toString() { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, floatPos, @@ -127,7 +128,8 @@ public static class annotation_item extends FileComponent implements GenerateTre } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, floatPos, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_ref_list.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_ref_list.java index 0f47533..704c31b 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_ref_list.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/annotation_set_ref_list.java @@ -9,11 +9,10 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.GenerateTreeNodeDexFile.MESSAGES; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -53,8 +52,10 @@ public String toString() { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; + addNode(parentNode, floatPos, Type_uint.LENGTH, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/annotations_directory_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/annotations_directory_item.java index 6feffd1..fd19ac4 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/annotations_directory_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/annotations_directory_item.java @@ -9,11 +9,10 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.GenerateTreeNodeDexFile.FORMAT_STRING_STRING; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -84,8 +83,10 @@ public class annotations_directory_item extends FileComponent implements Generat } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; + DefaultMutableTreeNode classAnOffsetNode = addNode(parentNode, floatPos, Type_uint.LENGTH, @@ -229,8 +230,10 @@ public static class field_annotation extends FileComponent implements GenerateTr } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; + addNode(parentNode, floatPos, Type_uint.LENGTH, @@ -281,8 +284,10 @@ public static class method_annotation extends FileComponent implements GenerateT } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; + addNode(parentNode, floatPos, Type_uint.LENGTH, @@ -332,8 +337,10 @@ public static class parameter_annotation extends FileComponent implements Genera } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; + addNode(parentNode, floatPos, Type_uint.LENGTH, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/class_data_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/class_data_item.java index d75a808..1abaeec 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/class_data_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/class_data_item.java @@ -10,11 +10,10 @@ import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.GenerateTreeNodeDexFile.MESSAGES; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -93,8 +92,10 @@ public class class_data_item extends FileComponent implements GenerateTreeNodeDe @Override @SuppressWarnings("java:S3776") - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dex) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dex = (DexFile)format; int floatPos = super.startPos; + addNode(parentNode, floatPos, this.static_fields_size.length, "static_fields_size", this.static_fields_size, "msg_class_data_item__static_fields_size", UITool.icon4Size()); floatPos += this.static_fields_size.length; addNode(parentNode, floatPos, this.instance_fields_size.length, "instance_fields_size", this.instance_fields_size, "msg_class_data_item__instance_fields_size", UITool.icon4Size()); @@ -234,8 +235,10 @@ public static class encoded_field extends FileComponent implements GenerateTreeN } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; + field_id_item field = dexFile.field_ids[this.field_idx_diff.value]; addNode(parentNode, floatPos, @@ -274,8 +277,10 @@ public static class encoded_method extends FileComponent implements GenerateTree } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; + method_id_item method = dexFile.method_ids[this.method_idx_diff.value]; addNode(parentNode, floatPos, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/class_def_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/class_def_item.java index 4fb48cc..7550c94 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/class_def_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/class_def_item.java @@ -10,10 +10,10 @@ import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -220,7 +220,8 @@ public String get_source_file(DexFile dexFile) { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, floatPos, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/code_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/code_item.java index 6487424..7c820c7 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/code_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/code_item.java @@ -9,10 +9,10 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.GenerateTreeNode; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -84,7 +84,7 @@ public class code_item extends FileComponent implements GenerateTreeNodeDexFile } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat dexFile) { int floatPos = super.startPos; addNode(parentNode, floatPos, Type_ushort.LENGTH, "registers_size", this.registers_size, "msg_code_item__registers_size", UITool.icon4Size()); floatPos += Type_ushort.LENGTH; diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_annotation.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_annotation.java index f21358f..59dc137 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_annotation.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_annotation.java @@ -11,11 +11,10 @@ import java.util.logging.Logger; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.GenerateTreeNodeDexFile.MESSAGES; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -76,7 +75,8 @@ public String toString(DexFile dexFile) { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, floatPos, @@ -150,7 +150,8 @@ public static class annotation_element extends FileComponent implements Generate } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, floatPos, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array.java index f22af3c..e59e315 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array.java @@ -11,10 +11,10 @@ import java.util.logging.Logger; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -59,7 +59,7 @@ public String toString() { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat dexFile) { int floatPos = super.startPos; addNode(parentNode, floatPos, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array_item.java index fb7d785..5ac5ab7 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/encoded_array_item.java @@ -9,9 +9,9 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -35,7 +35,7 @@ public class encoded_array_item extends FileComponent implements GenerateTreeNod } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat dexFile) { DefaultMutableTreeNode valueNode = addNode(parentNode, super.startPos, this.value.getLength(), "value", this.value, "msg_encoded_array_item__value", UITool.icon4Data()); this.value.generateTreeNode(valueNode, dexFile); } 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 e9c0246..2a59b41 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 @@ -9,9 +9,9 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -354,7 +354,8 @@ public String toString() { @Override @SuppressWarnings({"java:S2259", "java:S3776"}) - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dex) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat fileFormat) { + DexFile dex = (DexFile)fileFormat; int floatPos = super.startPos; ValueFormat format = ValueFormat.valueOf(this.value_type); diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/field_id_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/field_id_item.java index ed4d15d..b8d14e8 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/field_id_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/field_id_item.java @@ -9,8 +9,8 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -148,7 +148,8 @@ public String toString(DexFile dexFile) { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/header_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/header_item.java index 5ae1e11..841065d 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/header_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/header_item.java @@ -10,7 +10,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.BytesTool; import org.freeinternals.commonlib.core.FileComponent; -import org.freeinternals.commonlib.ui.GenerateTreeNode; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; @@ -26,7 +26,7 @@ * */ @SuppressWarnings({"java:S101", "java:S116", "java:S1104"}) -public class header_item extends FileComponent implements GenerateTreeNode { +public class header_item extends FileComponent implements GenerateTreeNodeDexFile { /** * @see map_list.TypeCodes#TYPE_HEADER_ITEM @@ -123,7 +123,7 @@ public class header_item extends FileComponent implements GenerateTreeNode { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat fileFormat) { DefaultMutableTreeNode nodeTemp; int floatPos = this.getStartPos(); @@ -133,16 +133,16 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { "header_item")); parentNode.add(headerNode); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "checksum", this.checksum, "msg_header_item_checksum", UITool.icon4Checksum()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "checksum", this.checksum, "msg_header_item_checksum", UITool.icon4Checksum()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, this.signature.length, "signature", Type_ubyte.toString(this.signature), "msg_header_item_signature", UITool.icon4Signature()); + nodeTemp = addNode(headerNode, floatPos, this.signature.length, "signature", Type_ubyte.toString(this.signature), "msg_header_item_signature", UITool.icon4Signature()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "file_size", this.file_size, "msg_header_item_file_size", UITool.icon4Size()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "file_size", this.file_size, "msg_header_item_file_size", UITool.icon4Size()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "header_size", this.header_size, "msg_header_item_header_size", UITool.icon4Size()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "header_size", this.header_size, "msg_header_item_header_size", UITool.icon4Size()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); headerNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent( @@ -154,57 +154,58 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode) { ))); floatPos += Type_uint.LENGTH; - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "link_size", this.link_size, "msg_header_item_link_size", UITool.icon4Size()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "link_size", this.link_size, "msg_header_item_link_size", UITool.icon4Size()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "link_off", this.link_off, "msg_header_item_link_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "link_off", this.link_off, "msg_header_item_link_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "map_off", this.map_off, "msg_header_item_map_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "map_off", this.map_off, "msg_header_item_map_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "string_ids_size", this.string_ids_size, "msg_header_item_string_ids_size", UITool.icon4Counter()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "string_ids_size", this.string_ids_size, "msg_header_item_string_ids_size", UITool.icon4Counter()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "string_ids_off", this.string_ids_off, "msg_header_item_string_ids_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "string_ids_off", this.string_ids_off, "msg_header_item_string_ids_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "type_ids_size", this.type_ids_size, "msg_header_item_type_ids_size", UITool.icon4Counter()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "type_ids_size", this.type_ids_size, "msg_header_item_type_ids_size", UITool.icon4Counter()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "type_ids_off", this.type_ids_off, "msg_header_item_type_ids_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "type_ids_off", this.type_ids_off, "msg_header_item_type_ids_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "proto_ids_size", this.proto_ids_size, "msg_header_item_proto_ids_size", UITool.icon4Counter()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "proto_ids_size", this.proto_ids_size, "msg_header_item_proto_ids_size", UITool.icon4Counter()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "proto_ids_off", this.proto_ids_off, "msg_header_item_proto_ids_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "proto_ids_off", this.proto_ids_off, "msg_header_item_proto_ids_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "field_ids_size", this.field_ids_size, "msg_header_item_field_ids_size", UITool.icon4Counter()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "field_ids_size", this.field_ids_size, "msg_header_item_field_ids_size", UITool.icon4Counter()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "field_ids_off", this.field_ids_off, "msg_header_item_field_ids_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "field_ids_off", this.field_ids_off, "msg_header_item_field_ids_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "method_ids_size", this.method_ids_size, "msg_header_item_method_ids_size", UITool.icon4Counter()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "method_ids_size", this.method_ids_size, "msg_header_item_method_ids_size", UITool.icon4Counter()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "method_ids_off", this.method_ids_off, "msg_header_item_method_ids_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "method_ids_off", this.method_ids_off, "msg_header_item_method_ids_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "class_defs_size", this.class_defs_size, "msg_header_item_class_defs_size", UITool.icon4Counter()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "class_defs_size", this.class_defs_size, "msg_header_item_class_defs_size", UITool.icon4Counter()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "class_defs_off", this.class_defs_off, "msg_header_item_class_defs_off", UITool.icon4Offset()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "class_defs_off", this.class_defs_off, "msg_header_item_class_defs_off", UITool.icon4Offset()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - nodeTemp = JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "data_size", this.data_size, "msg_header_item_data_size", UITool.icon4Counter()); + nodeTemp = addNode(headerNode, floatPos, Type_uint.LENGTH, "data_size", this.data_size, "msg_header_item_data_size", UITool.icon4Counter()); floatPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1(); - JTreeDexFile.addNode(headerNode, floatPos, Type_uint.LENGTH, "data_off", this.data_off, "msg_header_item_data_off", UITool.icon4Offset()); + addNode(headerNode, floatPos, Type_uint.LENGTH, "data_off", this.data_off, "msg_header_item_data_off", UITool.icon4Offset()); } + /** * The constant {@link Endian#ENDIAN_CONSTANT} is used to indicate the * endianness of the file in which it is found. Although the standard .dex diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/method_handle_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/method_handle_item.java index 7cfc430..3ba5154 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/method_handle_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/method_handle_item.java @@ -9,9 +9,9 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.ui.GenerateTreeNode; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -24,7 +24,7 @@ * */ @SuppressWarnings({"java:S101", "java:S116", "java:S1104"}) -public class method_handle_item extends FileComponent implements GenerateTreeNode { +public class method_handle_item extends FileComponent implements GenerateTreeNodeDexFile { /** * Item Size In Bytes. @@ -61,14 +61,14 @@ public class method_handle_item extends FileComponent implements GenerateTreeNod } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat fileFormat) { int floatPos = this.getStartPos(); addNode(parentNode, floatPos, Type_ushort.LENGTH, "string_data_off", this.method_handle_type, "msg_method_handle_item__method_handle_type", UITool.icon4Offset()); floatPos += Type_ushort.LENGTH; addNode(parentNode, floatPos, Type_ushort.LENGTH, "unused", "(unused)"); floatPos += Type_ushort.LENGTH; - addNode(parentNode, floatPos, Type_ushort.LENGTH, "field_or_method_id", this.field_or_method_id, "msg_method_handle_item__field_or_method_id"); // add icon later + addNode(parentNode, floatPos, Type_ushort.LENGTH, "field_or_method_id", this.field_or_method_id, "msg_method_handle_item__field_or_method_id", UITool.icon4Index()); floatPos += Type_ushort.LENGTH; addNode(parentNode, floatPos, Type_ushort.LENGTH, "unused", "(unused)"); } diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/method_id_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/method_id_item.java index a3abb3f..fad4f11 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/method_id_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/method_id_item.java @@ -9,8 +9,8 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -134,7 +134,8 @@ public String toString(DexFile dexFile) { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/proto_id_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/proto_id_item.java index 3b3878c..0947954 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/proto_id_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/proto_id_item.java @@ -9,9 +9,9 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -140,7 +140,8 @@ public String toString(DexFile dexFile) { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) { + DexFile dexFile = (DexFile)format; int floatPos = super.startPos; addNode(parentNode, diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/string_data_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/string_data_item.java index 202fc4a..0e8db24 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/string_data_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/string_data_item.java @@ -10,11 +10,10 @@ import java.nio.charset.StandardCharsets; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; -import org.freeinternals.commonlib.ui.GenerateTreeNode; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -27,7 +26,7 @@ * */ @SuppressWarnings({"java:S101", "java:S116", "java:S1104"}) -public class string_data_item extends FileComponent implements GenerateTreeNode { +public class string_data_item extends FileComponent implements GenerateTreeNodeDexFile { /** * size of this string, in UTF-16 code units (which is the "string length" @@ -69,7 +68,7 @@ public String getString() { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat fileFormat) { DefaultMutableTreeNode nodeTemp; int floatPos = this.getStartPos(); int utf16Size = this.utf16_size.value; diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/string_id_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/string_id_item.java index 4886e7d..441a627 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/string_id_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/string_id_item.java @@ -9,9 +9,9 @@ import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.ui.JTreeNodeFileComponent; import org.freeinternals.commonlib.ui.UITool; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -46,7 +46,8 @@ public class string_id_item extends FileComponent implements GenerateTreeNodeDex } @Override - public void generateTreeNode(final DefaultMutableTreeNode parentNode, final DexFile dexFile) { + public void generateTreeNode(final DefaultMutableTreeNode parentNode, final FileFormat format) { + DexFile dexFile = (DexFile)format; DefaultMutableTreeNode offsetNode = addNode(parentNode, this.startPos, Type_uint.LENGTH, "string_data_off", string_data_off, "msg_string_id_item__string_data_off", UITool.icon4Offset()); string_data_item item = (string_data_item) dexFile.data.get(this.string_data_off.value); @@ -58,6 +59,6 @@ public void generateTreeNode(final DefaultMutableTreeNode parentNode, final DexF GenerateTreeNodeDexFile.MESSAGES.getString("msg_string_data_item") )); offsetNode.add(dataNode); - item.generateTreeNode(dataNode); + item.generateTreeNode(dataNode, format); } } diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/type_id_item.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/type_id_item.java index 5fc66e9..e0a86ce 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/type_id_item.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/type_id_item.java @@ -11,10 +11,10 @@ import java.util.logging.Logger; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.UITool; import org.freeinternals.format.classfile.SignatureConvertor; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * Type identifiers list item. @@ -94,12 +94,12 @@ public SignatureConvertor.SignatureResult get_descriptor_jls(DexFile dexFile) { } @Override - public void generateTreeNode(DefaultMutableTreeNode parentNode, DexFile dexFile) { + public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat dexFile) { addNode(parentNode, this.startPos, Type_uint.LENGTH, "descriptor_idx", - String.format("%s - %s", descriptor_idx, this.get_descriptor(dexFile)), + String.format("%s - %s", descriptor_idx, this.get_descriptor((DexFile)dexFile)), "msg_type_id_item__descriptor_idx", UITool.icon4Offset() ); diff --git a/FormatDEX/src/main/java/org/freeinternals/format/dex/type_list.java b/FormatDEX/src/main/java/org/freeinternals/format/dex/type_list.java index ebcec09..22c1bc9 100644 --- a/FormatDEX/src/main/java/org/freeinternals/format/dex/type_list.java +++ b/FormatDEX/src/main/java/org/freeinternals/format/dex/type_list.java @@ -11,10 +11,10 @@ import java.util.List; import javax.swing.tree.DefaultMutableTreeNode; import org.freeinternals.commonlib.core.FileComponent; +import org.freeinternals.commonlib.core.FileFormat; import org.freeinternals.commonlib.core.FileFormatException; import org.freeinternals.commonlib.ui.UITool; import org.freeinternals.format.classfile.SignatureConvertor; -import static org.freeinternals.format.dex.JTreeDexFile.addNode; /** * @@ -50,7 +50,7 @@ public class type_list extends FileComponent implements GenerateTreeNodeDexFile } @Override - public void generateTreeNode(final DefaultMutableTreeNode parentNode, final DexFile dexFile) { + public void generateTreeNode(final DefaultMutableTreeNode parentNode, final FileFormat dexFile) { int floatPos = this.getStartPos(); addNode(parentNode, @@ -70,7 +70,7 @@ public void generateTreeNode(final DefaultMutableTreeNode parentNode, final DexF item.getStartPos(), item.getLength(), String.format("type_item[%d].type_idx", i), - item.get_type_jls(dexFile), + item.get_type_jls((DexFile)dexFile), "msg_type_item__type_idx", UITool.icon4Index() ); diff --git a/README.md b/README.md index 8cfa464..18079db 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ An application to show binary file internals visually & interactively for the meaning of every byte. Supported Formats + * [BMP](https://en.wikipedia.org/wiki/BMP_file_format) file * [Class](https://docs.oracle.com/javase/specs/) file * Programming Logic: http://www.codeproject.com/Articles/35915/Java-Class-Viewer @@ -12,11 +13,13 @@ Supported Formats * [ZIP](https://en.wikipedia.org/wiki/ZIP_(file_format)) file Will supported formats + * [DEX](https://en.wikipedia.org/wiki/Dalvik_(software)) file for Android (in progress) * [ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) file for `*nix` systems (todo) * [PE](https://en.wikipedia.org/wiki/Portable_Executable) file for Windows (todo) Legacy note + * The orignal *Java Class Viewer* has been retired, and merged into *Binary Internals Viewer* since Apr 2021 Build the Source Code @@ -32,6 +35,7 @@ Test Case * `./masstest-format-class.sh` Parse all `.class` files in current Ubuntu linux system `default-java` folder Download + * Download Application: https://github.com/amosshi/freeinternals/releases Usage guide @@ -40,3 +44,8 @@ Usage guide * `java -jar BinaryInternalsViewer-3.0.jar` * Menu item: `File` > `Open...` * Choose the binary file to view + +Dependency + +* This application do not rely on any 3rd party libraries, easy to add it to your project +