Skip to content

Instantly share code, notes, and snippets.

View NSG650's full-sized avatar
🥶
XCHG EAX, EAXing

NSG650 NSG650

🥶
XCHG EAX, EAXing
View GitHub Profile
@NSG650
NSG650 / WindowFocusLogger.c
Last active June 11, 2024 10:06
Logs which processes have received window focus
#include <stdio.h>
#include <Windows.h>
VOID CALLBACK WinEventProcHook(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd,
LONG idObject, LONG idChild, DWORD idEventThread, DWORD dwmsEventTime) {
DWORD ProcessId = 0;
if (GetWindowThreadProcessId(hwnd, &ProcessId) != 0) {
HANDLE ProcessHandle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, ProcessId);
if (ProcessHandle != (HANDLE)(-1)) {
char buffer[MAX_PATH] = {0};
@NSG650
NSG650 / FatalAppExitA.asm
Last active April 27, 2024 05:45
This x86_64 assembly program for Windows displays a message using the FatalAppExitA function.
section .text
extern _Start
_Start:
mov rax, [gs:0x60] ; rax = Peb
mov rax, [rax + 0x18] ; rax = Peb->Ldr
mov rsi, [rax + 0x20] ; rsi = Peb->Ldr->InMemoryOrderModuleList
; The first module is the executable itself
@NSG650
NSG650 / main.c
Created April 22, 2024 11:38
Multi threaded matrix multiplications using NT native API
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include "native.h"
#include "random.h"
typedef struct _MATRIX {
double **matrix;
ULONG rows;
ULONG columns;
@NSG650
NSG650 / lr.py
Last active February 9, 2024 15:53
Random idea I had for a linear regression algorithm by using medians
# This was put in a hurry will be bad but the key idea is
# - we calculate the slope between every 2 point and take the median out of all those slopes
# - now using the median slope we calculate the value of the b intercept and take the median out of all those b intercepts
# the line formed is y = median_slope * x + median_intercept
# This is probably not the best way. I am open for suggestions.
import matplotlib.pyplot as plt
import random
random_slope = random.randint(1, 10)
@NSG650
NSG650 / win95_key_gen.c
Last active November 26, 2023 12:21
Windows 95 Key generator
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#define random_between(min, max) (rand() % (max - min) + min)
#include <stdio.h>
#include <windows.h>
RECT gUsableAreaCoords = {0};
RECT gCurrentPos = {0};
INT gVelocityX = 5;
INT gVelocityY = 5;
DWORD gLast = 0;
@NSG650
NSG650 / fixing_fit.c
Created September 11, 2023 07:34
Fit To Screen Implementation in SDL2 and C
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <stdint.h>
#include <stddef.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
@NSG650
NSG650 / sudoku_generator_and_solver.c
Created July 17, 2023 10:57
Sudoku generator and then solves the generated puzzle.
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
/*
uint8_t sudoku_input_board[81] = {
0, 0, 8, 0, 6, 1, 0, 0, 0,
6, 0, 4, 0, 0, 7, 5, 0, 0,
@NSG650
NSG650 / console.c
Last active July 7, 2023 17:11
XNU on a Raspberry Pi. Patches for limine
noreturn void enter_in_el1_without_paging(uint64_t entry, uint64_t sp, uint64_t target_x0);
static void macho_highest_lowest(struct macho_header* mh, uint64_t *lowaddr, uint64_t *highaddr) {
struct load_command* cmd = (struct load_command*)((uint8_t*)mh + sizeof(struct macho_header));
// iterate through all the segments once to find highest and lowest addresses
uint64_t low_addr_temp = ~0;
uint64_t high_addr_temp = 0;
for (uint32_t i = 0; i < mh->command_count; i++) {
switch (cmd->cmd) {
case 0x19: {
struct segment_command_64* seg_cmd = (struct segment_command_64*)cmd;
@NSG650
NSG650 / nd2html.py
Created February 24, 2023 14:44
Really ugly python script to convert nd [a md like format of mine] to an html blog post for my website
import sys
from datetime import date
def parse_line(line):
if line[0] == "#":
if line[1] == "#":
return f"</div><div><h2>{line[2:]}</h2>"
return f"</div><div><h1>{line[2:]}</h1>"
if line[0] == "!":
text_to_use = line[line.index('[') + 1:line.index(']')]