Skip to content

Instantly share code, notes, and snippets.

View JonathonReinhart's full-sized avatar

Jonathon Reinhart JonathonReinhart

View GitHub Profile
@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:
Windows (PowerShell) (DER format):
Invoke-WebRequest -UseBasicParsing http://example.com/example.cer -OutFile example.cer
certutil.exe -addStore "Root" example.cer
Debian 8 (PEM format):
# wget -O /usr/local/share/ca-certificates/example.crt http://example.com/example.cer
# update-ca-certificates
#!/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 / vimstrace
Created July 28, 2016 14:56
Vim frontend to strace
#!/bin/sh
# Using Vim to view strace output
strace -o'!vim -R -' "$@"
@JonathonReinhart
JonathonReinhart / sample_output
Created July 29, 2016 15:12
Show Ethernet drivers on Linux
$ ~/what_eth_drivers.sh
eth0 [52:54:00:aa:bb:cc]: virtio_net (up)
eth1 [52:54:00:dd:ee:ff]: virtio_net (up)
eth2 [52:54:00:99:88:77]: virtio_net (up)
lo [00:00:00:00:00:00]: (unknown)
@JonathonReinhart
JonathonReinhart / a.h
Created October 15, 2016 23:08
Circular includes
#ifndef A_DOT_H_INCLUDED
#define A_DOT_H_INCLUDED
#include "b.h"
struct a
{
struct b *b;
};
@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 / search.c
Created March 14, 2017 20:13
Places "goto" can improve C code
void *search_without_goto(const char *key)
{
int i;
void *result;
for (i = 0; i < some_length; i++) {
if (strcmp(some_collection[i].key, key) == 0)
break;
}
if (i == some_length)
@JonathonReinhart
JonathonReinhart / 20171128_radeon_lockup.txt
Created November 29, 2017 03:06
Radeon driver lockup
Nov 28 21:24:06.432882 kernel: radeon 0000:01:00.0: ring 0 stalled for more than 10092msec
Nov 28 21:24:06.441917 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x0000000001ff9744 last fence id 0x0000000001ff9755 on ring 0)
Nov 28 21:24:06.455092 kernel: radeon 0000:01:00.0: ring 4 stalled for more than 10104msec
Nov 28 21:24:06.455374 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x000000000100a400 last fence id 0x000000000100a401 on ring 4)
Nov 28 21:24:06.655161 kernel: radeon 0000:01:00.0: ring 3 stalled for more than 10080msec
Nov 28 21:24:06.655451 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x0000000000d334fd last fence id 0x0000000000d3350e on ring 3)
Nov 28 21:24:06.935108 kernel: radeon 0000:01:00.0: ring 0 stalled for more than 10596msec
Nov 28 21:24:06.935390 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x0000000001ff9744 last fence id 0x0000000001ff9755 on ring 0)
Nov 28 21:24:06.959090 kernel: radeon 0000:01:00.0: ring 4 stalled for more than 106
@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)