c++ modify resources at runtime

狂风中的少年 提交于 2020-01-02 03:12:23

问题


Is it possible to edit resources for an executable at runtime programmatically? If so, how? If not, is there another program that can easily be used to modify resources?

Thanks, Derek.


回答1:


Yes, it is possible, though not especially easy. It basically requires writing a resource compiler (at least for the resource types you want to modify).

For example I once wrote a menu compiler that took its input out of a database at run-time (at then saved the result back to the DB). If the source tables were unchanged then the existing resource was used, otherwise it was rebuilt.

In the case of menu resources (and I believe dialogs) the tricky bit is that certain members are only present depending on flag settings, as well as strict alignment requirements.

In the case of modifying resources already present in your .exe you would need to copy the resource data into a memory buffer (with extra space available if you are adding new elements) (by using FindResource, LockResource, a memory copy then UnlockResource).

After making the changes you then use one of the indirect create functions (i.e. CreateMenuIndirect) and pass the buffer's address.

The resource API allows for writing such a buffer back to the application binary but that would break the signature if you use code signing so be very careful. I also do not know if that API works for a program that is actually running.



来源:https://stackoverflow.com/questions/339265/c-modify-resources-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!