Skip to content

Instantly share code, notes, and snippets.

View mfukar's full-sized avatar

Michael Foukarakis mfukar

View GitHub Profile
@mfukar
mfukar / inspector_malloc.gdb
Last active May 9, 2023 11:04
gdb functions to dump glibc malloc arenas + chunks
define -mem-heap-dump-chunk
printf "%#016x: ", $mem_addr
printf "%016lu %016lu %#02x ", ((long *)$mem_addr)[0], ((long *)$mem_addr)[1] & ~3, ((long*)$mem_addr)[1] & 3
printf "%016x %016x\n", ((long *)$mem_addr)[2], ((long *)$mem_addr)[3]
set $mem_addr = $mem_addr + ((long *)$mem_addr)[1] & ~3
end
document -mem-heap-dump-chunk
!!! FOR INTERNAL USE ONLY - DO NOT CALL !!!
end
@mfukar
mfukar / fuckyou.cpp
Created October 4, 2022 15:06
fuck this interview question and fuck the people that ask stupid questions that require this answer
#include <iostream>
template<int N>
struct stupid {
static void out(std::ostream& os) {
stupid<N-1>::out(os);
os << N << std::endl;
}
};
@mfukar
mfukar / download_owned_cards.ps1
Last active February 2, 2022 03:29
[Tyrant Unleashed] Download your cards into a ownedcards.txt file, and your decks into a currentdecks.txt, for use with the optimiser. From your browser, get the response from the api.php?message=init request into a file named json.txt in the /data/ directory of the optimiser, along with this script. Reqs Powershell 7. Will create two files in t…
$stopwatch = [Diagnostics.Stopwatch]::StartNew()
if (-not (Test-Path "json.txt")) {
Write-Host "[-] To update owned cards, supply the response to api.php?message=init in json.txt"
exit 1
}
$account_details = Get-Content "json.txt" | ConvertFrom-JSON -AsHashtable
if (-not (Test-Path "cards_section*.xml")) {
Write-Host "[-] Run this script inside the optimiser's /data/ directory"
@mfukar
mfukar / luhn.cpp
Last active November 8, 2021 17:27
The Luhn test in C++11
#include <algorithm>
#include <numeric>
#include <iostream>
#include <vector>
/*
* Assuming an input of a string of digits, perform the Luhn test on the indicated sequence.
* Returns true if the given string passes the test, false otherwise.
*/
bool luhn(const std::string& seq) {
@mfukar
mfukar / countdown.cpp
Last active November 8, 2021 17:26
Countdown
/**
* Solver for the Countdown numbers game. Branch-and-bound search.
* Compile with:
* clang++ -std=c++17 -O3 -o countdown countdown.cpp
*
* Should find answers in much less than a second.
*/
#include <limits>
#include <vector>
#include <string>
@mfukar
mfukar / z3-salsa10.py
Last active September 3, 2020 08:07
Recover the key used by Petya to encrypt the MFT
# Recover the key used by the Petya ransomware to encrypt the MFT (master file table)
import z3
import sys, struct
# XOR key for salsa10-src.bin :
KEY_SECTOR = 0x37
# Counter position, as two words
CNTLO = 0
CNTHI = 0
@mfukar
mfukar / terminate-worker-threads.c
Last active June 6, 2020 00:23
C11 code to have a POSIX multithreaded application which signal work completion via a condition variable, and then terminate.
#include <unistd.h>
#include <stdbool.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 10
pthread_mutex_t cv_mutex;
pthread_cond_t notification_cv;
@mfukar
mfukar / mach_msg_hook.c
Last active March 21, 2018 03:34
Hook mach_msg and print message contents
/*
* View the contents of messages sent/received via `mach_msg`.
*
* Compile with:
* clang -arch x86_64 -arch i386 -Wall -o mach_msg_hook.dylib -dynamiclib mach_msg_hook.c
*
* and run as:
* DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=mach_msg_hook.dylib [COMMAND]
*
* Have fun.
@mfukar
mfukar / com.local.jekyll.server.agent.plist
Created August 14, 2017 09:03
macos LaunchAgent to debug, test, and serve a Github page locally
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.local.jekyll.server.agent</string>
<key>ProgramArguments</key>
<array>
<string>PATH_TO_YOUR_BUNDLE_BINARY_OR_WRAPPER</string>
@mfukar
mfukar / vmware.py
Created May 26, 2016 18:21
Some interview question from VMware. Figure out the problem statement, it's obvious.
import sys
def main():
N = raw_input()
elements = [int(element) for element in sys.stdin.read().split(' ')]
L, R = 0, len(elements)
# We got ourselves a maximum subarray problem, with inverted semantics.
# The subarray we want to find is the one to flip all the bits in.