-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when throwing exception inside loaded dll. #4
Comments
Hi A temporary fix is to disable DEP[1] in the Visual Studio build options. Another possibility is to implement the missing parts of the pe loading process in MemoryModule. I'll provide some code, if I get an allowance from my boss. [1] DEP: http://en.wikipedia.org/wiki/Data_Execution_Prevention |
Hi JesseKlugmann, any updates on this? Could you provide some code, or give some hints what parts are missing and maybe describe how they should be implemented? |
My guess (and I dont know a lot about the subject) is that you have to load the .SAFESEH section of the dll, otherwise the SafeSeh mechanism will terminate the process when an exception occurs, as it cannot verify that the exception handlers are safe. See http://msdn.microsoft.com/en-us/library/9a89h429(v=vs.90).aspx |
@JesseKlugmann do you have any hints or links to documentation how this could be implemented? |
|
The "DarkMMap" project found here (https://github.com/DarthTon/DarkMMap) loads libraries from memory and according to the project page, has "Exception handling support (SEH and C++), needs more testing though, but seems reliable". Perhaps someone could take a look at how they implement exception handling support and adopt it to work with MemoryModule. |
I checked DarkMMap (now deprecated and called Blackbone). It works just fine but doesn't support Windows XP. I found the relevant code from their library, can someone help incorporate it into MemoryModule? I'm a not too good at Win32... It's in MMap.cpp:550 /// /// Set custom exception handler to bypass SafeSEH under DEP /// image data
#else
#endif } |
Could you please create a pull request for the changes or provide a proper diff? |
This is just code I found on Blackbone's repository which I found relevant. I lack the knowledge to actually add it to your library. Here's a direct link to the relevant code: I think that using your knowledge and Zorro1's advice, you can manage to merge it into your library. |
Hi, have you had any luck implementing try/catch support? I tried to understand the code linked to above (Blackbone) but it deals with a lot of assembly that I can't really follow. Thanks |
I found an article on how SEH and VEH exceptions are handled and it seems to expand on what Zorro1 posted. https://hackmag.com/uncategorized/exceptions-for-hardcore-users/ I will be trying to figure this out but in the mean time maybe someone else can use what I found. |
Hello, I'm also interessted in a solution. |
I have located another possible source for a solution. It is designed to load windows DLLs on linux and it supports exception handling. |
I have found a working solution to the problem! https://github.com/nettitude/SimplePELoader I have confirmed that an exception can be thrown and caught within the loaded library. I have also confirmed that an exception can be thrown inside the library and caught in the executable that loaded it. This is explicitly handled on 64 bit builds but has not be implemented for 32 bit builds. However the disabling DEP solution is a viable workaround for 32 bit builds. Notes:
Edit: This solution will only allow you to catch exceptions with a catch all block on 64 bit builds. catch(...){
// You can do whatever you want here.. but you can't know what the exception is
} The moment you try to define the exception the program will crash as usual. |
When throwing and catching an exception inside the "memory-loaded" dll the application crashes with "Unhandled exception at ...". Even though the appropriate catch is in place.
This is when using Visual Studio 2010. I've created a repository that demonstrates this problem. Hopefully i am the one who has missed something and the memory loading is working as intended.
Link to repo: https://github.com/Niblitlvl50/DLL-crash-when-loading-dll-into-memory
Thank you.
The text was updated successfully, but these errors were encountered: