Skip to content

Instantly share code, notes, and snippets.

@Barakat
Barakat / iat-hook.cpp
Last active July 22, 2018 10:41
Import Address Table hook
// مثال لخطف دالة عن طريق استبدال عنوانها في جدول عناوين الدوال المستوردة
// https://twitter.com/barakatsoror/status/1020710139475759105
#include <Windows.h>
#include <winternl.h>
#include <cstdio>
#include <cassert>
#include <winnt.h>
#include <cstring>
#include <cwchar>
@Barakat
Barakat / injector.cpp
Created July 13, 2018 20:08
DLL Injection via CreateRemoteThread
// أداة الحقن
#include <Windows.h>
#include <cassert>
int
main(int argc, char** argv)
{
(void)argc;
(void)argv;
#include <Windows.h>
#include <cassert>
int
main(int argc, char **argv)
{
(void)argc;
(void)argv;
// التعليمات مولّدة من هذا الكود:
@Barakat
Barakat / ascii_upper_encoder.py
Created June 27, 2018 19:30
Encode binary data into uppercase-only ASCII
ASCII_A_CODE = ord('A')
def ascii_upper_encode(data):
code = ''
for byte in data:
code += chr((byte >> 4) + ASCII_A_CODE)
code += chr((byte & 0xf) + ASCII_A_CODE)
return code
def ascii_upper_decode(code):
@Barakat
Barakat / CMakeLists.txt
Last active October 14, 2023 22:36
Minimal Objective-C++ SDL2 + Metal example
# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(example)
set(CMAKE_CXX_STANDARD 11)
find_package(SDL2 REQUIRED)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_COMPILER_IS_CLANGCXX 1)
endif ()
@Barakat
Barakat / mini.kt
Last active June 6, 2017 00:34
Mini-programming language in pure-Kotlin
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.io.PrintStream
import java.util.*
import java.util.concurrent.Callable
enum class Token constructor(val symbol: String) {
IF("if"),
ELSE("else"),
@Barakat
Barakat / ean13-checksum.py
Created February 27, 2017 10:50
Compute the checksum of EAN-13 barcodes
def compute_ean13_checksum(barcode):
assert len(barcode) == 12 and barcode.isdigit()
return (10 - sum(int(i) * j for i, j in zip(barcode, (1, 3) * 6)) % 10) % 10
@Barakat
Barakat / matrix.c
Created December 15, 2016 10:39
Cache optimized serial matrix multiplication
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
typedef struct {
size_t rows;
size_t columns;
@Barakat
Barakat / DebugMessageCallback.cpp
Created July 10, 2016 06:00
An implementation of glDebugMessageCallbackARB callback
#include <gl/glew.h>
#include <string>
void GLAPIENTRY DebugMessageCallback(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const void* userParam)
@Barakat
Barakat / caesar.py
Last active September 3, 2015 03:44
Caesar cipher implementation in Python
def caesar_enc(plain, key):
plain = plain.encode('utf-8')
cipher = bytearray(plain)
for i, c in enumerate(plain):
cipher[i] = (c + key) & 0xff
return bytes(cipher)
def caesar_dec(cipher, key):
plain = bytearray(len(cipher)) # at most, len(plain) <= len(cipher)
for i, c in enumerate(cipher):