Module Stomping

Load a PICO over a stomped module.

Project Files

Notes

This is a simple module stomping PICO runner. It's main purpose is to show stomping .pdata with Crystal Palace's generated stack unwind data.

loader.c loads xpsservices.dll, finds .text and places our PICO's code over it. It places our PICO's constants and data over the module's .data section. And, our stack unwinding meta-information is placed over .pdata (x64 only). The result is our PICO lives in image memory and has unwindable call stacks.

Now, for some unwinding-specific details:

.pdata is a block of RUNTIME_FUNCTION values. These point to the begin and end offset of non-leaf functions relative to a base address. Crystal Palace generates this data assuming position 0 of our executable code is the base. But, in a stomped module, the base of the module is the base address. In a stomping context, we have to play nice with the module's base, because this and the size of .pdata are cached elsewhere.

Another important detail relates to how .pdata is searched. Windows does a binary search on this information. So, when we stomp .pdata, we need to take care that our code is findable in a binary search context. Here, I've simplified things, because I've placed our RUNTIME_INFORMATION block over position 0. I'm taking a chance that our RUNTIME_INFORMATION is sorted properly over the existing .pdata. A more robust implementation might walk each existing RUNTIME_INFORMATION block, find where the new one best fits, and overwrite the old one.

Another detail relates to alignment of .xdata. Crystal Palace packages unwind codes, which describe the function prologue, in line with the PICO's executable code. This data must exist on a 4B boundary. This means, if you opt to extend this and stomp over an exported function, you'll want to take care to preserve the 4B alignment of your PICO's code.

Conversation

License

This project is licensed under the BSD License.