1
+ ;Example of intercepting a signal with our own handler using the signal API. API calls found in this example program:
2
+ ; signal, write, exit
3
+ ; High level description of what theis example program does:
4
+ ; Set up a signal handler to 'handle_it' using signal API
5
+ ; Proceed into infinite Loop
6
+ ; In 'handle_it' tell user that 'ctrl+C'd to fuck off,
7
+ ; then set up new signal handler to exit if ctrl+C is used
8
+ ; return to infinite Loop
9
+ ; If Ctrl+C is pressed again, program prints a message indicating defeat and exits
10
+
11
+ section .text
12
+ global _start
13
+
14
+ _start:
15
+
16
+ ; Set up signal handler to intercept SIGINT (CTRL+C)
17
+ ;------------------------------------------------------------------------------
18
+ mov eax , 48 ; signal
19
+ mov ebx , 2 ; SIGINT
20
+ mov ecx , handle_it ; Address to signal handler when catching sigint
21
+ int 0x80
22
+
23
+ ; Infinit Loop
24
+ ;------------------------------------------------------------------------------
25
+ iloop:
26
+ jmp iloop
27
+
28
+ ; Handler for Interupt Signal
29
+ ;------------------------------------------------------------------------------
30
+ handle_it:
31
+ mov eax , 4 ; write
32
+ mov ebx , 1 ; stdout
33
+ mov ecx , message ; '^C <- Nah, Fuck you!'
34
+ mov edx , 19 ; how many bytes to print
35
+ int 0x80
36
+ mov eax , 48 ; new signal
37
+ mov ebx , 2 ; SIGINT
38
+ mov ecx , exit ; Exit this time
39
+ int 0x80
40
+ ret ; but for now, go back to our infinite loop
41
+
42
+ ; Exit
43
+ ;------------------------------------------------------------------------------
44
+ exit:
45
+ mov eax , 4 ; write
46
+ mov ebx , 1 ; stdout
47
+ mov ecx , message2 ; '^C Fine...'
48
+ mov edx , 9 ; how many bytes to print
49
+ int 0x80
50
+ mov eax , 1
51
+ int 0x80
52
+
53
+ section .data
54
+ message db ' <- Nah, Fuck you!' , 0x0a
55
+ message2 db ' Fine...' , 0x0a
56
+
57
+ ; All the standard signal codez
58
+ ;------------------------------------------------------------------------------
59
+ ; 1 - SIGHUP - Hangup
60
+ ; 2 - SIGINT - Terminal interrupt
61
+ ; 3 - SIGQUIT - Terminal quit
62
+ ; 4 - SIGILL - Illegal instruction
63
+ ; 5 - SIGTRAP - Trace/breakpoint trap
64
+ ; 6 - SIGABRT - Abort process
65
+ ; 7 - SIGBUS - Memory access error
66
+ ; 8 - SIGFPE - Arithmetic exception
67
+ ; 9 - SIGKILL - Sure Kill
68
+ ; 10 - SIGUSR1 - User-defined signal 1
69
+ ; 11 - SIGSEGV - Invalid memory reference
70
+ ; 12 - SIGUSR2 - User-defined signal 2
71
+ ; 13 - SIGPIP - Broken pipe
72
+ ; 14 - SIGALRM - Real-time timer expired
73
+ ; 15 - SIGTERM - Terminate process
74
+ ; 16 - SIGSTKFLT - Stack fault on coprocessor
75
+ ; 17 - SIGCHLD - Child terminated or stopped
76
+ ; 18 - SIGCONT - Continue if stopped
77
+ ; 19 - SIGSTOP - Sure stop
78
+ ; 20 - SIGTSTP - Terminal stop
79
+ ; 21 - SIGTTIN - Terminal read from BG
80
+ ; 22 - SIGTTOU - Terminal write from BG
81
+ ; 23 - SIGURG - Urgent data on socket
82
+ ; 24 - SIGXCPU - CPU time limit exceeded
83
+ ; 25 - SIGXFSZ - File size limit exceeded
84
+ ; 26 - SIGVTALRM - Virtual timer expired
85
+ ; 27 - SIGPROF - Profiling timer expired
86
+ ; 28 - SIGWINCH - Terminal window size change
87
+ ; 29 - SIGIO/POLL- I/O possible
88
+ ; 30 - SIGPWR - Power about to fail
89
+ ; 31 - SIGSYS - Invalid system call
0 commit comments