Skip to content

Commit 2bef722

Browse files
artemdinaburgkumarak
authored andcommitted
Add support for widechar data type and some string related debugging comments
1 parent a2c60d7 commit 2bef722

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

scripts/ghidra/PatchestryDecompileFunctions.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,19 @@ private void serialize(DataType data_type) throws Exception {
576576
serializePrototype((FunctionSignature) data_type);
577577

578578
} else if (data_type instanceof PartialUnion) {
579-
name("kind").value("todo"); // TODO(pag): Implement this
579+
name("kind").value("todo:PartialUnion"); // TODO(pag): Implement this
580580
name("size").value(data_type.getLength());
581581

582582
} else if (data_type instanceof BitFieldDataType) {
583-
name("kind").value("todo"); // TODO(pag): Implement this
583+
name("kind").value("todo:BitFieldDataType"); // TODO(pag): Implement this
584584
name("size").value(data_type.getLength());
585585

586586
} else if (data_type instanceof WideCharDataType) {
587-
name("kind").value("todo"); // TODO(pag): Implement this
587+
name("kind").value("WideCharDataType");
588588
name("size").value(data_type.getLength());
589589

590590
} else if (data_type instanceof StringDataType) {
591-
name("kind").value("todo"); // TODO(pag): Implement this
591+
name("kind").value("todo:StringDataType"); // TODO(pag): Implement this
592592
name("size").value(data_type.getLength());
593593

594594
} else {
@@ -877,13 +877,17 @@ private String findNullTerminatedString(Address address, Pointer pointer) throws
877877
Address ram_address = convertAddressToRamSpace(address);
878878
MemoryBufferImpl memoryBuffer = new MemoryBufferImpl(program.getMemory(), ram_address);
879879
DataType char_type = pointer.getDataType();
880+
//println("Debug: char_type = " + char_type.getName() + ", size = " + char_type.getLength());
881+
//println("Debug: char_type class = " + char_type.getClass().getName());
880882
StringDataInstance string_data_instance = StringDataInstance.getStringDataInstance(char_type, memoryBuffer, char_type.getDefaultSettings(), -1);
881883
int detectedLength = string_data_instance.getStringLength();
884+
//println("Debug: detectedLength = " + detectedLength);
882885
if (detectedLength == -1) {
883886
return null;
884887
}
885-
string_data_instance = new StringDataInstance(char_type, char_type.getDefaultSettings(), memoryBuffer, detectedLength, true);
886-
return string_data_instance.getStringValue();
888+
String value = string_data_instance.getStringValue();
889+
//println("Debug: stringValue = " + value);
890+
return value;
887891
}
888892

889893
private Data getDataReferencedAsConstant(Varnode node) throws Exception {
@@ -893,7 +897,8 @@ private Data getDataReferencedAsConstant(Varnode node) throws Exception {
893897
// Ghidra sometime fail to resolve references to Data and show it as const.
894898
// Check if it is referencing Data as constant from `ram` addresspace.
895899
Address ram_address = convertAddressToRamSpace(node.getAddress());
896-
return getDataAt(ram_address);
900+
Data data = getDataAt(ram_address);
901+
return data;
897902
}
898903

899904
// Serialize an input or output varnode.

0 commit comments

Comments
 (0)