For that we need 3-4 things:
- The ID of the button
- The message map of the control it is placed on
- The offset inside the message map
- The static initializer that sets the handlers address (optional).
We know the control, it's "CIFMainPopup". There's no N in the name, therefore its using the old, resinfo/*.txt files. A look into ifmainpopup.txt reveals:
The ID is 15, or 0xF.
Next we need to find the message map. We can easily do that because we know that the 4th virtual function of a UI control is GetMessageMap. All we have to do is find the virtual function table (using RTTI, for example).
Have a look inside and you see this ... well ... not exactly this ... but you'll get it.
The address being moved into EAX is the messageMap address. Follow that and we land here.
There are now two addresses being shown. The first one points to the parent-class' messageMap and the second one points to our messageMapEntries (which will ultimately contain the handlers).
The addresses of the handlers are assigned during application startup and therefore not visible when analyzing the binary statically. But we can find the location where our handler will be written. Remember: The ID was 15, or 0xF.
When setting the correct type, Ghidra will show the structure as follows and we can easily search for 15 (0xF).
In other words: Recognize the recurring pattern and count. We can see that 0xF is at index 5.
You can now just run the game and read the address from the memory. Its written to 00eb8130.
Or you can follow me down the rabbit hole and explore more.
Lets find the static initalizer now. A reference search for the address of the messageMapEntries returns quite a lot of results. Any of them leads to the right direction. But Ghidra can already lead us to the correct one as we know we are looking for number 5.
The function we land at looks like this:
(I've added the pseudo-code output to give you a better understanding of what's going on.)
As you can see, there are other addresses being written to other fields. These are handlers for other buttons. Now knowing how things are connected together, you can look the IDs up and look what they are for.