Skip to content

Instantly share code, notes, and snippets.

#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 {
@iximeow
iximeow / segment_heccery.asm
Created December 29, 2019 11:20
what does Sz bit do in protected mode
; build and run: `nasm segment_heccery.asm -f bin -o img.bin && qemu-system-x86_64 img.bin -s -S`
[BITS 16]
[ORG 7c00h]
init:
cli
lgdt [gdtr]
mov eax, cr0
or al, 1
@iximeow
iximeow / bootloader.asm
Created December 12, 2017 06:41
x86 totally supports read/write to 0
; assemble like `nasm bootloader.asm` (will produce a flat binary output by default)
; run like `qemu-system-x86_64 bootloader`
[BITS 16]
[ORG 7c00h]
init:
mov cx, 0xB800
mov gs, cx
call clr_vga
mov si, HELLO