Skip to content

Instantly share code, notes, and snippets.

@C0deH4cker
C0deH4cker / printsegs.c
Created January 15, 2015 20:52
Example for parsing a mach-o using the ITERCMDS macro (best thing ever!)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <mach-o/loader.h>
/* Get the next load command from the current one */
@C0deH4cker
C0deH4cker / thread_local_lldb.c
Created June 26, 2016 08:16
Sample source file exhibiting incorrect debug info within Xcode
#include <stdio.h>
// Even making the pointer volatile doesn't help
__thread int* tl_ptr;
int main(void) {
int x = 0xDEAD;
// Put a breakpoint on the following line
tl_ptr = &x;
@C0deH4cker
C0deH4cker / sierpinski.cpp
Created January 18, 2014 04:05
Solution to a problem from a local programming contest.
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
struct Block {
vector<vector<bool> > grid;
int size;
@C0deH4cker
C0deH4cker / savevid.py
Last active January 1, 2016 07:09
Run this on a Mac with an iPhone plugged in and then view a video snap. It will be saved to the current directory. To stop, press Control-C. Requires iFuse. Works without a jailbreak. Clearly not affiliated with Snapchat in any way.
#!/usr/bin/env python
import sys, os
import subprocess
from shutil import copyfile
def main():
mnt = os.path.expanduser("~/mnt")
snap = mnt + "/snapchat"
@C0deH4cker
C0deH4cker / destroy.h
Created November 14, 2015 05:36
Safer way to free a variable in C
#include <stdlib.h>
/*! Frees the pointer pointed to by the parameter and then sets it to NULL */
#define destroy(pptr) do { \
__typeof__(*(pptr)) volatile* _pptr = (pptr); \
if(!_pptr) { \
break; \
} \
free(*_pptr); \
*_pptr = NULL; \
@C0deH4cker
C0deH4cker / wordshift.cpp
Created February 11, 2015 21:18
Determine all possible valid words that can be formed by shifting a valid word by one on a keyboard
//
// wordshift.cpp
// WordShift
//
// Created by C0deH4cker on 2/11/15.
// Copyright (c) 2015 C0deH4cker. All rights reserved.
//
#include <iostream>
#include <fstream>
@C0deH4cker
C0deH4cker / 2d.fsn
Last active August 29, 2015 13:56
Various programs in the Fission programming language
R'Hello, di'\
+'!snoisnem'/
O.........../