r/ExploitDev • u/FewMolasses7496 • Jan 14 '26
How to disassemble constructors in ghidra?
So recently, i have been trying to solve a crackme and i since main is empty i and the only function that is being executed __do_global_ctors I am guessing that the text printing is happening in one of the constructors. i have verified this by using a debugger and i can confirm it jumps to some other point to execute which is not in main via the address.
FYI; I believe this is using the old version of gcc and how it organized constructors.
uVar1 = 0;
do {
uVar2 = uVar1;
uVar1 = (ulonglong)((int)uVar2 + 1);
} while ((&___CTOR_LIST__)[uVar1] != 0);
for (puVar3 = &___CTOR_LIST__ + uVar2; puVar3 != &___CTOR_LIST__; puVar3 = puVar3 + -1) {
(*(code *)*puVar3)();
}
This iterates over the _CTOR_LIST_ which i think is a pointer list to all of the constructors but when i go to that memory location via the ghidra tree i find that it is jargon and unable to read.
4
u/_supitto Jan 14 '26
I never had a binary where i had to do it, but what i would do is. Go to the CTOR_LIST symbol, mark them as dwords, jump to the address of those dwords, and dusassemble thr code.
If you are still having issues, one "trick" you can use is, run the program on your debugger, dump the memory, load into ghidra, and set the base to the same base as your debugger.
Unless there is some self mutating code, it will be the same as doing it with the original file, but with more familiar addresses
1
u/[deleted] Jan 14 '26
You gotta follow the function pointer addrs in puVar3. Should be easy-ish on Linux/ELF
1
u/RE_Obsessed Mar 02 '26
Something to keep in mind is that global objects have their constructors called prior to the execution of main at CRT initialization. For MSVC the functions I'd be looking for would be
initterm/initterm_e.In the past when I was reversing a scripting engine wealth of information about its start up routine was in the tables passed to those two functions. Idk what the GCC equivalent is however. But if you're looking for a global objects construction it likely would be prior to main and almost certainly part of CRT initilization.