Nikolay Igotti
More fun with SEH
Just to demonstrate what kind of fancy stuff SEH provides, I wrote this small demo code for win32/x86. Idea of this code is to show how to modify the way other frames handle their exceptions. I don't see much applications for this technology, other than explanation how SEH works. If you understand how this demo does what it does - you likely understand SEHs pretty well.
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
void handler() {
printf("intercepted");
getchar();
exit(1);
}
void install(int where) {
void** head;
__asm {
mov eax, fs:0
mov head, eax
}
int n = 0;
while (head != (void**)-1) {
if (n++ == where) {
*(head+1) = &handler;
}
head = (void**)*head;
}
return;
}
void foo(int r) {
if (r == 0) {
install(3);
return;
}
__try {
foo(r-1);
if (r == 3) {
*(char*)0 = 0;
}
} __except(1) {
printf("regular\n");
}
}
int _tmain(int argc, _TCHAR* argv[])
{
foo(10);
getchar();
return 0;
}
Posted at 03:55PM Jun 24, 2007 by nike in Sun | Comments[0]
Comments:
Sunday Jun 24, 2007