It is legal to overwrite exported data in attached DLL/SO?
Example (win32):
t_Controller controller = (t_Controller*) GetProcAddress(SomeDLL, "Controller");
controller->Args = args; // <--- here
controller->Run();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ok – so you are exporting a struct of some kind.
Once a pointer to the struct is obtained, whether or not its legal to write to the struct from the exe, depends entirely on whether or not its legal, in the dll, to write to the struct.
i.e. is it a const struct?
If its not defined as const, then you can write to it.
If it is defined as const, then your
GetProcAddressis just a complicated way of casting theconstoff, which will result – as always – in undefined behavior. i.e. it may, or may not work, depending on your compilers implementation – usually whether or not static objects declared at global scope are placed in a read-only data section.