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);

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


Note that I have also posted this question here - https://github.com/NationalSecurityAgency/ghidra/issues/2274

1 Answer 1


If you are trying to change and individual string, you can right click on the first character of the string and under Data, convert it to TerminatedCString.

If you have a problem with how Ghidra is recognizing strings, you can tweak the settings in the ASCII Strings analyzer to have it recognize shorter strings, change alignments ettings or use a different word model.

  • yes, I can change the type that way (i.e. in gui), but is there any way to do this automatically with headless analyzer python script?
    – R4444
    Sep 14, 2020 at 18:15
  • 2
    You can change the settings on the ASCII Strings analyzer to change the minimum amount of characters or to use a different word model. This may help it recognize different strings that it's not catching in its current settings. Sep 14, 2020 at 18:19
  • thanks shane, I found such options under ascii strings and data references in GUI analysis pane. But, question is how to enable these options in scripting mode.
    – R4444
    Sep 14, 2020 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.