Skip to content

Instantly share code, notes, and snippets.

@fay59
fay59 / Key code reader.
Created May 25, 2015 21:29
Key code reader
/*
* Based on keytable.c by Mauro Carvalho Chehab
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@fay59
fay59 / realism.py
Last active September 19, 2017 07:29
Solution to realism.py that uses z3
'''
Solution to the realism challenge from CSAW'17 Quals.
https://github.com/isislab/CSAW-CTF-2017-Quals/tree/master/rev/realism
'''
from z3 import *
s = Solver()
# This is a simplification of the array of bytes found at 0x7D90:
# 0xff => 1, 0x00 => 0; where 1 means "include this value in the psadbw sum"
fn digits_to_vec(digits: String) -> Vec<u32> {
let mut result = Vec::new();
for c in digits.chars() {
match c.to_digit(10) {
Some(v) => result.push(v),
None => {}
}
}
return result;
}
fn digits_to_vec(digits: String) -> Vec<u32> {
let mut result = Vec::new();
for c in digits.chars() {
match c.to_digit(10) {
Some(v) => result.push(v),
None => {}
}
}
return result;
}
@fay59
fay59 / deriv.swift
Last active December 29, 2017 00:19 — forked from jdh30/deriv.swift
Swift code to compute the nth derivative of x^x
precedencegroup ExponentPrecedence {
associativity: right
higherThan: MultiplicationPrecedence
}
infix operator **: ExponentPrecedence
fileprivate enum Expr: CustomStringConvertible {
case Int(n: Int)
indirect case Var(x: String)
@fay59
fay59 / dom_tree.py
Created May 19, 2018 06:42
Finding regions in Python
import networkx as nx
class DominatorTreeNode(object):
__slots__ = ("value", "depth", "parent", "children")
def __init__(self, value):
self.value = value
self.depth = None
self.parent = None
use std::cmp;
fn spiral_distance(num: u32) -> u32 {
let ring = (((num as f64).sqrt() - 1.) / 2.).ceil() as u32;
let root = (num as f64 - 1.).sqrt() as u32;
let offset_to_mid = root / 2;
let ring_min = root * root + 1 + offset_to_mid;
let ring_max = (root + 1) * (root + 1) - offset_to_mid;
return ring + cmp::min(
(num as i32 - ring_min as i32).abs(),
@fay59
fay59 / comments.lex
Created March 14, 2017 21:13
Tiny Flex lexer that skips C-style block comments
%option noyywrap
%x C_COMMENT
%%
"/*" { BEGIN(C_COMMENT); }
<C_COMMENT>"*/" { BEGIN(INITIAL); }
<C_COMMENT>. { }
<C_COMMENT>\n { }
@fay59
fay59 / words.txt
Created June 3, 2015 17:23
English words
This file has been truncated, but you can view the full file.
a
aah
aahed
aahing
aahs
aardvark
aardvarks
aardwolf
ab
abaci
@fay59
fay59 / Quirks of C.md
Last active September 4, 2024 23:07
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;