I'm currently attempting to read decompilation in Ghidra. I've identified what I believe to be a "God object" that the library is uses to store state for the entire program. It's passed everywhere and has ~216 fields to it. It's far too large to manually figure out the structure of the struct
(with my current ability), so I had Ghidra "Auto create structure" to define it.
The problem now is, I'm seeing weird behavior where the struct is used. For the initialization of the mutexes that it holds for example, prior to retyping, this is how the code looks in the decompilation window (__arg
is a pointer to the newly calloc
ed God-object):
undefined4 *god
. . .
pthread_mutex_init((pthread_mutex_t *)(god + 2),(pthread_mutexattr_t *)0x0);
pthread_mutex_init((pthread_mutex_t *)(god + 0x39),(pthread_mutexattr_t *)0x0);
pthread_mutex_init((pthread_mutex_t *)(god + 0x1c00f2),(pthread_mutexattr_t *)0x0);
Which is ugly, but mostly makes sense. I'm assuming god + 0x39
is a reference to a field (although, god + 0x1c00f2
is a rather huge field offset) . The problem is, when I retype the field to be of type God
(the auto-generated type), it changes to this:
God *god;
pthread_mutex_init(&god->mutex1,(pthread_mutexattr_t *)0x0);
pthread_mutex_init(&god[1].mutex1,(pthread_mutexattr_t *)0x0);
pthread_mutex_init((pthread_mutex_t *)&god[0x8258].field_0x28,(pthread_mutexattr_t *)0x0);
My best guess as to this weird result is the struct was created improperly. If I go around to different functions where it's used and have Ghidra attempt to create a struct, the size of the struct changes every time (although, it's always around 210-230 fields).
Is there anything I can do to improve Ghidra's auto-creation of the struct? And am I correct that the array-access notation suggests an improper creation of a struct?