Skip to content

Commit 7ac8c87

Browse files
committed
#11 DEX format - rename types
1 parent ee885b3 commit 7ac8c87

25 files changed

+210
-181
lines changed

FormatDEX/src/main/java/org/freeinternals/biv/ui/dex/TreeNodeGenerator.java

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
*/
77
package org.freeinternals.biv.ui.dex;
88

9+
import java.nio.charset.StandardCharsets;
910
import java.util.Map;
1011
import javax.swing.tree.DefaultMutableTreeNode;
1112
import org.freeinternals.commonlib.core.FileComponent;
1213
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
1314
import org.freeinternals.format.dex.ClassDefItem;
1415
import org.freeinternals.format.dex.DexFile;
15-
import org.freeinternals.format.dex.Dex_ubyte;
16-
import org.freeinternals.format.dex.Dex_uint;
17-
import org.freeinternals.format.dex.Dex_ushort;
16+
import org.freeinternals.format.dex.Type_ubyte;
17+
import org.freeinternals.format.dex.Type_uint;
18+
import org.freeinternals.format.dex.Type_ushort;
1819
import org.freeinternals.format.dex.FieldIdItem;
1920
import org.freeinternals.format.dex.HeaderItem;
2021
import org.freeinternals.format.dex.HeaderItem.Endian;
@@ -76,13 +77,13 @@ private void generateMagic() {
7677
magicNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
7778
startPos,
7879
DexFile.DEX_FILE_MAGIC1.size(),
79-
"magic 1")));
80+
"magic 1: " + new String(this.dexFile.magic1, StandardCharsets.UTF_8))));
8081
startPos += DexFile.DEX_FILE_MAGIC1.size();
8182

8283
magicNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
8384
startPos,
8485
DexFile.DEX_FILE_MAGIC2.size(),
85-
"magic 2")));
86+
"magic 2: " + new String(this.dexFile.magic2, StandardCharsets.UTF_8))));
8687
}
8788

8889
private void generateHeaderItem() {
@@ -96,76 +97,76 @@ private void generateHeaderItem() {
9697
"header_item"));
9798
this.rootNode.add(headerNode);
9899

99-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "checksum", header.checksum);
100+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "checksum", header.checksum);
100101
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
101102

102103
headerNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
103104
startPos,
104105
header.signature.length,
105-
"signature: " + Dex_ubyte.toString(header.signature))));
106+
"signature: " + Type_ubyte.toString(header.signature))));
106107
startPos += header.signature.length;
107108

108-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "file_size", header.file_size);
109+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "file_size", header.file_size);
109110
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
110111

111-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "header_size", header.header_size);
112+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "header_size", header.header_size);
112113
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
113114

114115
headerNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
115116
startPos,
116-
Dex_uint.LENGTH,
117+
Type_uint.LENGTH,
117118
"endian_tag: " + header.endian_tag.toString() + " / " + Endian.toString(header.endian_tag.intValue()))));
118-
startPos += Dex_uint.LENGTH;
119+
startPos += Type_uint.LENGTH;
119120

120-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "link_size", header.link_size);
121+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "link_size", header.link_size);
121122
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
122123

123-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "link_off", header.link_off);
124+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "link_off", header.link_off);
124125
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
125126

126-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "map_off", header.map_off);
127+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "map_off", header.map_off);
127128
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
128129

129-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "string_ids_size", header.string_ids_size);
130+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "string_ids_size", header.string_ids_size);
130131
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
131132

132-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "string_ids_off", header.string_ids_off);
133+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "string_ids_off", header.string_ids_off);
133134
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
134135

135-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "type_ids_size", header.type_ids_size);
136+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "type_ids_size", header.type_ids_size);
136137
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
137138

138-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "type_ids_off", header.type_ids_off);
139+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "type_ids_off", header.type_ids_off);
139140
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
140141

141-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "proto_ids_size", header.proto_ids_size);
142+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "proto_ids_size", header.proto_ids_size);
142143
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
143144

144-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "proto_ids_off", header.proto_ids_off);
145+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "proto_ids_off", header.proto_ids_off);
145146
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
146147

147-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "field_ids_size", header.field_ids_size);
148+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "field_ids_size", header.field_ids_size);
148149
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
149150

150-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "field_ids_off", header.field_ids_off);
151+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "field_ids_off", header.field_ids_off);
151152
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
152153

153-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "method_ids_size", header.method_ids_size);
154+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "method_ids_size", header.method_ids_size);
154155
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
155156

