Skip to content

Commit 65baa70

Browse files
committed
add project files
1 parent 66474c9 commit 65baa70

17 files changed

+415
-3
lines changed

README.md

100644100755
Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
1-
# StopShutdown
2-
A small proof of concept that temporarily prevents a shutdown
1+
# WinAPI-Fun
2+
> A collection of (relatively) harmless prank / virus examples using the Windows API
33
4-
This really small program is handy if you have pesky friends / coworkers that think its funny to shutoff your computer while you are working. I had a problem with this in one of my classes, so I created an easy solution.
4+
<br>
5+
6+
Pre-built binaries can be found in the [Releases](../../releases) section
7+
8+
To reset most examples, re-launch and kill the program again
9+
10+
<br>
11+
12+
| File | Description |
13+
| -------------------------------------------------- | --------------------------------------------------------------------- |
14+
| [avoid.nim](src/avoid.nim) | The start button avoids mouse clicks by jumping around on the taskbar |
15+
| [bsod.nim](src/bsod.nim) | Triggers Blue Screen of Death |
16+
| [dripper.nim](src/dripper.nim) | Moves the current window down slightly every 10 seconds |
17+
| [highcontrast.nim](src/highcontrast.nim) | Enable high contrast mode system-wide |
18+
| [intercept_space.nim](src/intercept_space.nim) | Replaces space bar keypress with the word "space" |
19+
| [mouse_button_swap.nim](src/mouse_button_swap.nim) | Swap the left and right mouse buttons |
20+
| [mouse_trails.nim](src/mouse_trails.nim) | Creates a trail of mouse icons behind the cursor as it moves |
21+
| [mouse_trap.nim](src/mouse_trap.nim) | Traps the mouse cursor in the top right corner for 60 seconds |
22+
| [random_capslock.nim](src/random_capslock.nim) | Randomly toggle the Caps Lock every 0-30 seconds |
23+
| [random_close.nim](src/random_close.nim) | Randomly closes the current focussed window every 0-30 seconds |
24+
| [rotate.nim](src/rotate.nim) | Rotates the display 180 degrees |
25+
| [shake.nim](src/shake.nim) | Rapidly shakes the current focussed window |
26+
| [start_disable.nim](src/start_disable.nim) | Disables clicking the start button or taskbar |
27+
| [start_popup.nim](src/start_popup.nim) | Opens the start menu popup randomly every 0-60 seconds |
28+
| [stop_shutdown.nim](src/stop_shutdown.nim) | Temporarily prevents a shutdown with a custom message |
29+
| [time_local.nim](src/time_local.nim) | Adds the message "HI" to the AM/PM localization string system-wide |
30+
31+
<br>
32+
33+
## Requirements
34+
[Install Nim](https://nim-lang.org/install_unix.html) and the [Winim](https://github.com/khchen/winim) library, then compile with the `--app:gui` flag
35+
36+
Note: if cross-compiling from Linux or macOS, also install the [mingw](https://www.mingw-w64.org/) toolchain and use the `-d:mingw` flag
37+
38+
```sh
39+
nim c -d:mingw --app:gui src/avoid.nim
40+
```
41+
42+
<br> <br>
43+
44+
### USE AT YOUR OWN RISK

src/avoid.nim

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import std/random
2+
import winim
3+
4+
5+
let hWndTaskBar = FindWindow("Shell_TrayWnd", NULL);
6+
let hWndStart = FindWindowEx(hWndTaskBar, 0x0, "Start", "Start");
7+
8+
var cursor: POINT
9+
GetCursorPos(&cursor)
10+
11+
var rectTaskBar: RECT
12+
GetWindowRect(hWndTaskBar, &rectTaskBar)
13+
14+
var rectStart: RECT
15+
GetWindowRect(hWndStart, &rectStart)
16+
17+
# Reset Start Button Position
18+
SetWindowPos(hWndStart, 0x0, 0, 0, 0, 0, (SWP_NOSIZE or SWP_NOZORDER))
19+
20+
var upperBound = rectTaskBar.right - rectStart.right;
21+
22+
23+
# Run callback everytime mouse is moved
24+
proc HookCallback(nCode: int32, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} =
25+
GetCursorPos(&cursor)
26+
27+
if cursor.x >= rectStart.left and cursor.x <= rectStart.right and cursor.y >= rectStart.top:
28+
var newX = rand(upperBound)
29+
SetWindowPos(hWndStart, 0x0, (int32)newX, 0, 0, 0, (SWP_NOSIZE or SWP_NOZORDER))
30+
GetWindowRect(hWndStart, &rectStart)
31+
32+
return CallNextHookEx(0, nCode, wParam, lParam)
33+
34+
35+
# Hook LowLevelMouseProc
36+
var hook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC) HookCallback, 0, 0)
37+
if bool(hook):
38+
try:
39+
PostMessage(0, 0, 0, 0)
40+
var msg: MSG
41+
while GetMessage(msg.addr, 0, 0, 0):
42+
discard
43+
44+
finally:
45+
UnhookWindowsHookEx(hook)

