-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinhelloworld.asm
93 lines (77 loc) · 2.03 KB
/
winhelloworld.asm
1
2
3
4
5
6
7
8
9
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
.386
.MODEL FLAT, STDCALL
ExitProcess PROTO ,:DWORD
MessageBoxA PROTO ,:DWORD, :DWORD, :DWORD, :DWORD
SetUnhandledExceptionFilter PROTO ,:DWORD
.STACK 10000h
.DATA
msgBoxCaption db "Asm message box!", 0
msgBoxText db "My first assembly message box! Hello, World!", 0
finalCaption db "Final handler", 0
finalText db "Final handler executed", 0
localCaption db "Local handler", 0
localText db "Local handler executed", 0
localCaption1 db "Local1 handler", 0
localText1 db "Local1 handler executed", 0
internalCaption db "internal handler", 0
internalText db "internal handler executed", 0
.CONST
NULL equ 0
MB_OK equ 0
assume nothing
.CODE
finalHandler proc near
invoke MessageBoxA, NULL, ADDR finalText, ADDR finalCaption, MB_OK
mov eax, 1
ret
finalHandler endp
localHandler proc near
invoke MessageBoxA, NULL, ADDR localText, ADDR localCaption, MB_OK
mov eax, 1
ret
localHandler endp
localHandler1 proc near
invoke MessageBoxA, NULL, ADDR localText1, ADDR localCaption1, MB_OK
mov ebx, [esp+0Ch]
mov [ebx+0B8h], offset safe_place
mov eax, 0
ret
localHandler1 endp
internalHandler proc near
invoke MessageBoxA, NULL, ADDR internalText, ADDR internalCaption, MB_OK
mov ebx, [esp+0Ch]
mov [ebx+0B8h], offset internal_safe_place
mov eax, 0
ret
internalHandler endp
start:
mov eax, 10h
mov ebx, 15h
add eax, ebx
mul ebx
invoke SetUnhandledExceptionFilter, ADDR finalHandler
push offset localHandler1
push fs:[0]
mov fs:[0], esp
push offset localHandler
push fs:[0]
mov fs:[0], esp
invoke MessageBoxA, NULL, ADDR msgBoxText, ADDR msgBoxCaption, MB_OK
push offset internalHandler
push fs:[0]
mov fs:[0], esp
invoke MessageBoxA, NULL, ADDR msgBoxText, 0FFFFFFFFh, MB_OK
internal_safe_place:
mov esp, fs:[0]
pop fs:[0]
add esp, 4h
invoke MessageBoxA, NULL, ADDR msgBoxText, 0FFFFFFFFh, MB_OK
safe_place:
mov esp, fs:[0]
pop fs:[0]
add esp, 4h
pop fs:[0]
add esp, 4h
invoke MessageBoxA, NULL, ADDR msgBoxText, ADDR msgBoxCaption, MB_OK
invoke ExitProcess, 0
END start