Skip to content

Instantly share code, notes, and snippets.

@8051Enthusiast
8051Enthusiast / polyrec-fizzbuzz.rs
Last active November 10, 2023 07:54
fucked up fizzbuzz (compile with `RUST_MIN_STACK=1000000000` and cranelift backend (and roughly 10GB of memory))
#![recursion_limit = "1000000"]
trait N {
fn f<B: N, C: N, D: N, E: N, F: N, G: N, H: N, I: N>(fun: impl FnMut());
}
impl N for i8 {
#[inline(never)]
fn f<B: N, C: N, D: N, E: N, F: N, G: N, H: N, I: N>(mut fun: impl FnMut()) {
fun();
B::f::<Self, C, D, E, F, G, H, I>(fun)
}
@8051Enthusiast
8051Enthusiast / fizzbuzz.c
Last active July 6, 2023 10:41 — forked from anonymous/fizzbuzz.c
A FizzBuzz program. Somehow. I don't know why it works. The long awaited sequel with proper allocation sizes.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gmp.h>
char * polynomial="-74101463560860539810482394216134472786413399/404009590666424903383979388988167534591844018460526499864038804741201731572423877094984692537474105135297393596654648304117684895744000000000000000000000*x^99 + 1786563401621773217421750502452955853226339781/1943688752347061390850759947022111850270039951356484879070977067483444756705819339975871373032521468004867185688372878439054154137600000000000000000000*x^98 - 27321291157050372775340569532625689973429185264741/12024094960310264981666053243695462339042976739896622019763059664916718201560234437350734896948634081407660523709959770955883479040000000000000000000000*x^97 + 4936870031754926645682423836151042176171669450909/1336493173680525187613977630110369004256312194947800263402124063124652591386915768177479078216982141485276408003996973457735680000000000000000000000*x^96 - 24473118674386691114350902920738421254018653211816783/55093218603941649400531744530105211175454647
@8051Enthusiast
8051Enthusiast / allyourbase.py
Last active April 26, 2023 23:20
a script that tries to find a base address candidate for firmware by looking at string addresses and pointer target addresses
#!/usr/bin/env python3
import sys
import re
import argparse
import math
from typing import Literal
import numpy as np
def get_string_addresses(b: bytes, n: int) -> set[int]:
@8051Enthusiast
8051Enthusiast / advent-of-code-6.sage
Last active December 14, 2022 03:34
advent-of-code-6.sage
num = {'a': 0x4f04adb47ec5294440250a2aca3cc81cdc7adcc8fc8f4df95a2ca92c41cc8b221a5626e429f89a2e4d317eeea16b3475bb6878be9b5584be0d64e409c14a57fd7a2c876b2361854cb7f8e49a13e9f41e924b0a2bd093228e964a91dcc9ed7e76f093657e4fe3c3b75a6ad442ef0d0a40fb6294d556792753657d03add51daf355ea669cc5c195b9fe87fe45e3a85bba8674a07e081372ceda9495e741ac26385cf67b3448d983edefd666856446975e2aaf7e5aa23fc6629125cc3f6b970ade2c118796975f47939a5d5dfbae9d77c690d3de380519c0224ed924d3d0606fd849595d57e7bdae9770b1d07dcf6e1ad3d46faa75298aa115f6de06f733a18cd96e34a2cc8483cd40461cee9d77d7d5c12c86ff2742e3060b01e41511b58d5a5563bf2dc22b61a4c4a44dac8e7fcee04dd07a58ae22483dcb628a08803e196863822707d2e25754113d3bd2d07189da675ca2c0b4e8cfa14c6543d09d4d96932d385ee7e6f8a8ec733fc54ceb63070067e6d269f201149c4d60d642cffafe2a8baff351a7972df6c1961ab1eeb11b4623f545c40e760cdf6e449ffe96a5af0281dffcf8e10e4a41b4e5840835271566e13f69d1c0619f2f7df39d3bb5b68ca6396ce61090c4ed22af4628e9d1d636ace86a84df7503fd84df678129fa43fe2af0c967a9532d8c1cbf0711193b60401f9b147e95fa83ece05a019
@8051Enthusiast
8051Enthusiast / genptrref.py
Last active November 17, 2020 05:41
finds general pointer references in ghidra 8051 code
state = getState()
currentProgram = state.getCurrentProgram()
def to_positive(b):
if b >= 0:
return b
return b + 256
def maybe_get_gptr_ref(b):
if len(b) < 6:
return None
@8051Enthusiast
8051Enthusiast / at51fun.py
Created July 6, 2020 15:21
Ghidra script to import functions found by at51's libfind into ghidra
# Imports the functions found by at51 into the program
import json
import subprocess
import sys.exit as exit
state = getState()
currentProgram = state.getCurrentProgram()
filepath = currentProgram.getExecutablePath()
# note: this won't work properly if the file is loaded at an offset
proc = subprocess.Popen(["at51", "libfind", "-j", filepath],
stdout = subprocess.PIPE, stderr = subprocess.PIPE)
@8051Enthusiast
8051Enthusiast / quine.c
Created April 19, 2020 21:13
preprocess with `gcc -E -std=c99 quine.c -o quine.i` and compile with `gcc -std=gnu99 quine.i -o quine`
#include <stdio.h>
#ifdef A
R"("
#else
#define A
const char *s =
#include __FILE__
;
#undef A
#endif
@8051Enthusiast
8051Enthusiast / cursed_jumptable.a51
Last active October 3, 2021 03:12
cursed_jumptable.a51
; Licensed under the MIT License:
; Copyright (c) 2021 8051Enthusiast
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions: