I have following code:
#include <stdio.h>
char somes[10] = "good job!";
char somes1[8] = "another";
char somes2 [5] = "job";
int func()
{
printf("You did a %s\n", somes);
// func(10);
}
int main()
{
printf("You did a %s\n", somes1);
printf("You did a %s\n", somes2);
printf("garb");
printf("sharp");
func();
}
I want to get sizes of strings defined in the code. Ghidra behaves strangely in such cases, even with symbol information. For e.g. in the above program, ghidra accurately detects lengths (or sizes of) all strings except. "garb" - it says that its size is 1 and defined as a single character "g" (s.getObject()
). I feel this very strange, as even with debugging information, ghidra fails to detect this. Is there anything I can do to get such sizes (or correct string representations)?
I am doing something like:
symbols = set(currentProgram.getSymbolTable().getAllSymbols(True))
for s in symbols:
if s.isGlobal():
// gives me size of object
print(s.getObject().getLength())
Note that I have also posted this question here - https://github.com/NationalSecurityAgency/ghidra/issues/2274