|
1 |
| -# A Python script to generate a BSOD. |
2 |
| -# This script is based on the following article: |
3 |
| -# https://stackoverflow.com/questions/11254763/is-there-a-way-in-windows-to-throw-a-bsod-on-demand-from-python |
4 |
| -# https://www.geeksforgeeks.org/how-to-create-a-countdown-timer-using-python/ |
5 |
| -import os |
6 |
| -import sys |
7 |
| -import time |
8 |
| - |
9 |
| -if os.name != 'nt': |
10 |
| - print("This script is only for Windows.") |
11 |
| - sys.exit(1) |
12 |
| - |
13 |
| - |
14 |
| -def bsod(): |
15 |
| - """Generate a BSOD.""" |
16 |
| - from ctypes import POINTER, byref, c_int, c_uint, c_ulong, windll |
17 |
| - |
18 |
| - nullptr = POINTER(c_int)() |
19 |
| - |
20 |
| - windll.ntdll.RtlAdjustPrivilege( |
21 |
| - c_uint(19), |
22 |
| - c_uint(1), |
23 |
| - c_uint(0), |
24 |
| - byref(c_int()) |
25 |
| - ) |
26 |
| - |
27 |
| - windll.ntdll.NtRaiseHardError( |
28 |
| - c_ulong(0xC000007B), |
29 |
| - c_ulong(0), |
30 |
| - nullptr, |
31 |
| - nullptr, |
32 |
| - c_uint(6), |
33 |
| - byref(c_uint()) |
34 |
| - ) |
35 |
| - |
36 |
| - |
37 |
| -def countdown(t): |
38 |
| - """Countdown timer.""" |
39 |
| - while t: |
40 |
| - mins, secs = divmod(t, 60) |
41 |
| - timer = '{:02d}:{:02d}'.format(mins, secs) |
42 |
| - print(timer, end="\r") |
43 |
| - time.sleep(1) |
44 |
| - t -= 1 |
45 |
| - |
46 |
| - |
47 |
| -if __name__ == '__main__': |
48 |
| - # Check arguments |
49 |
| - if len(sys.argv) != 2: |
50 |
| - print("Usage: python3 bsod.py <seconds>") |
51 |
| - sys.exit(1) |
52 |
| - try: |
53 |
| - # Ask for confirmation, comment out if you don't want to ask |
54 |
| - ''' |
55 |
| - print("This will generate a BSOD in {} seconds.".format(sys.argv[1])) |
56 |
| - print("Press Ctrl+C to cancel.") |
57 |
| - confirmMsg = "Yes, I want to generate a BSOD." |
58 |
| - confirmInput = input("Type \""+confirmMsg + |
59 |
| - "\" and press Enter to continue: ") |
60 |
| - if confirmInput != confirmMsg: |
61 |
| - print("Aborted.") |
62 |
| - sys.exit(1) |
63 |
| - ''' |
64 |
| - |
65 |
| - # Get seconds absolute value |
66 |
| - seconds = abs(int(sys.argv[1])) |
67 |
| - |
68 |
| - # Countdown |
69 |
| - countdown(seconds) |
70 |
| - |
71 |
| - # Generate BSOD |
72 |
| - bsod() |
73 |
| - print("\nBSOD generated.") |
74 |
| - sys.exit(0) |
75 |
| - except KeyboardInterrupt: |
76 |
| - print("\nAborted.") |
77 |
| - sys.exit(1) |
| 1 | +# A Python script to generate a BSOD. |
| 2 | +# This script is based on the following article: |
| 3 | +# https://stackoverflow.com/questions/11254763/is-there-a-way-in-windows-to-throw-a-bsod-on-demand-from-python |
| 4 | +# https://www.geeksforgeeks.org/how-to-create-a-countdown-timer-using-python/ |
| 5 | +import os |
| 6 | +import sys |
| 7 | +import time |
| 8 | + |
| 9 | +if os.name != 'nt': |
| 10 | + print("This script is only for Windows.") |
| 11 | + sys.exit(1) |
| 12 | + |
| 13 | + |
| 14 | +def bsod(): |
| 15 | + """Generate a BSOD.""" |
| 16 | + from ctypes import POINTER, byref, c_int, c_uint, c_ulong, windll |
| 17 | + |
| 18 | + nullptr = POINTER(c_int)() |
| 19 | + |
| 20 | + windll.ntdll.RtlAdjustPrivilege( |
| 21 | + c_uint(19), |
| 22 | + c_uint(1), |
| 23 | + c_uint(0), |
| 24 | + byref(c_int()) |
| 25 | + ) |
| 26 | + |
| 27 | + windll.ntdll.NtRaiseHardError( |
| 28 | + c_ulong(0xC000007B), |
| 29 | + c_ulong(0), |
| 30 | + nullptr, |
| 31 | + nullptr, |
| 32 | + c_uint(6), |
| 33 | + byref(c_uint()) |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +def countdown(t): |
| 38 | + """Countdown timer.""" |
| 39 | + while t: |
| 40 | + mins, secs = divmod(t, 60) |
| 41 | + timer = '{:02d}:{:02d}'.format(mins, secs) |
| 42 | + print(timer, end="\r") |
| 43 | + time.sleep(1) |
| 44 | + t -= 1 |
| 45 | + |
| 46 | + |
| 47 | +if __name__ == '__main__': |
| 48 | + # Check arguments |
| 49 | + if len(sys.argv) != 2: |
| 50 | + print("Usage: python3 bsod.py <seconds>") |
| 51 | + sys.exit(1) |
| 52 | + try: |
| 53 | + # Ask for confirmation, comment out if you don't want to ask |
| 54 | + ''' |
| 55 | + print("This will generate a BSOD in {} seconds.".format(sys.argv[1])) |
| 56 | + print("Press Ctrl+C to cancel.") |
| 57 | + confirmMsg = "Yes, I want to generate a BSOD." |
| 58 | + confirmInput = input("Type \""+confirmMsg + |
| 59 | + "\" and press Enter to continue: ") |
| 60 | + if confirmInput != confirmMsg: |
| 61 | + print("Aborted.") |
| 62 | + sys.exit(1) |
| 63 | + ''' |
| 64 | + |
| 65 | + # Get seconds absolute value |
| 66 | + seconds = abs(int(sys.argv[1])) |
| 67 | + |
| 68 | + # Countdown |
| 69 | + countdown(seconds) |
| 70 | + |
| 71 | + # Generate BSOD |
| 72 | + bsod() |
| 73 | + print("\nBSOD generated.") |
| 74 | + sys.exit(0) |
| 75 | + except KeyboardInterrupt: |
| 76 | + print("\nAborted.") |
| 77 | + sys.exit(1) |
0 commit comments