-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
415 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,44 @@ | ||
# StopShutdown | ||
A small proof of concept that temporarily prevents a shutdown | ||
# WinAPI-Fun | ||
> A collection of (relatively) harmless prank / virus examples using the Windows API | ||
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. | ||
<br> | ||
|
||
Pre-built binaries can be found in the [Releases](../../releases) section | ||
|
||
To reset most examples, re-launch and kill the program again | ||
|
||
<br> | ||
|
||
| File | Description | | ||
| -------------------------------------------------- | --------------------------------------------------------------------- | | ||
| [avoid.nim](src/avoid.nim) | The start button avoids mouse clicks by jumping around on the taskbar | | ||
| [bsod.nim](src/bsod.nim) | Triggers Blue Screen of Death | | ||
| [dripper.nim](src/dripper.nim) | Moves the current window down slightly every 10 seconds | | ||
| [highcontrast.nim](src/highcontrast.nim) | Enable high contrast mode system-wide | | ||
| [intercept_space.nim](src/intercept_space.nim) | Replaces space bar keypress with the word "space" | | ||
| [mouse_button_swap.nim](src/mouse_button_swap.nim) | Swap the left and right mouse buttons | | ||
| [mouse_trails.nim](src/mouse_trails.nim) | Creates a trail of mouse icons behind the cursor as it moves | | ||
| [mouse_trap.nim](src/mouse_trap.nim) | Traps the mouse cursor in the top right corner for 60 seconds | | ||
| [random_capslock.nim](src/random_capslock.nim) | Randomly toggle the Caps Lock every 0-30 seconds | | ||
| [random_close.nim](src/random_close.nim) | Randomly closes the current focussed window every 0-30 seconds | | ||
| [rotate.nim](src/rotate.nim) | Rotates the display 180 degrees | | ||
| [shake.nim](src/shake.nim) | Rapidly shakes the current focussed window | | ||
| [start_disable.nim](src/start_disable.nim) | Disables clicking the start button or taskbar | | ||
| [start_popup.nim](src/start_popup.nim) | Opens the start menu popup randomly every 0-60 seconds | | ||
| [stop_shutdown.nim](src/stop_shutdown.nim) | Temporarily prevents a shutdown with a custom message | | ||
| [time_local.nim](src/time_local.nim) | Adds the message "HI" to the AM/PM localization string system-wide | | ||
|
||
<br> | ||
|
||
## Requirements | ||
[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 | ||
|
||
Note: if cross-compiling from Linux or macOS, also install the [mingw](https://www.mingw-w64.org/) toolchain and use the `-d:mingw` flag | ||
|
||
```sh | ||
nim c -d:mingw --app:gui src/avoid.nim | ||
``` | ||
|
||
<br> <br> | ||
|
||
### USE AT YOUR OWN RISK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import std/random | ||
import winim | ||
|
||
|
||
let hWndTaskBar = FindWindow("Shell_TrayWnd", NULL); | ||
let hWndStart = FindWindowEx(hWndTaskBar, 0x0, "Start", "Start"); | ||
|
||
var cursor: POINT | ||
GetCursorPos(&cursor) | ||
|
||
var rectTaskBar: RECT | ||
GetWindowRect(hWndTaskBar, &rectTaskBar) | ||
|
||
var rectStart: RECT | ||
GetWindowRect(hWndStart, &rectStart) | ||
|
||
# Reset Start Button Position | ||
SetWindowPos(hWndStart, 0x0, 0, 0, 0, 0, (SWP_NOSIZE or SWP_NOZORDER)) | ||
|
||
var upperBound = rectTaskBar.right - rectStart.right; | ||
|
||
|
||
# Run callback everytime mouse is moved | ||
proc HookCallback(nCode: int32, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} = | ||
GetCursorPos(&cursor) | ||
|
||
if cursor.x >= rectStart.left and cursor.x <= rectStart.right and cursor.y >= rectStart.top: | ||
var newX = rand(upperBound) | ||
SetWindowPos(hWndStart, 0x0, (int32)newX, 0, 0, 0, (SWP_NOSIZE or SWP_NOZORDER)) | ||
GetWindowRect(hWndStart, &rectStart) | ||
|
||
return CallNextHookEx(0, nCode, wParam, lParam) | ||
|
||
|
||
# Hook LowLevelMouseProc | ||
var hook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC) HookCallback, 0, 0) | ||
if bool(hook): | ||
try: | ||
PostMessage(0, 0, 0, 0) | ||
var msg: MSG | ||
while GetMessage(msg.addr, 0, 0, 0): | ||
discard | ||
|
||
finally: | ||
UnhookWindowsHookEx(hook) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import winim | ||
|
||
|
||
proc RtlAdjustPrivilege*(privilege: ULONG, bEnablePrivilege: BOOLEAN, isThreadPrivilege: BOOLEAN, previousValue: PBOOLEAN): NTSTATUS | ||
{.discardable, stdcall, dynlib: "ntdll", importc: "RtlAdjustPrivilege".} | ||
|
||
proc NtRaiseHardError*(errorStatus: NTSTATUS, numberOfParameters: ULONG, unicodeStringParameterMask: ULONG, parameters: PULONG_PTR, validResponseOption: ULONG, response: PULONG): NTSTATUS | ||
{.discardable, stdcall, dynlib: "ntdll", importc: "NtRaiseHardError".} | ||
|
||
var | ||
prev: BOOLEAN | ||
response: ULONG | ||
|
||
# SE_SHUTDOWN_PRIVILEGE = 19 | ||
discard RtlAdjustPrivilege(19, TRUE, FALSE, &prev) | ||
|
||
discard NtRaiseHardError(STATUS_ASSERTION_FAILURE, 0, 0, NULL, 6, &response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
import winim | ||
|
||
|
||
var windowCoords: RECT | ||
|
||
while true: | ||
var hWnd = GetForegroundWindow() | ||
GetWindowRect(hWnd, &windowCoords) | ||
|
||
SetWindowPos(hWnd, 0x0, windowCoords.left, windowCoords.top + 2, 0, 0, (SWP_NOSIZE or SWP_NOZORDER)) | ||
sleep(10000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import winim | ||
|
||
|
||
var contrast: HIGHCONTRASTA | ||
contrast.cbSize = (int32)sizeof(HIGHCONTRASTA) | ||
|
||
SystemParametersInfoA(SPI_GETHIGHCONTRAST, (int32)sizeof(HIGHCONTRASTA), &contrast, 0) | ||
|
||
contrast.dwFlags = contrast.dwFlags xor HCF_HIGHCONTRASTON | ||
|
||
SystemParametersInfoA(SPI_SETHIGHCONTRAST, (int32)sizeof(HIGHCONTRASTA), &contrast, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import winim | ||
|
||
|
||
type | ||
SendKeys = array[12, INPUT] | ||
|
||
proc SendSpace() = | ||
var inputs: SendKeys | ||
|
||
# Hold shift for caps | ||
inputs[0].type = INPUT_KEYBOARD | ||
inputs[0].ki.wVk = VK_SHIFT | ||
|
||
# S key | ||
inputs[1].type = INPUT_KEYBOARD | ||
inputs[1].ki.wVk = 0x53 | ||
inputs[2].type = INPUT_KEYBOARD | ||
inputs[2].ki.wVk = 0x53 | ||
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# P key | ||
inputs[3].type = INPUT_KEYBOARD | ||
inputs[3].ki.wVk = 0x50 | ||
inputs[4].type = INPUT_KEYBOARD | ||
inputs[4].ki.wVk = 0x50 | ||
inputs[4].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# A key | ||
inputs[5].type = INPUT_KEYBOARD | ||
inputs[5].ki.wVk = 0x41 | ||
inputs[6].type = INPUT_KEYBOARD | ||
inputs[6].ki.wVk = 0x41 | ||
inputs[6].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# C key | ||
inputs[7].type = INPUT_KEYBOARD | ||
inputs[7].ki.wVk = 0x43 | ||
inputs[8].type = INPUT_KEYBOARD | ||
inputs[8].ki.wVk = 0x43 | ||
inputs[8].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# E key | ||
inputs[9].type = INPUT_KEYBOARD | ||
inputs[9].ki.wVk = 0x45 | ||
inputs[10].type = INPUT_KEYBOARD | ||
inputs[10].ki.wVk = 0x43 | ||
inputs[10].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# Release shift key | ||
inputs[11].type = INPUT_KEYBOARD | ||
inputs[11].ki.wVk = VK_SHIFT | ||
inputs[11].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT)); | ||
|
||
|
||
# Run callback everytime key is pressed | ||
proc HookCallback(nCode: int32, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} = | ||
|
||
if (bool(lParam)): | ||
var kbd: PKBDLLHOOKSTRUCT = cast[ptr KBDLLHOOKSTRUCT](lparam) | ||
|
||
if (kbd.vkCode == VK_SPACE): | ||
if (wParam == WM_KEYDOWN): | ||
SendSpace() | ||
return 1 | ||
elif (wParam == WM_KEYUP): | ||
return 1 | ||
|
||
return CallNextHookEx(0, nCode, wParam, lParam) | ||
|
||
|
||
# Hook LowLevelKeyboardProc | ||
var hook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC) HookCallback, 0, 0) | ||
if bool(hook): | ||
try: | ||
PostMessage(0, 0, 0, 0) | ||
var msg: MSG | ||
while GetMessage(msg.addr, 0, 0, 0): | ||
discard | ||
|
||
finally: | ||
UnhookWindowsHookEx(hook) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import winim | ||
|
||
# If buttons were already swapped, return back to normal | ||
if (SwapMouseButton(TRUE)): | ||
SwapMouseButton(FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import std/random | ||
import winim | ||
|
||
|
||
var trails: int32 | ||
SystemParametersInfoA(SPI_GETMOUSETRAILS, 0, &trails, 0) | ||
|
||
if (trails < 2): | ||
trails = (int32)rand(2..9) | ||
else: | ||
trails = 0 | ||
|
||
SystemParametersInfoA(SPI_SETMOUSETRAILS, trails, NULL, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import std/os | ||
import winim | ||
|
||
|
||
var rect: RECT | ||
SetRect(&rect, 0, 0, 100, 100); | ||
|
||
ClipCursor(&rect); | ||
sleep(60000) | ||
ClipCursor(NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import std/os | ||
import std/random | ||
import winim | ||
|
||
|
||
type | ||
SendKeys = array[2, INPUT] | ||
|
||
var inputs: SendKeys | ||
|
||
# Key Down event | ||
inputs[0].type = INPUT_KEYBOARD | ||
inputs[0].ki.wVk = VK_CAPITAL | ||
|
||
# Key Up event | ||
inputs[1].type = INPUT_KEYBOARD | ||
inputs[1].ki.wVk = VK_CAPITAL | ||
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# Send keypress randomly | ||
while true: | ||
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT)); | ||
sleep(rand(30000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import std/os | ||
import std/random | ||
import winim | ||
|
||
|
||
type | ||
SendKeys = array[4, INPUT] | ||
|
||
var inputs: SendKeys | ||
|
||
inputs[0].type = INPUT_KEYBOARD | ||
inputs[0].ki.wVk = VK_MENU | ||
|
||
inputs[1].type = INPUT_KEYBOARD | ||
inputs[1].ki.wVk = VK_F4 | ||
|
||
inputs[2].type = INPUT_KEYBOARD | ||
inputs[2].ki.wVk = VK_F4 | ||
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
inputs[3].type = INPUT_KEYBOARD | ||
inputs[3].ki.wVk = VK_MENU | ||
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# Send keypress randomly | ||
while true: | ||
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT)); | ||
sleep(rand(30000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import winim | ||
|
||
|
||
var dm: DEVMODE | ||
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm) | ||
|
||
if (dm.dmDisplayOrientation == DMDO_DEFAULT): | ||
dm.dmDisplayOrientation = DMDO_180 | ||
else: | ||
dm.dmDisplayOrientation = DMDO_DEFAULT | ||
|
||
ChangeDisplaySettings(&dm, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import std/random | ||
import winim | ||
|
||
|
||
var hWndOrig = GetForegroundWindow() | ||
var windowCoords: RECT | ||
GetWindowRect(hWndOrig, &windowCoords) | ||
|
||
while true: | ||
var hWndNew = GetForegroundWindow() | ||
|
||
if (hWndNew != hWndOrig): | ||
hWndOrig = hWndNew | ||
GetWindowRect(hWndOrig, &windowCoords) | ||
|
||
var | ||
newX = rand(windowCoords.left - 3 .. windowCoords.left + 3) | ||
newY = rand(windowCoords.top - 3 .. windowCoords.top + 3) | ||
|
||
SetWindowPos(hWndOrig, 0x0, (int32)newX, (int32)newY, 0, 0, (SWP_NOSIZE or SWP_NOZORDER)) | ||
sleep(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import winim | ||
|
||
|
||
let hWndTaskBar = FindWindow("Shell_TrayWnd", NULL); | ||
let hWndStart = FindWindowEx(hWndTaskBar, 0x0, "Start", "Start"); | ||
|
||
# If the windows are already disabled, re-enable them | ||
if (EnableWindow(hWndStart, FALSE) or EnableWindow(hWndTaskBar, FALSE)): | ||
EnableWindow(hWndStart, TRUE) | ||
EnableWindow(hWndTaskBar, TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import std/os | ||
import winim | ||
|
||
|
||
type | ||
SendKeys = array[2, INPUT] | ||
|
||
var inputs: SendKeys | ||
|
||
# Key Down event | ||
inputs[0].type = INPUT_KEYBOARD | ||
inputs[0].ki.wVk = VK_LWIN | ||
|
||
# Key Up event | ||
inputs[1].type = INPUT_KEYBOARD | ||
inputs[1].ki.wVk = VK_LWIN | ||
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP | ||
|
||
# Send input every 60 seconds | ||
while true: | ||
SendInput((UINT)len(inputs), &inputs[0], (int32)sizeof(INPUT)); | ||
sleep(60000) |
Oops, something went wrong.