B
Boris Fortes
I need to unhook event receiver as result of native C++ event.
It unhooks successfully, but __raise does not return and throws access
violation.
Visual Studio 2003
How to reproduce:
Consol Win32 exe project
#include "stdafx.h"
[event_source(native)]
class Publisher
{
public:
__event void Signal(Publisher* sender);
void RaiseSignal()
{
// throws access violation
__raise Signal(this);
}
};
[event_receiver(native)]
class Subscriber
{
public:
void Handler(Publisher* sender)
{
// unhooks successfully
Unhook(sender);
return;
}
void Hook(Publisher* sender)
{
__hook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}
void Unhook(Publisher* sender)
{
__unhook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Publisher pub;
Subscriber sub;
sub.Hook(&pub);
pub.RaiseSignal();
return 0;
}
Debug output window
'Hook.exe': Loaded 'C:\Projects\Hook\Debug\Hook.exe', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', Symbols loaded.
First-chance exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.
Unhandled exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.
It unhooks successfully, but __raise does not return and throws access
violation.
Visual Studio 2003
How to reproduce:
Consol Win32 exe project
#include "stdafx.h"
[event_source(native)]
class Publisher
{
public:
__event void Signal(Publisher* sender);
void RaiseSignal()
{
// throws access violation
__raise Signal(this);
}
};
[event_receiver(native)]
class Subscriber
{
public:
void Handler(Publisher* sender)
{
// unhooks successfully
Unhook(sender);
return;
}
void Hook(Publisher* sender)
{
__hook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}
void Unhook(Publisher* sender)
{
__unhook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Publisher pub;
Subscriber sub;
sub.Hook(&pub);
pub.RaiseSignal();
return 0;
}
Debug output window
'Hook.exe': Loaded 'C:\Projects\Hook\Debug\Hook.exe', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', Symbols loaded.
First-chance exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.
Unhandled exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.