Skip to content

Instantly share code, notes, and snippets.

@mooware
mooware / gnu-libc-print-stacktrace.c
Last active April 25, 2024 12:29
Print a stacktrace on Linux with GNU libc
// this code fragment shows how to print a stack trace (to stderr)
// on Linux using the functions provided by the GNU libc
#include <execinfo.h>
#define MAX_STACK_LEVELS 50
// helper-function to print the current stack trace
void print_stacktrace()
{
@mooware
mooware / ra_api.py
Last active March 7, 2024 04:30
RetroAchievements API client in python for getting random games from their database
import urllib.request
import os, json, random, time, re
# adult games are part of the hub "Theme - Mature",
# but I can't get the data over the API, so I manually scraped it from the website.
# use this expression in the browser dev console on the mature hub:
# Array.from(document.querySelectorAll("table td.py-2 a")).map(x => x.href.split("/")[4] + ", # " + x.parentElement.outerText.split("\n")[0]).join("\n")
# scrape date: 2024-03-06
_mature_games = set([
420, # Mario is a Drug Addict
# takes a csv export of the google sheet as input and tries to download pastebins
#
# usage:
# download_pastebins.py <prefix> <name column> <url column> <csv file>
#
# example:
# download_pastebins.py mt18 1 5 "MT18 Draw List - Played Games.csv"
import sys, os, re, urllib.request, csv
@mooware
mooware / ld-preload-intercept-method.cpp
Last active November 29, 2023 16:59
Intercept C++ methods with LD_PRELOAD
// this file is an example of how to intercept a C++ method by using the
// LD_PRELOAD environment variable of the GNU dynamic linker.
//
// it works like this:
//
// 1) define a method that will have the same symbol as the intercepted
// method when compiled. For example, the method Foo::getValue()
// defined here has the mangled symbol "_ZNK3Foo8getValueEv".
// tools like nm, objdump or readelf can display the symbols of
// binaries. note that depending on compiler and linker options,
@mooware
mooware / changeres.cpp
Last active October 23, 2023 14:51
Simple program to change the display resolution on Windows
// prebuilt for VC14/VS2015 here:
// https://dl.dropboxusercontent.com/u/267889/changeres.exe
#include <iostream>
#include <sstream>
#include <Windows.h>
int main(int argc, char **argv)
{
bool reset = false;
@mooware
mooware / cdb-show-dump.cmd
Last active October 21, 2023 01:33
print lots of windows minidump information with CDB
@echo off
:: used cdb commands:
:: !sym noisy -> prints verbose output when searching PDBs
:: .symopt+0x40 -> accept mismatching PDBs
:: .lines -e -> enable source file and line information
:: .kframes 100 -> set max number of display stack frames to 0x100
:: lmv -> list all loaded modules with version information
:: | -> show process status
:: !peb -> show process environment block (command line arguments, environment variables)
@mooware
mooware / codepage_unzip.py
Last active August 22, 2023 17:08
A little script to extract old japanese zip files with the correct text encoding for filenames. Most applications assume a US text codepage for old zip formats, which is not always correct.
# A little script to extract old japanese zip files
# with the correct text encoding for filenames.
# Most applications assume a US text codepage for
# old zip formats, which is not always correct.
import os
import shutil
import sys
import zipfile
from datetime import datetime
@mooware
mooware / colorstreamhandler.py
Last active July 20, 2023 16:16
Colored log output for Python logging framework. Works on Windows, Linux, and probably Mac as well.
# colored stream handler for python logging framework (use the ColorStreamHandler class).
#
# based on:
# http://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output/1336640#1336640
# how to use:
# i used a dict-based logging configuration, not sure what else would work.
#
# import logging, logging.config, colorstreamhandler
#
@mooware
mooware / srl.html
Last active January 14, 2023 01:13
HTML page to list SRL races and link to multitwitch and similar services
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>SRL Races</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
@mooware
mooware / outlook-disable-encryption.py
Created October 23, 2019 00:51
Python script to monitor the Windows registry and ensure that Outlook email encryption by default stays off
import ctypes, ctypes.wintypes
advapi32 = ctypes.windll.advapi32
# LSTATUS RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
RegOpenKeyExA = advapi32.RegOpenKeyExA
RegOpenKeyExA.argtypes = (ctypes.wintypes.HKEY, ctypes.wintypes.LPCSTR, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.wintypes.PHKEY)
# LSTATUS RegCloseKey(HKEY hKey)
RegCloseKey = advapi32.RegCloseKey