156-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "method_ids_off", header.method_ids_off);
157+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "method_ids_off", header.method_ids_off);
157158
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
158159

159-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "class_defs_size", header.class_defs_size);
160+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "class_defs_size", header.class_defs_size);
160161
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
161162

162-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "class_defs_off", header.class_defs_off);
163+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "class_defs_off", header.class_defs_off);
163164
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
164165

165-
nodeTemp = this.addNode(headerNode, startPos, Dex_uint.LENGTH, "data_size", header.data_size);
166+
nodeTemp = this.addNode(headerNode, startPos, Type_uint.LENGTH, "data_size", header.data_size);
166167
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
167168

168-
this.addNode(headerNode, startPos, Dex_uint.LENGTH, "data_off", header.data_off);
169+
this.addNode(headerNode, startPos, Type_uint.LENGTH, "data_off", header.data_off);
169170
}
170171

171172
private void generateStringIds() {
@@ -178,7 +179,7 @@ private void generateStringIds() {
178179

179180
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
180181
startPos,
181-
size * Dex_uint.LENGTH,
182+
size * Type_uint.LENGTH,
182183
"string_ids"));
183184
this.rootNode.add(node);
184185

@@ -212,7 +213,7 @@ private void generateTypeIds() {
212213

213214
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
214215
startPos,
215-
size * Dex_uint.LENGTH,
216+
size * Type_uint.LENGTH,
216217
"type_ids"));
217218
this.rootNode.add(node);
218219

@@ -253,11 +254,11 @@ private void generateProtoIds() {
253254
"proto_id_item[" + String.format("%,d", i) + "]"));
254255
node.add(itemNode);
255256

256-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "shorty_idx", item.shorty_idx);
257+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "shorty_idx", item.shorty_idx);
257258
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
258259
this.addNode(nodeTemp, 0, 0, "Value", this.dexFile.getString(item.shorty_idx.intValue()));
259260

260-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "return_type_idx", item.return_type_idx);
261+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "return_type_idx", item.return_type_idx);
261262
this.addNode(nodeTemp, 0, 0, "Value", this.dexFile.getTypeDescriptor(item.return_type_idx.intValue()));
262263
}
263264
}
@@ -285,13 +286,13 @@ private void generateFieldIds() {
285286
"proto_id_item[" + String.format("%,d", i) + "]"));
286287
node.add(itemNode);
287288

288-
nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, MESSAGE_CLASS_IDX, item.class_idx);
289+
nodeTemp = this.addNode(itemNode, startPos, Type_ushort.LENGTH, MESSAGE_CLASS_IDX, item.class_idx);
289290
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
290291

291-
nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, "type_idx", item.type_idx);
292+
nodeTemp = this.addNode(itemNode, startPos, Type_ushort.LENGTH, "type_idx", item.type_idx);
292293
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
293294

294-
this.addNode(itemNode, startPos, Dex_uint.LENGTH, "name_idx", item.name_idx);
295+
this.addNode(itemNode, startPos, Type_uint.LENGTH, "name_idx", item.name_idx);
295296
}
296297
}
297298

@@ -318,13 +319,13 @@ private void generateMethodIds() {
318319
"method_id_item[" + String.format("%,d", i) + "]"));
319320
node.add(itemNode);
320321

321-
nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, MESSAGE_CLASS_IDX, item.class_idx);
322+
nodeTemp = this.addNode(itemNode, startPos, Type_ushort.LENGTH, MESSAGE_CLASS_IDX, item.class_idx);
322323
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
323324

324-
nodeTemp = this.addNode(itemNode, startPos, Dex_ushort.LENGTH, "proto_idx", item.proto_idx);
325+
nodeTemp = this.addNode(itemNode, startPos, Type_ushort.LENGTH, "proto_idx", item.proto_idx);
325326
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
326327

327-
this.addNode(itemNode, startPos, Dex_uint.LENGTH, "name_idx", item.name_idx);
328+
this.addNode(itemNode, startPos, Type_uint.LENGTH, "name_idx", item.name_idx);
328329
}
329330
}
330331

@@ -351,28 +352,28 @@ private void generateClassDefs() {
351352
"class_def_item[" + String.format("%,d", i) + "]"));
352353
node.add(itemNode);
353354

354-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, MESSAGE_CLASS_IDX, item.class_idx);
355+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, MESSAGE_CLASS_IDX, item.class_idx);
355356
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
356357

