[Question] Is there an existing way to force Ghidra to create labels for `CodeUnit`s?
When there is a string code unit with only references to parts of the string that are not the beginning, the string will not have a symbol for its start. For example the Test3.exe x86_32 Windows executable compiled and linked with the Visual Studio 2005 Professional Edition toolchain in Test3.zip. In the function starting at 0x00401000 there are 4 references to characters in the string starting at 0x00403018:
Ghidra correctly makes a code unit for the whole string and symbols for the individual characters. But I also want a symbol for the beginning of the string to resolve an issue raised in https://github.com/boricj/ghidra-delinker-extension/issues/6#issuecomment-2227268928. I have been using this script to check what Ghidra is doing:
codeaddress = currentProgram.getAddressFactory().getAddress("0x00401000")
references = currentProgram.getReferenceManager().getReferencesFrom(codeaddress)
print(references)
for reference in references:
print(reference)
address = reference.getToAddress()
codeunit = currentProgram.getListing().getCodeUnitContaining(address);
print(codeunit)
symbol = codeunit.getPrimarySymbol()
print(symbol)
symbol2 = currentProgram.getSymbolTable().getPrimarySymbol(address)
print(symbol2)
And its output:
array(ghidra.program.model.symbol.Reference, [From: 00401000 To: 00403024 Type: READ Op: 1 DEFAULT])
From: 00401000 To: 00403024 Type: READ Op: 1 DEFAULT
ds "PATCH_FLAGS_p_D_b_l"
None
s_p_D_b_l_00403024
I understand why this would not be the default behavior for Ghidra, but is there an analyzer, script, or option somewhere that can do this already using the same format for the symbol that Ghidra would normally use if there was a reference to the start of the string?