summaryrefslogtreecommitdiff
path: root/pwnlib/shellcraft/templates/common/linux/sleep.asm
blob: cb53d40165b17f39d8f8d3a0e1432ae704b1c8ff (plain)
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
<%
  import pwnlib.abi
  from pwnlib import shellcraft
%>
<%page args="seconds"/>
<%docstring>
Sleeps for the specified amount of seconds.

Uses SYS_nanosleep under the hood.
Doesn't check for interrupts and doesn't retry with the remaining time.

Args:
  seconds (int,float): The time to sleep in seconds.
</%docstring>
<%
  # struct timespec {
  #     time_t  tv_sec;  /* Seconds */
  #     long    tv_nsec; /* Nanoseconds */
  # };
  tv_sec = int(seconds)
  tv_nsec = int((seconds % 1) * 1000000000)

  abi = pwnlib.abi.ABI.syscall()
  stack = abi.stack
%>
    /* sleep(${seconds}) */
    ${shellcraft.push(tv_nsec)}
    ${shellcraft.push(tv_sec)}
    ${shellcraft.nanosleep(stack, 0)}