The following scenario: Let there be a structure S at offset X. In the disassembly of my program however not only the offset X is referred to, but also X+4, X+... for different members in different sections of the code. Thus, Ghidra infered 32-bit words at X, X+4, X+8, ..., however I want there to be a structure.
If I forcefully try to assign the correct datatype (let's call it struc_X), using Strg+T (i.e. the choose datatype "tool"), I am told that:
"struc_X doesn't fit into 4 bytes, needed N bytes".
Is there anyway to forcefully change the datatype here? IDA is able to do so...
Edit: If I manually undefine all memory areas, it seems to work, but for larger structures this quickly becomes intractable... I would be glad if there is a better solution.
By default Ghidra won't clear things that are defined that might conflict. There is an attempt to clear anything that is ?? or Undefinedxx in many cases, but the locations where clearing undefined data makes sense haven't been all found and changed. The Data Type Chooser dialog, needs to be changed to clear undefined data.
If you drag and drop the structure from the Data Type manager, the dialog allows you to overwrite existing data. So you can search for your structure, and then drag it on memory.
As an aside, for memory you can select the region of bytes, including defined data types. Then press '{' which will automatically create a new structure there, or choose a matching structure of the selection size. This would be cumbersome for large areas.
An overwrite button on the dialog, or a setting to always overwrite could be added.
Most helpful comment
By default Ghidra won't clear things that are defined that might conflict. There is an attempt to clear anything that is ?? or Undefinedxx in many cases, but the locations where clearing undefined data makes sense haven't been all found and changed. The Data Type Chooser dialog, needs to be changed to clear undefined data.
If you drag and drop the structure from the Data Type manager, the dialog allows you to overwrite existing data. So you can search for your structure, and then drag it on memory.
As an aside, for memory you can select the region of bytes, including defined data types. Then press '{' which will automatically create a new structure there, or choose a matching structure of the selection size. This would be cumbersome for large areas.
An overwrite button on the dialog, or a setting to always overwrite could be added.