Skip to content

Instantly share code, notes, and snippets.

View mbs0221's full-sized avatar
🏠
Working

Benshan Mei mbs0221

🏠
Working
View GitHub Profile
@browny
browny / simple_socket_example.c
Last active April 21, 2026 22:21
simple socket example in C
/* --- Usage --- */
g++ server.c -o server
g++ client.c -o client
./server
./client 127.0.0.1
/* --- server.c --- */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@tonyseek
tonyseek / README.rst
Last active August 16, 2025 15:57
Build Python binding of C++ library with cffi (PyPy/Py3K compatible)

Run with Python:

pip-2.7 install cffi
PYTHON=python2.7 sh go.sh

Run with PyPy:

pip-pypy install cffi
PYTHON=pypy sh go.sh
@itarato
itarato / encryption.java
Created September 28, 2014 18:59
Java AES CBC encryption example
package com.company;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest;
import java.security.SecureRandom;
public class Main {
@rindeal
rindeal / cpuid-dump.c
Last active December 26, 2024 16:58
CPUID dumper
#if !defined(__GNUC__) || ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800)
# error "This program requires GNU C compiler v4.8+!"
#endif
#include <stdio.h>
#include <stdbool.h>
#define PRINT_TEST_CPU_SUPPORT_RESULT(inst) printf("\t%-7s: %d\n", inst, __builtin_cpu_supports(inst)?1:0)
#define PRINT_TEST_CPU_TYPE_RESULT(inst) printf("\t%-12s: %d\n", inst, __builtin_cpu_is(inst)?1:0)
@ytakano
ytakano / rtm_test.c
Created April 10, 2015 10:32
Intel TSX RTM
#include <stdio.h>
int main()
{
volatile int i = 0;
while (i < 100000000) {
asm ("xbegin ABORT");
i++;
asm ("xend");
asm ("ABORT:");
@envy
envy / sgx_avail.c
Created August 14, 2015 13:39
Check SGX availability
#include <stdio.h>
/*
* This program checks SGX availability by checking CPUID
* Relevant spec sections: 1.7 (and 1.7.1 and 1.7.2)
* 2015-08-14 Nico Weichbrodt
*/
/*
* Helper function for CPUID querying
@bellbind
bellbind / avxvec.c
Last active February 21, 2025 04:41
[c][avx][simd]example for intel SSE/AVX intrinsic api
// clang -std=c11 -mavx avxvec.c -o avxvec
#include <x86intrin.h>
#include <stdio.h>
// see https://software.intel.com/sites/landingpage/IntrinsicsGuide/#techs=AVX
int main() {
double mem[4] = {1.0, 2.0, 3.0, 4.0};
//__m256d v = _mm256_load_pd(mem);
__m256d v = _mm256_set_pd(1, 2, 3, 4); // (e3, e2, e1, e1)
__m256d sq = _mm256_mul_pd(v, v);
@retrography
retrography / annotex.py
Last active November 20, 2024 14:45
PDF highlight and annotation extractor
#!/usr/bin/env python
__author__ = 'Mahmood S. Zargar'
import poppler
import sys
import urllib
import os
def main():
@kinichiro
kinichiro / 1_Hello_libtls
Last active May 6, 2025 23:23
Hello libtls - libressl libtls API sample program
Hello libtls - libressl libtls API sample program
@mayanez
mayanez / Makefile
Last active November 20, 2024 13:54
Simple ROP Exploit Example (x86)
simple-rop: simple-rop.c
gcc -m32 -O0 -g -static -fno-stack-protector $^ -o $@
.PHONY: clean
clean:
rm -rf simple-rop