Skip to content

Instantly share code, notes, and snippets.

View iximeow's full-sized avatar
🐟
you can tune a piano but you can't tuna fish

iximeow iximeow

🐟
you can tune a piano but you can't tuna fish
View GitHub Profile
@iximeow
iximeow / wakeup_lat.rs
Last active December 13, 2024 01:41
measure wakeup latencies
// this program tries to measure a producer/consumer latency when
// the consumer thread may be in deep idle states.
//
// illumos only for now, sorry.
//
// run like `./wakeup_lat 20 22 park 200` to measure
// core 20 waking core 22, 200 times
use std::sync::{Arc, Condvar, Mutex};
use std::sync::atomic::Ordering;
@iximeow
iximeow / msr_peek.rs
Last active December 6, 2024 23:17
msr read characteristics
//! # hey! you're curious about the characteristics of reading various MSRs? me too!
//!
//! this reads a few registers (TSC, AMD RAPL core and package power) 2M times and reports a bit
//! about the adventure. you need root wherever you run it. runs on linux (need the `msr` module
//! loaded) or illumos.
//!
//! you probably want to bind this to a single CPU when run. if you don't, it might work
//! reasonably, or if it's task-switched between cores while running, core-specific MSRs (RAPL core
//! power) will have nonsense skew.
//!
#include <assert.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
int main() {
int fd = open("doesnotexist", O_CREAT);
assert(fd > 0);
void* map = mmap(NULL, 65536, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
@iximeow
iximeow / stub.rs
Created January 30, 2022 00:21
glue between nasm and exec
use std::io::Write;
use std::process::Command;
extern "C" {
fn mprotect(addr: *const u8, len: usize, prot: u32) -> u32;
}
fn main() {
let mut args = std::env::args();
let _ = args.next();
@iximeow
iximeow / disassembly
Created August 1, 2021 00:29
some function out of ntoskrn and (... some of its ...) interactions with memory
0x00000000: 48895c2408 : mov qword [rsp + 0x8], rbx
0x00000005: 48896c2410 : mov qword [rsp + 0x10], rbp
0x0000000a: 4889742418 : mov qword [rsp + 0x18], rsi
0x0000000f: 57 : push rdi
0x00000010: 4154 : push r12
0x00000012: 4155 : push r13
0x00000014: 4883ec20 : sub rsp, 0x20
0x00000018: 4885c9 : test rcx, rcx
0x0000001b: 0f844b040c00 : jz 0xc044b
0x00000021: f6410602 : test byte [rcx + 0x6], 0x2
@iximeow
iximeow / asn1.sh
Created April 13, 2021 00:12
asn.1 parsing in pure bash
#! /bin/bash
asn1=$(echo -e "\x30\x13\x02\x01\x05\x16\x0e\x41\x6e\x79\x62\x6f\x64\x79\x20\x74\x68\x65\x72\x65\x3f")
#asn2=$(echo -e "\x00\x01\x02\x03")
asn2=""
offset=0
# while [ $offset -lt ${#asn1} ]; do
# curr=${asn1:offset:1}
# printf "$offset: %02x\n" \'$curr
@iximeow
iximeow / main.c
Last active February 21, 2021 20:01
how to download more ram
/*
* if you need more memory, add some to your program with this cool trick
*/
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/mman.h>
@iximeow
iximeow / main.rs
Created October 10, 2020 04:19
rust is good at vtables
trait Person {
fn greeting(&self) -> StateOfMind;
fn name(&self) -> &'static str;
}
struct Ixi { }
struct Katie { }
#[derive(Debug)]
enum StateOfMind {
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ucontext.h>
#include <stdint.h>
void interpret(char op) {
printf("interpreting %02x\n", op);
}
@iximeow
iximeow / the_good_rust.rs
Created July 1, 2020 19:23
monkeypatching in rust
trait Person {
fn greeting(&self) -> StateOfMind;
fn name(&self) -> &'static str;
}
struct Ixi { }
struct Katie { }
#[derive(Debug)]
enum StateOfMind {