Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select hex editor bytes when an instance in an array is selected #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/main/java/io/kaitai/struct/visualizer/DataNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public DataNode(int depth, Object value, String name) {
this(depth, value, null, name, null, null);
}

private DataNode(int depth, Object value, String name, Integer posStart, Integer posEnd) {
this(depth, value, null, name, posStart, posEnd);
}

private DataNode(int depth, Object value, Method method, Integer posStart, Integer posEnd) {
this(depth, value, method, null, posStart, posEnd);
}
Expand Down Expand Up @@ -134,7 +138,16 @@ protected List<DataNode> doInBackground() throws Exception {
Object el = list.get(i);
String arrayIdxStr = String.format("%04d", i);

children.add(new DataNode(depth + 1, el, arrayIdxStr));
DataNode parentNode = (DataNode) parent;
if (parentNode.value instanceof KaitaiStruct) {
KaitaiStruct parentKaitaiStruct = (KaitaiStruct) parentNode.value;
DebugAids debug = DebugAids.fromStruct(parentKaitaiStruct);
Integer posStart = debug.getArrayStart(name, i);
Integer posEnd = debug.getArrayEnd(name, i);
children.add(new DataNode(depth + 1, el, arrayIdxStr, posStart, posEnd));
} else {
children.add(new DataNode(depth + 1, el, arrayIdxStr));
}
}
} else if (value instanceof KaitaiStruct) {
DebugAids debug = DebugAids.fromStruct((KaitaiStruct) value);
Expand All @@ -155,8 +168,8 @@ protected List<DataNode> doInBackground() throws Exception {
field.setAccessible(true);
Object curValue = field.get(value);

Integer posStart = debug.getStart(methodName);
Integer posEnd = debug.getEnd(methodName);
Integer posStart = debug.getAttrStart(methodName);
Integer posEnd = debug.getAttrEnd(methodName);

DataNode dn = new DataNode(depth + 1, curValue, m, posStart, posEnd);
children.add(dn);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/kaitai/struct/visualizer/DebugAids.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ private DebugAids(
this.arrEnd = arrEnd;
}

public Integer getStart(String attrName) {
public Integer getAttrStart(String attrName) {
return attrStart.get(attrName);
}

public Integer getEnd(String attrName) {
public Integer getAttrEnd(String attrName) {
return attrEnd.get(attrName);
}

public Integer getStart(String attrName, int idx) {
ArrayList<Integer> positions = arrStart.get(attrName);
public Integer getArrayStart(String arrName, int idx) {
ArrayList<Integer> positions = arrStart.get(arrName);
return (positions != null) ? positions.get(idx) : null;
}

public Integer getEnd(String attrName, int idx) {
ArrayList<Integer> positions = arrEnd.get(attrName);
public Integer getArrayEnd(String arrName, int idx) {
ArrayList<Integer> positions = arrEnd.get(arrName);
return (positions != null) ? positions.get(idx) : null;
}

Expand Down