Skip to content

Instantly share code, notes, and snippets.

@C0deH4cker
C0deH4cker / hungman.py
Created July 31, 2019 02:23
Exploit for [PWN 300] Hungman from CSAW CTF Quals 2016
#!/usr/bin/env python
from pwn import *
import sys
debug_server = False
use_system_libc = True
r = remote("pwn.chal.csaw.io", 8003); use_system_libc = False
# r = process("./hungman")
# r = process("./linux_serverx64"); debug_server = True
@C0deH4cker
C0deH4cker / this_is_bad.c
Created February 2, 2018 05:18
This is bad
/* THIS IS VERY BAD */
#define CONCAT(a, b) CONCAT_(a, b)
#define CONCAT_(a, b) a##b
#define THIS_IS_BAD(test, first, rest, cond, body...) THIS_IS_BAD_2(__COUNTER__, test, first, rest, cond, ##body)
#define THIS_IS_BAD_2(uniq, test, first, rest, cond, body...) THIS_IS_BAD_3(CONCAT(this_is_bad_, uniq), test, first, rest, cond, ##body)
#define THIS_IS_BAD_3(label, test, first, rest, cond, body...) do { \
if(test) { \
first(); \
@C0deH4cker
C0deH4cker / crash.swift
Created February 5, 2017 08:45
Crash the swift interpreter by entering the first part, followed by entering the second part. Must be separate copy/pastes!
// Part 1
extension UInt {
public init(bytes: Bytes) {
self = 0
for byte in bytes {
self <<= 8
self |= UInt(byte)
}
}
}
@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 / syms.c
Created March 20, 2016 03:21
Prints out the name, type, and value of every symbol in a Mach-O file, similar to nm.
//
// main.c
// macho-syms
//
// Created by C0deH4cker on 3/19/16.
// Copyright © 2016 C0deH4cker. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@C0deH4cker
C0deH4cker / keybase.md
Last active March 2, 2017 12:12
Keybase.io GitHub Verification

Keybase proof

I hereby claim:

  • I am c0deh4cker on github.
  • I am c0deh4cker (https://keybase.io/c0deh4cker) on keybase.
  • I have a public key ASDAYDYtqJGjVHyfmEJDXA3gw4geCBLvgpynNHx7M2t1Wgo

To claim this, I am signing this object:

@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 / patternhooker.c
Last active January 19, 2022 02:04
Example of hooking a function from a Substrate tweak by searching for a byte pattern in the app's code segments. UNTESTED CODE
//
// patternhooker.c
// PatternHooker
//
// Finds a function by searching for a byte pattern and hooks it with CydiaSubstrate.
//
// Created by C0deH4cker on 7/26/15.
// Copyright (c) 2015 C0deH4cker. All rights reserved.
//
@C0deH4cker
C0deH4cker / with.h
Created June 10, 2015 08:34
Python's with statement, implemented in C++ via macros
// Just like C#'s using statement and Python's with statement.
// This allows use of a resource within a code block, after which
// the declared object's destructor will clean up.
// There's nothing about `with` that doesn't work in C, but it is
// pointless in standard C as there are no destructors.
// Multiple with statements can be nested as well, so it works as
// you'd expect. If for some bizarre reason you need to put multiple
// using statements on the same line, I've added another version,
// defined below as with_inline.
//
@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>