Unhandled exception at 0x6D3800C8 in Konfig32.exe: 0xC000041D after using MS Detours

0

First of all, I'm a beginner and I started to learn C++ last month, so don't be mad if I can't good explain the problem. :D

I'm using MS Detours to hook some custom functions to original functions from Windows. When I run the software, the original functions which are showing the text inside menus, windows etc. will be changed with my functions which are going to translate the text and show it like original function but just in the other language.

I have done the traditional hooking in C++ where I overwrite hot-patch header of function but the problem is that such hooking doesn't work with an 64-bit software and I realized that I can use MS Detours to do hooking because it is compatible with X86 and X64 software. The traditional hooking worked in 32 bit mode but after implementing MS Detours I get an error:

Unhandled exception at 0x6D3800C8 in Konfig32.exe: 0xC000041D: An unhandled exception was encountered during a user callback.

Here is a photo of it where you can see the function and the exception inside wincore.cpp file

The hooking worked and a checked with debugger that every function was successfully hooked to the original one. Then the program starts to translate the text and it was successfull and after calling this function i got this error.

I searched for an answer in stackoverflow but none of them was connected with hooking, so it would be great if somebody can say what can be the possible problem or solution.

This is my source code:

// Constructor
CFunctionControll::CFunctionControll(BYTE* pOrigFunc, BYTE* pDetourFunc)
{
   m_pOrigFunc = pOrigFunc;
   m_pDetourFunc = pDetourFunc;
}


// Destructor
CFunctionControll::~CFunctionControll()
{
   Disable();
}


void CFunctionControll::Enable()
{

   try
   {
      DetourTransactionBegin();
      DetourUpdateThread(GetCurrentThread());
      DetourAttach(&(LPVOID&)m_pOrigFunc, m_pDetourFunc);
      if (!DetourTransactionCommit())
         throw transactionerror;
   }
   catch (TransactionError)
   {
      // Add proper exception handling later
   }
}


void CFunctionControll::Disable()
{

   try
   {
       DetourTransactionBegin();
       DetourUpdateThread(GetCurrentThread());
       DetourDetach(&(LPVOID&)m_pOrigFunc, m_pDetourFunc);
       if (!DetourTransactionCommit())
          throw transactionerror;
   }
   catch (TransactionError)
   {
      // Add proper exception handling later
   }
}

class TransactionError : public std::exception
{
   virtual const char* what() const throw()
   {
      return "DetourTransactionCommit() failed.";
   }
} transactionerror;

The paramerer pOrigFunc is a pointer to the original function and the parameter pDetourFunc is a pointer to my customized function.

I am doing hooking with this CFunctionControll class where I can just say Enable()[to hook a function] or Disable()[to unhook it] :)

c++
windows
winapi
asked on Stack Overflow Sep 30, 2019 by (unknown user) • edited Oct 1, 2019 by (unknown user)

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0