Skip to content

Instantly share code, notes, and snippets.

@prozacchiwawa
prozacchiwawa / elfshow.py
Last active November 17, 2024 08:18
Given an elf file, show a hex dump of each section along with the relationships between symbols and relocations annotated below each line
import sys
from elftools.elf.elffile import ELFFile
from elftools.elf.sections import Section, SymbolTableSection, Symbol
from elftools.elf.relocation import RelocationSection, Relocation
from elftools.elf.constants import SH_FLAGS
class RelocSource:
def __init__(self, target_section_number, symbol_section_number, r):
self.target_section_number = target_section_number
self.symbol_section_number = symbol_section_number
@prozacchiwawa
prozacchiwawa / fake-elf.py
Created September 11, 2024 06:07
Make an elf file that pretends to have specific functions at specific addresses
#!/usr/bin/env python
from elftools.elf.elffile import ELFFile
from pathlib import Path
import struct
import subprocess
# Steps
#
# 0) Read definitions with addresses
@prozacchiwawa
prozacchiwawa / serialwrap.py
Created May 27, 2024 02:35
gxemul XTERM= wrapper for connecting to a serial server from qemu (or others)
#!/usr/bin/env python3
# adapted from my xtwrap
import os
import sys
import tty
import time
import uuid
import signal
import socket
@prozacchiwawa
prozacchiwawa / readdress.py
Created May 5, 2024 07:36
Simple way of marking up a ppc disassembly with addresses and info
#!/usr/bin/env python
import sys
import argparse
import json
branch_instrs = [
'b',
'bl',
'beq',
@prozacchiwawa
prozacchiwawa / metris_challenge.txt
Last active January 21, 2024 02:58
A weird quine related challenge idea
Tetris has these pieces:
[][] [][] [][] [] [][][][] [] []
[][] [][] [][] [][] [] []
[] [][] [][]
If you associate a 4-byte sequence with each of these pieces and use the method
below to turn a tetris game with a specific piece sequence and move sequence
into a program using those sequences, it seems possible that that program could
itself be a tetris game that can write itself into memory or to some io device.
@prozacchiwawa
prozacchiwawa / rs6000_checksum.py
Created December 29, 2023 19:31
RS/6000 nvram checksum algorithm
def rol(r,n):
return (r << n) | (r >> (32 - n))
def crcgen(r3,r4):
r6 = rol(r3,8) & 0xff00
r0 = rol(r4,0) & 0xff
r3 = rol(r3,24) & 0xffffff
r4 = r3 ^ r0
r0 = rol(r4,8) & 0xffffff00
r0 = rol(r0,20) & 0xfffff
@prozacchiwawa
prozacchiwawa / palette.py
Last active March 16, 2023 00:33
A nice 64 color palette?
from PIL import Image
img = Image.new(mode="RGB", size=(8,8))
pixels = [ ]
# Black
pixels.append((0,0,0))
# Greys and white
for i in range(15):
v = int((i + 1) * (255 / 15))
@prozacchiwawa
prozacchiwawa / main.rs
Last active February 5, 2023 05:59
Haskell inspired type based destructuring in rust
use serde_json;
pub enum And<T,U> {
These(T,U)
}
pub enum Field<T> {
Named(&'static str,T)
}
#[cfg(any(test, feature = "fuzzer"))]
use rand::prelude::*;
use rand::Error;
use random_lfsr_256_galois::{LFSRGalois, LFSRGaloisBuilder};
// A pseudo RNG which uses a slice for all entropy. It iterates a given slice
// many times, scrambling the bits through an LFSR in subsequent passes so that
// the fuzzer maintains a relationship between the original input bits and the
// output with some predictability.
@prozacchiwawa
prozacchiwawa / div2.v
Last active September 26, 2022 08:24
very crap proof that n/2 < n for n > 0
Fixpoint nat_lt (a : nat) (b : nat) : bool :=
match b with
| 0 => false
| (S b1) =>
match a with
| 0 => true
| (S a1) => nat_lt a1 b1
end
end.