- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
typedef struct _xjmp_stru {
unsigned long Ebp;
unsigned long Ebx;
unsigned long Edi;
unsigned long Esi;
unsigned long Esp;
unsigned long Eip;
} xjmp_stru;
typedef int xjmp_buf[6];
__declspec(naked)
int __cdecl xsetjmp(xjmp_buf)
{
__asm
{
mov edx, [esp+4]
mov [edx], ebp
mov [edx+4], ebx
mov [edx+8], edi
mov [edx+12], esi
mov [edx+16], esp
mov eax, [esp]
mov [edx+20], eax
xor eax, eax
ret
}
}
__declspec(naked, noreturn)
void __cdecl xlongjmp(xjmp_buf, int)
{
__asm
{
mov edx, [esp+4]
mov ebp, [edx]
mov ebx, [edx+4]
mov edi, [edx+8]
mov esi, [edx+12]
mov eax, [esp+8]
test eax, eax
jne __
inc eax
__:
mov esp, [edx+16]
add esp, 4
mov edx, [edx+20]
jmp edx
}
}
int dummy(xjmp_buf jbuf)
{
volatile int jk = 8;
if (jk)
xlongjmp(jbuf, 2);
else
return 7;
}
int main()
{
xjmp_buf jbuf;
if (xsetjmp(jbuf))
{
puts("excpt");
return -1;
}
dummy(jbuf);
puts("great work");
return 0;
}
stasuss 13.03.2012 08:31 # −1
istem 13.03.2012 23:45 # 0