Skip to content

Instantly share code, notes, and snippets.

View JonathonReinhart's full-sized avatar

Jonathon Reinhart JonathonReinhart

View GitHub Profile
@JonathonReinhart
JonathonReinhart / SConstruct
Last active January 6, 2024 06:42
mkdir -p implemented in C
env = Environment(
CCFLAGS = ['-Wall', '-Werror'],
)
env.Program('mkdir_p_test', ['mkdir_p.c', 'test.c'])
@JonathonReinhart
JonathonReinhart / pystartup.py
Created February 18, 2017 18:17
Default hex output in Python interactive console
# Display integers as hex and decimal
import sys
def displayhook(item):
if isinstance(item, int) and not isinstance(item, bool):
print '0x{0:X} ({0})'.format(item)
elif isinstance(item, long):
print '0x{0:X}L ({0}L)'.format(item)
elif item is not None:
print repr(item)
sys.displayhook = displayhook
@JonathonReinhart
JonathonReinhart / kvm_emulate.md
Created July 27, 2022 04:14
KVM Emulate Flowchart

When does Linux KVM emulate instructions?

Flow Chart

graph LR

x86_emulate_instruction --> x86_emulate_insn
emulate_instruction --> x86_emulate_instruction
#!/usr/bin/env python
import BaseHTTPServer, SimpleHTTPServer
import ssl
import sys
import argparse
ap = argparse.ArgumentParser()
ap.add_argument('--certfile')
ap.add_argument('--keyfile')
ap.add_argument('--port', type=int, default=443)
@JonathonReinhart
JonathonReinhart / Program.cs
Created February 18, 2018 23:12
Gotta catch 'em all: Last-chance exception handling in .NET with WinForms
using System;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using WinformsExceptions;
static class Program
{
/// <summary>
@JonathonReinhart
JonathonReinhart / docker-compose.yml
Last active June 1, 2023 21:39
Mysql docker image: Always run initialization scripts
version: '2'
services:
# MySQL Database
db:
image: mysql:5.6
volumes:
- ./data/mysql:/var/lib/mysql
- ./mysql-entrypoint.sh:/custom-entrypoint.sh:ro
@JonathonReinhart
JonathonReinhart / pipe_client.py
Last active May 23, 2023 23:44
Named Pipes between C# and Python
import time
import struct
f = open(r'\\.\pipe\NPtest', 'r+b', 0)
i = 1
while True:
s = 'Message[{0}]'.format(i).encode('ascii')
i += 1
@JonathonReinhart
JonathonReinhart / ctypes_structs_example.py
Last active November 4, 2022 13:39
Using Python ctypes to manipulate binary data
#!/usr/bin/env python3
from __future__ import print_function
from tempfile import TemporaryFile
from binascii import hexlify
from ctypes import *
class StructHelper(object):
def __get_value_str(self, name, fmt='{}'):
val = getattr(self, name)
@JonathonReinhart
JonathonReinhart / nbdinfo.py
Last active August 23, 2022 06:54
Linux NBD (Network Block Device) info
#!/usr/bin/env python3
# Show Linux NBD (Network Block Device) info
# Requires Python 3.7+
# Author: Jonathon Reinhart
# License: MIT
from dataclasses import dataclass
from pathlib import Path
class NotConnected(Exception):
pass
@JonathonReinhart
JonathonReinhart / hexdump.py
Last active July 23, 2022 00:12 — forked from 7h3rAm/hexdump.py
hexdump implementation in Python
import string
def hexdump(src, length=16, sep='.'):
DISPLAY = string.digits + string.letters + string.punctuation
FILTER = ''.join(((x if x in DISPLAY else '.') for x in map(chr, range(256))))
lines = []
for c in xrange(0, len(src), length):
chars = src[c:c+length]
hex = ' '.join(["%02x" % ord(x) for x in chars])
if len(hex) > 24: