Ghidra: Global strings in decompiler

Created on 8 May 2019  路  3Comments  路  Source: NationalSecurityAgency/ghidra

char s[] = {'w','o','r','l','d', '\n'};

int main() {
    printf("hello %s", s);
}

This snippet of code produce the following decompiled code

undefined8 main(void)
{
  printf("hello %s",s);
  return 0;
}

I was wondering if there's any chance to get the value of the char array instead of its name. Am i missing something?

I've compiled this snippet both for AARCH64 and x86_64 with gcc and it produce the same decompiled code.

In IDA hex-rays options if i untick "Print only constant string literals" i can get the following decompiled code:

int __cdecl main(int argc, const char **argv)
{
  printf("hello %s", "world\n");
  return 0;
}

Thank you in advance.

Question

Most helpful comment

Thank you for the answer, i solved the problem by setting the mutability to constant on the string. I consider this issue solved and closing it.

All 3 comments

It will depend on if the value is in a memory section that is read-only.

Thank you for the answer, i solved the problem by setting the mutability to constant on the string. I consider this issue solved and closing it.

馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kerilk picture Kerilk  路  3Comments

marcushall42 picture marcushall42  路  3Comments

forkoz picture forkoz  路  3Comments

rliu88 picture rliu88  路  3Comments

loudinthecloud picture loudinthecloud  路  3Comments