Skip to content

Commit

Permalink
fixup! update handling of element type if null
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarak committed Oct 22, 2024
1 parent b75a47c commit ad9ddf5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions scripts/ghidra/PatchestryDecompileFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ private void serializePointerType(Pointer ptr) throws Exception {
name("kind").value("pointer");
name("size").value(ptr.getLength());
DataType elem_type = ptr.getDataType();

// element data type can be null
if (elem_type != null) {
name("element_type").value(label(elem_type));
// Pointer element type could be null; assign void type to
// element in such case
if (elem_type == null) {
elem_type = VoidDataType.dataType;
}

name("element_type").value(label(elem_type));
}

private void serializeTypedefType(TypeDef typedef) throws Exception {
Expand All @@ -225,9 +227,13 @@ private void serializeTypedefType(TypeDef typedef) throws Exception {
name("size").value(typedef.getLength());

DataType base_type = typedef.getBaseDataType();
if (base_type != null) {
name("base_type").value(label(base_type));
// If base_type is null, could it be void or undefined type??
// Assign void base type in such case
if (base_type == null) {
base_type = VoidDataType.dataType;
}

name("base_type").value(label(base_type));
}

private void serializeArrayType(Array arr) throws Exception {
Expand Down Expand Up @@ -324,8 +330,7 @@ private void serialize(DataType data_type) throws Exception {
private void serializeTypes() throws Exception {
for (int i = 0; i < types_to_serialize.size(); i++) {
DataType type = types_to_serialize.get(i);
String type_id = label(type);
name(type_id).beginObject();
name(label(type)).beginObject();
serialize(type);
endObject();
}
Expand Down

0 comments on commit ad9ddf5

Please sign in to comment.