Jump to content
  • Advertisement
Sign in to follow this  
MyKee

Dll injection problems

This topic is 3156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm injecting a piece of code into another process but when the code runs, the application crashes with "Access violation writing location 0x580....." and I can't figure out why. The dll injection is done by using CreateRemoteThread and I patch the IAT-table for a C++ library export with my own function that should be called instead. The method I'm hooking is "QLabel::setWordWrap(bool on)" in the QT-library just for testing purpose. void __stdcall QLabel_SetWrap(bool); void __stdcall QLabel_SetWrap(bool on) { void (__stdcall *pQLabel_SetWrap)(bool on); pQLabel_SetWrap = (void (__stdcall *)(bool)) old; MessageBox(NULL, "QLabel_SetWrap called!", "API Hook", MB_OK); pQLabel_SetWrap(on); } When the pQLabel_SetWrap(on) is called the application crashes with the "Access violation". But here is the strange part, it works without a problem If I do one of the following things  - Comment out the MessageBox() line  - Comment out the pQLabel_SetWrap(on) line  - Move the pQLabel_SetWrap(on) to be called before the MessageBox() What have I missed?

Share this post


Link to post
Share on other sites
Advertisement
Since setWordWrap is a non-static method of the class QLabel, the first thing I notice is that you're missing the "this" pointer in your declaration.
Additionally, I do not believe stdcall is the correct calling convention, you might want to try thiscall.

Share this post


Link to post
Share on other sites
this pointer seems to come in the ECX register, when I called some other function the ECX register got overwritten with some other value causing it to crash when the SetWrap method was called!

Pushing the ECX value to the stack and then restoring it just before calling SetWrap fixed the problem, thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!