357-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "access_flags", item.access_flags);
358+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "access_flags", item.access_flags);
358359
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
359360

360-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "superclass_idx", item.superclass_idx);
361+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "superclass_idx", item.superclass_idx);
361362
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
362363

363-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "interfaces_off", item.interfaces_off);
364+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "interfaces_off", item.interfaces_off);
364365
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
365366

366-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "source_file_idx", item.source_file_idx);
367+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "source_file_idx", item.source_file_idx);
367368
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
368369

369-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "annotations_off", item.annotations_off);
370+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "annotations_off", item.annotations_off);
370371
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
371372

372-
nodeTemp = this.addNode(itemNode, startPos, Dex_uint.LENGTH, "class_data_off", item.class_data_off);
373+
nodeTemp = this.addNode(itemNode, startPos, Type_uint.LENGTH, "class_data_off", item.class_data_off);
373374
startPos = ((JTreeNodeFileComponent)nodeTemp.getUserObject()).getLastPosPlus1();
374375

375-
this.addNode(itemNode, startPos, Dex_uint.LENGTH, "static_values_off", item.static_values_off);
376+
this.addNode(itemNode, startPos, Type_uint.LENGTH, "static_values_off", item.static_values_off);
376377
}
377378
}
378379

@@ -394,7 +395,7 @@ private void generateData() {
394395
DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
395396
startPos,
396397
fc.getLength(),
397-
Dex_uint.toString(startPos) + " - " + fc.getClass().getSimpleName()));
398+
Type_uint.toString(startPos) + " - " + fc.getClass().getSimpleName()));
398399
node.add(itemNode);
399400

400401
if (fc instanceof StringDataItem) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ public class ClassDefItem extends FileComponent {
3030
* index into the type_ids list for this class. This must be a class type,
3131
* and not an array or primitive type.
3232
*/
33-
public Dex_uint class_idx;
33+
public Type_uint class_idx;
3434

3535
/**
3636
* access flags for the class (public, final, etc.). See "access_flags
3737
* Definitions" for details.
3838
*/
39-
public Dex_uint access_flags;
39+
public Type_uint access_flags;
4040

4141
/**
4242
* index into the type_ids list for the superclass, or the constant value
4343
* NO_INDEX if this class has no superclass (i.e., it is a root class such
4444
* as Object). If present, this must be a class type, and not an array or
4545
* primitive type.
4646
*/
47-
public Dex_uint superclass_idx;
47+
public Type_uint superclass_idx;
4848

4949
/**
5050
* offset from the start of the file to the list of interfaces, or 0 if
@@ -53,7 +53,7 @@ public class ClassDefItem extends FileComponent {
5353
* elements of the list must be a class type (not an array or primitive
5454
* type), and there must not be any duplicates.
5555
*/
56-
public Dex_uint interfaces_off;
56+
public Type_uint interfaces_off;
5757

5858
/**
5959
* index into the string_ids list for the name of the file containing the
@@ -62,7 +62,7 @@ public class ClassDefItem extends FileComponent {
6262
* any given method may override this source file, but the expectation is
6363
* that most classes will only come from one source file.
6464
*/
65-
public Dex_uint source_file_idx;
65+
public Type_uint source_file_idx;
6666

6767
/**
6868
* offset from the start of the file to the annotations structure for this
@@ -71,7 +71,7 @@ public class ClassDefItem extends FileComponent {
7171
* the format specified by "annotations_directory_item" below, with all
7272
* items referring to this class as the definer.
7373
*/
74-
public Dex_uint annotations_off;
74+
public Type_uint annotations_off;
7575

7676
/**
7777
* offset from the start of the file to the associated class data for this
@@ -81,7 +81,7 @@ public class ClassDefItem extends FileComponent {
8181
* the format specified by "class_data_item" below, with all items referring
8282
* to this class as the definer.
8383
*/
84-
public Dex_uint class_data_off;
84+
public Type_uint class_data_off;
8585

8686
/**
8787
* offset from the start of the file to the list of initial values for
@@ -96,7 +96,7 @@ public class ClassDefItem extends FileComponent {
9696
* the array than there are static fields, then the leftover fields are
9797
* initialized with a type-appropriate 0 or null.
9898
*/
99-
public Dex_uint static_values_off;
99+
public Type_uint static_values_off;
100100

101101
ClassDefItem(PosDataInputStreamDex stream) throws IOException {
102102
super.startPos = stream.getPos();

0 commit comments

Comments
 (0)