Skip to content

Instantly share code, notes, and snippets.

View colematt's full-sized avatar
:shipit:
Secret Squirrel

Matthew Cole colematt

:shipit:
Secret Squirrel
View GitHub Profile
@colematt
colematt / dictionary.py
Last active March 29, 2023 18:04
Download a wordlist file from a remote server.
#!/usr/bin/python3
import urllib.request
from urllib.error import URLError
from string import whitespace
# Fetch a wordlist
try:
data = urllib.request.urlopen("https://raw.githubusercontent.com/colematt/english-words/master/words_alpha.txt")
wordlist = list(word.decode("utf-8").lower().rstrip(whitespace) for word in data.readlines())
@colematt
colematt / .Detect C or C++ Standard from Predefined Macros.md
Last active February 2, 2021 20:31
[Detect C or C++ Standard from Predefined Macros] #c #cpp
@colematt
colematt / MyPass.cpp
Last active September 18, 2024 11:05
[Writing an LLVM Pass] #llvm
//===- MyPass.cpp - Example pass ----------------*- C++ -*-===//
#define DEBUG_TYPE "mypass"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
@colematt
colematt / Disable-Yama-Ptrace-Restrictions.md
Last active November 7, 2019 21:29
[Disable Yama PTrace Restrictions] #intel #Pin #Linux

Why would you want to do this?

There is a known problem of using Intel® SDE on Linux* systems that prevents the use of ptrace attach via the sysctl /proc/sys/kernel/yama/ptrace_scope. In this case Pin is not able to use its default (parent) injection mode. (SDE does not need to run as root.)

How do you do it?

The following commands disable yama on the system until the next reboot. Add to the init scripts to make permanent.

This command is recommended by the Intel SDE installation guide, but doesn't work on after Ubuntu 14.04 because the directory doesn't exist:

@colematt
colematt / .Adding-Attributes-to-LLVM.md
Last active August 21, 2025 20:57
[Adding Attributes to LLVM] #llvm

Introduction

This post describes how to add a custom attribute to LLVM and Clang. Why would you want to do such a thing?

  • You have semantic information of which the front-end is aware, but the back-end discards in the Intermediate Representation (IR), and an existing attribute can't be used to retain this information. Adding the attribute using the front-end analysis preserves the information into the back-end generated IR.
  • You've considered using the GCC/LLVM annotate attribute to hold arbitrary strings, but you also need to add a parameter (or more!) to that annotation.

The Clang Internals Manual discusses how to do this, but not with the detail you might like to see. Its description is high-level, and only lists one file that needs to be modified. Tracking down all of the other files that must be changed is left as a frustrating exercise to the reader.

Conventions used i

@colematt
colematt / .Generating-Entropy-for-Keys.md
Last active November 12, 2019 20:10
[Generating Entropy for Keys] #linux

Introduction

Did you get this error message?

We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 210 more bytes)

How much entropy do I actually have?

cat /proc/sys/kernel/random/entropy_avail
@colematt
colematt / Makefile
Last active September 11, 2024 19:53
Using the LLVM Junk Drawer
CC=/usr/bin/clang
CFLAGS=-g -Wall
%.bc:%.c
$(CC) -c -emit-llvm $^ -o $@
%.ll:%.c
$(CC) -S -emit-llvm $^ -o $@
factorial: factorial.c main.c
@colematt
colematt / classroom-clone.sh
Created February 25, 2020 17:06
GitHub Classroom Scripts
#!/bin/bash
# This file is for cloning assignments made in GitHub Classroom into the
# present working directory.
# USAGE
# This script accepts the following command line arguments:
# $1 - the name of the github classroom (e.g. "bucs220")
# $2 - the assignment's prefix before the username MINUS a trailing hyphen (e.g. "F17-A1")
# $3 - the name of the file with a list of repository owners (either individual users or groups).
@colematt
colematt / benchmark.py
Created March 12, 2020 22:11
Using reduce and lambda isn't faster than built-in max!
#!/usr/bin/python3
import random
import functools
import timeit
# Construct a large list of integers with few repeats expected
random.seed()
randints = [random.randint(0,100000000) for _ in range(1000000)]