This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2016 Adrien Guinet | |
// Helper templates to easily check whether a function type has the right | |
// signature (without std::function). | |
// If you have std::function, simply do | |
// | |
// template <class F, class R, class... Args> | |
// struct has_sign: | |
// public std::is_convertible<F, std::function<R(Args...)>> | |
// { }; | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import llvmlite.ir as ll | |
module = ll.Module() | |
Int64 = ll.IntType(64) | |
fntype = ll.FunctionType(ll.VoidType(), []) | |
func = ll.Function(module, fntype, name='foo') | |
BB = func.append_basic_block() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The idea is to statically create a list of initializers that would be | |
// launched when the "user" wants. This question has been asked by @lapinhib0u | |
// for the shell-factory project (https://github.com/gdelugre/shell-factory). | |
// The idea is that some classes might define initializers that needs to be | |
// launched at the beggining of the shell code, and each class might define | |
// whether it needs such initializer or not. Even if the whole code ends up in | |
// one compilation unit in the end, the construction of the initializer list is | |
// splitted accross various include files. | |
// | |
// Here is below one implementation of this that uses the __COUNTER__ macro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <cstdio> | |
template <class Array, class F, class Seq> | |
struct map_impl; | |
template <class Array, class F, size_t... I> | |
struct map_impl<Array, F, std::index_sequence<I...>> | |
{ | |
template <class... Args> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include "targetver.h" | |
#include <stdio.h> | |
#include <tchar.h> | |
#include <Windows.h> | |
#include <Wincrypt.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import pydffi | |
import llvmlite.ir as ll | |
FFI = pydffi.FFI() | |
CU = FFI.cdef(''' | |
#include <stdbool.h> | |
typedef struct { | |
bool b; | |
int i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <inttypes.h> | |
#define CST 11246805480246805480ULL | |
static uint64_t load64_le(uint8_t const* V) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdlib.h> | |
uint32_t crc32b(uint8_t* data, size_t len) { | |
uint32_t crc = 0xFFFFFFFF; | |
for (size_t i = 0; i < len; ++i) { | |
const uint8_t v = data[i]; | |
crc ^= v; | |
for (size_t j = 0; j < 8; ++j) { | |
const uint32_t bit = crc & 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extracted from https://github.com/pyjamask-cipher/pyjamask-reference-implementation/blob/master/pyjamask.c | |
#include <cstdint> | |
#define right_rotate(row) \ | |
row = (row >> 1) | (row << 31); | |
#define COL_M0 0xa3861085 | |
#define COL_M1 0x63417021 | |
#define COL_M2 0x692cf280 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
static uintptr_t sign_pointer_a(uintptr_t ptr, uint64_t ctx) { | |
__asm__ ("pacia %0, %1" : "+r" (ptr) : "r" (ctx) ); | |
return ptr; | |
} | |
static uintptr_t auth_pointer_a(uintptr_t ptr, uint64_t ctx) { | |
__asm__ ("autia %0, %1" : "+r" (ptr) : "r" (ctx) ); |