src/bsod.nim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import winim
2+
3+
4+
proc RtlAdjustPrivilege*(privilege: ULONG, bEnablePrivilege: BOOLEAN, isThreadPrivilege: BOOLEAN, previousValue: PBOOLEAN): NTSTATUS
5+
{.discardable, stdcall, dynlib: "ntdll", importc: "RtlAdjustPrivilege".}
6+
7+
proc NtRaiseHardError*(errorStatus: NTSTATUS, numberOfParameters: ULONG, unicodeStringParameterMask: ULONG, parameters: PULONG_PTR, validResponseOption: ULONG, response: PULONG): NTSTATUS
8+
{.discardable, stdcall, dynlib: "ntdll", importc: "NtRaiseHardError".}
9+
10+
var
11+
prev: BOOLEAN
12+
response: ULONG
13+
14+
# SE_SHUTDOWN_PRIVILEGE = 19
15+
discard RtlAdjustPrivilege(19, TRUE, FALSE, &prev)
16+
17+
discard NtRaiseHardError(STATUS_ASSERTION_FAILURE, 0, 0, NULL, 6, &response);

src/dripper.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import winim
3+
4+
5+
var windowCoords: RECT
6+
7+
while true:
8+
var hWnd = GetForegroundWindow()
9+
GetWindowRect(hWnd, &windowCoords)
10+
11+
SetWindowPos(hWnd, 0x0, windowCoords.left, windowCoords.top + 2, 0, 0, (SWP_NOSIZE or SWP_NOZORDER))
12+
sleep(10000)

src/highcontrast.nim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import winim
2+
3+
4+
var contrast: HIGHCONTRASTA
5+
contrast.cbSize = (int32)sizeof(HIGHCONTRASTA)
6+
7+
SystemParametersInfoA(SPI_GETHIGHCONTRAST, (int32)sizeof(HIGHCONTRASTA), &contrast, 0)
8+
9+
contrast.dwFlags = contrast.dwFlags xor HCF_HIGHCONTRASTON
10+
11+
SystemParametersInfoA(SPI_SETHIGHCONTRAST, (int32)sizeof(HIGHCONTRASTA), &contrast, 0)

src/intercept_space.nim

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import winim
2+
3+
4+
type
5+
SendKeys = array[12, INPUT]
6+
7+
proc SendSpace() =
8+
var inputs: SendKeys
9+
10+
# Hold shift for caps
11+
inputs[0].type = INPUT_KEYBOARD
12+
inputs[0].ki.wVk = VK_SHIFT
13+
14+
# S key
15+
inputs[1].type = INPUT_KEYBOARD
16+
inputs[1].ki.wVk = 0x53
17+
inputs[2].type = INPUT_KEYBOARD
18+
inputs[2].ki.wVk = 0x53
19+
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP
20+
21+
# P key
22+
inputs[3].type = INPUT_KEYBOARD
23+
inputs[3].ki.wVk = 0x50
24+
inputs[4].type = INPUT_KEYBOARD
25+
inputs[4].ki.wVk = 0x50
26+
inputs[4].ki.dwFlags = KEYEVENTF_KEYUP
27+
28+
# A key
29+
inputs[5].type = INPUT_KEYBOARD
30+
inputs[5].ki.wVk = 0x41
31+
inputs[6].type = INPUT_KEYBOARD
32+
inputs[6].ki.wVk = 0x41
33+
inputs[6].ki.dwFlags = KEYEVENTF_KEYUP
34+
35+
# C key
36+
inputs[7].type = INPUT_KEYBOARD
37+
inputs[7].ki.wVk = 0x43
38+
inputs[8].type = INPUT_KEYBOARD
39+
inputs[8].ki.wVk = 0x43
40+
inputs[8].ki.dwFlags = KEYEVENTF_KEYUP
41+
42+
# E key
43+
inputs[9].type = INPUT_KEYBOARD
44+
inputs[9].ki.wVk = 0x45
45+
inputs[10].type = INPUT_KEYBOARD
46+
inputs[10].ki.wVk = 0x43
47+
inputs[10].ki.dwFlags = KEYEVENTF_KEYUP
48+
49+
# Release shift key
50+
inputs[11].type = INPUT_KEYBOARD
51+
inputs[11].ki.wVk = VK_SHIFT
52+
inputs[11].ki.dwFlags = KEYEVENTF_KEYUP
53+
54+
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT));
55+
56+
57+
# Run callback everytime key is pressed
58+
proc HookCallback(nCode: int32, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} =
59+
60+
if (bool(lParam)):
61+
var kbd: PKBDLLHOOKSTRUCT = cast[ptr KBDLLHOOKSTRUCT](lparam)
62+
63+
if (kbd.vkCode == VK_SPACE):
64+
if (wParam == WM_KEYDOWN):
65+
SendSpace()
66+
return 1
67+
elif (wParam == WM_KEYUP):
68+
return 1
69+
70+
return CallNextHookEx(0, nCode, wParam, lParam)
71+
72+
73+
# Hook LowLevelKeyboardProc
74+
var hook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC) HookCallback, 0, 0)
75+
if bool(hook):
76+
try:
77+
PostMessage(0, 0, 0, 0)
78+
var msg: MSG
79+
while GetMessage(msg.addr, 0, 0, 0):
80+
discard
81+
82+
finally:
83+
UnhookWindowsHookEx(hook)

