Skip to content

Commit

Permalink
#11 DEX format UI refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Aug 30, 2021
1 parent 5c9dba7 commit ca5fb95
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -21,12 +22,13 @@
* </pre>
*/
@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit ca5fb95

Please sign in to comment.