Skip to content

Instantly share code, notes, and snippets.

Avatar

Ferdinand Bachmann Ferdi265

View GitHub Profile
@Ferdi265
Ferdi265 / named_args.h
Last active Aug 2, 2020
C++17 Named Arguments
View named_args.h
#pragma once
#include <type_traits>
#include <utility>
#include <tuple>
#include <optional>
namespace named_args {
// named argument value type
template <typename T, typename K>
@Ferdi265
Ferdi265 / lambda.cpp
Created Jul 2, 2020
Embedded Lambda Calculus in local C++ lambda expression templates
View lambda.cpp
#include <type_traits>
#define LAMBDA(name, value) \
[](auto __t){ \
using name = std::remove_reference_t<decltype(__t)>; \
return value; \
}
#define TYPE_LAMBDA(name, ...) \
[](auto __t){ \
@Ferdi265
Ferdi265 / cursed.cpp
Last active Jul 2, 2020
C++ struct templates in local scope
View cursed.cpp
#include <type_traits>
#define DEFINE_LOCAL_VALUE_TEMPLATE(name, value) \
[](auto __t){ \
using name = std::remove_reference_t<decltype(__t)>; \
return value; \
}
#define DEFINE_LOCAL_TYPE_TEMPLATE(name, ...) \
[](auto __t){ \
@Ferdi265
Ferdi265 / test.cpp
Created Jun 2, 2020
virtual_base_union -- a union class that functions as a smart pointer to a polymorphic type
View test.cpp
#include <iostream>
#include <string>
#include "virtual_base_union.h"
class Screen {
public:
virtual ~Screen() = default;
virtual void draw() = 0;
};
@Ferdi265
Ferdi265 / ignored.md
Last active Oct 16, 2020
GNU ld.so ignored ELF fields
View ignored.md

Fields ignored by GNU ld.so in ELF data structures for shared objects

This file documents which fields can be safely corrupted, overlapped, or filled with code, while still being loadable by GNU ld.so via LD_PRELOAD. Information gathered via experimentation. This list may be incomplete.

A checkmark means this field is ignored, a plus means part of the field is ignored. offsets are in hex.

Elf64_Ehdr:

  • 00-10: e_ident
@Ferdi265
Ferdi265 / golf.so.s
Created Apr 26, 2020
PlaidCTF golf.so challenge - LosFuzzys
View golf.so.s
bits 64
org 0x0
ehdr:
db 0x7f, "ELF" ; e_ident[0:4] = ELFMAG
db 2 ; e_ident[4] = ELFCLASS64
db 1 ; e_ident[5] = ELFDATA2LSB
db 1 ; e_ident[6] = EV_CURRENT
db 0 ; e_ident[7] = ELFOSABI_SYSV
db 0 ; e_ident[8] = EI_ABIVERSION
@Ferdi265
Ferdi265 / cenum.sh
Last active Feb 6, 2019
Script to expand macros and enums from C headers
View cenum.sh
#!/bin/bash
CC=${CC:-gcc}
# check usage
if [[ $# -eq 0 ]]; then
echo "usage: cenum [headers..] ENUM" >&2
exit 1
fi
@Ferdi265
Ferdi265 / cmacro.sh
Created Dec 28, 2018
Script to expand macros from C headers
View cmacro.sh
#!/bin/bash
# check usage
if [[ $# -eq 0 ]]; then
echo "usage: cmacro [headers..] MACRO" >&2
exit 1
fi
# generate temporary file
f=$(mktemp --suffix=.c)
@Ferdi265
Ferdi265 / slidername.html
Created Sep 24, 2018
Name Slider Thingy
View slidername.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Name Slider Thingy</title>
<style type="text/css">
#name {
margin-left: 1em;
}
.content {
@Ferdi265
Ferdi265 / anews.py
Last active Dec 24, 2015
anews - Arch Linux news python script
View anews.py
#!/usr/bin/env python3
import os
import sys
import time
import termcolor
import feedparser
# Usage:
# anews [number of headlines (optional)]
# e.g. "anews 6" or "anews"