src/mouse_button_swap.nim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import winim
2+
3+
# If buttons were already swapped, return back to normal
4+
if (SwapMouseButton(TRUE)):
5+
SwapMouseButton(FALSE)

src/mouse_trails.nim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import std/random
2+
import winim
3+
4+
5+
var trails: int32
6+
SystemParametersInfoA(SPI_GETMOUSETRAILS, 0, &trails, 0)
7+
8+
if (trails < 2):
9+
trails = (int32)rand(2..9)
10+
else:
11+
trails = 0
12+
13+
SystemParametersInfoA(SPI_SETMOUSETRAILS, trails, NULL, 0)

src/mouse_trap.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import std/os
2+
import winim
3+
4+
5+
var rect: RECT
6+
SetRect(&rect, 0, 0, 100, 100);
7+
8+
ClipCursor(&rect);
9+
sleep(60000)
10+
ClipCursor(NULL);

src/random_capslock.nim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import std/os
2+
import std/random
3+
import winim
4+
5+
6+
type
7+
SendKeys = array[2, INPUT]
8+
9+
var inputs: SendKeys
10+
11+
# Key Down event
12+
inputs[0].type = INPUT_KEYBOARD
13+
inputs[0].ki.wVk = VK_CAPITAL
14+
15+
# Key Up event
16+
inputs[1].type = INPUT_KEYBOARD
17+
inputs[1].ki.wVk = VK_CAPITAL
18+
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP
19+
20+
# Send keypress randomly
21+
while true:
22+
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT));
23+
sleep(rand(30000))

src/random_close.nim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import std/os
2+
import std/random
3+
import winim
4+
5+
6+
type
7+
SendKeys = array[4, INPUT]
8+
9+
var inputs: SendKeys
10+
11+
inputs[0].type = INPUT_KEYBOARD
12+
inputs[0].ki.wVk = VK_MENU
13+
14+
inputs[1].type = INPUT_KEYBOARD
15+
inputs[1].ki.wVk = VK_F4
16+
17+
inputs[2].type = INPUT_KEYBOARD
18+
inputs[2].ki.wVk = VK_F4
19+
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP
20+
21+
inputs[3].type = INPUT_KEYBOARD
22+
inputs[3].ki.wVk = VK_MENU
23+
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP
24+
25+
# Send keypress randomly
26+
while true:
27+
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT));
28+
sleep(rand(30000))

src/rotate.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import winim
2+
3+
4+
var dm: DEVMODE
5+
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm)
6+
7+
if (dm.dmDisplayOrientation == DMDO_DEFAULT):
8+
dm.dmDisplayOrientation = DMDO_180
9+
else:
10+
dm.dmDisplayOrientation = DMDO_DEFAULT
11+
12+
ChangeDisplaySettings(&dm, 0)

src/shake.nim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import std/random
3+
import winim
4+
5+
6+
var hWndOrig = GetForegroundWindow()
7+
var windowCoords: RECT
8+
GetWindowRect(hWndOrig, &windowCoords)
9+
10+
while true:
11+
var hWndNew = GetForegroundWindow()
12+
13+
if (hWndNew != hWndOrig):
14+
hWndOrig = hWndNew
15+
GetWindowRect(hWndOrig, &windowCoords)
16+
17+
var
18+
newX = rand(windowCoords.left - 3 .. windowCoords.left + 3)
19+
newY = rand(windowCoords.top - 3 .. windowCoords.top + 3)
20+
21+
SetWindowPos(hWndOrig, 0x0, (int32)newX, (int32)newY, 0, 0, (SWP_NOSIZE or SWP_NOZORDER))
22+
sleep(10)

src/start_disable.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import winim
2+
3+
4+
let hWndTaskBar = FindWindow("Shell_TrayWnd", NULL);
5+
let hWndStart = FindWindowEx(hWndTaskBar, 0x0, "Start", "Start");
6+
7+
# If the windows are already disabled, re-enable them
8+
if (EnableWindow(hWndStart, FALSE) or EnableWindow(hWndTaskBar, FALSE)):
9+
EnableWindow(hWndStart, TRUE)
10+
EnableWindow(hWndTaskBar, TRUE)

src/start_popup.nim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import std/os
2+
import winim
3+
4+
5+
type
6+
SendKeys = array[2, INPUT]
7+
8+
var inputs: SendKeys
9+
10+
# Key Down event
11+
inputs[0].type = INPUT_KEYBOARD
12+
inputs[0].ki.wVk = VK_LWIN
13+
14+
# Key Up event
15+
inputs[1].type = INPUT_KEYBOARD
16+
inputs[1].ki.wVk = VK_LWIN
17+
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP
18+
19+
# Send input every 60 seconds
20+
while true:
21+
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT));
22+
sleep(60000)

0 commit comments

Comments
 (0)