Skip to content

Instantly share code, notes, and snippets.

View mbs0221's full-sized avatar
🏠
Working

Benshan Mei mbs0221

🏠
Working
View GitHub Profile
@xjdrew
xjdrew / nanosleep.c
Created August 20, 2018 07:31
nanosleep resolution
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define ONE_SECOND 1000000000L
#define ONE_MS 1000000L
@will
will / metldown.c
Last active September 5, 2023 16:39
// copied from https://github.com/gkaindl/meltdown-poc/blob/master/meltdown.c
// flush_reload from https://github.com/defuse/flush-reload-attacks
// TSX from https://github.com/andikleen/tsx-tools
// dump_hex from https://gist.github.com/ccbrown/9722406
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
@ErikAugust
ErikAugust / spectre.c
Last active October 7, 2025 15:37
Spectre example code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
/* Simple PT dumper */
/*
* Copyright (c) 2015, Intel Corporation
* Author: Andi Kleen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
@liyang85105
liyang85105 / print_macro.cc
Created August 15, 2017 03:14
print macro(#define macro ...)'s value when using gcc/g++
/* Some test definition here */
#define DEFINED_BUT_NO_VALUE
#define DEFINED_INT 3
#define DEFINED_STR "ABC"
/* definition to expand macro then apply to pragma message */
#define VALUE_TO_STRING(x) #x
#define VALUE(x) VALUE_TO_STRING(x)
#define VAR_NAME_VALUE(var) #var "=" VALUE(var)
@apsun
apsun / hax.c
Last active November 13, 2025 03:35
Hook main() using LD_PRELOAD
/*
* Hook main() using LD_PRELOAD, because why not?
* Obviously, this code is not portable. Use at your own risk.
*
* Compile using 'gcc hax.c -o hax.so -fPIC -shared -ldl'
* Then run your program as 'LD_PRELOAD=$PWD/hax.so ./a.out'
*/
#define _GNU_SOURCE
#include <stdio.h>
@penafieljlm
penafieljlm / cissp_notes.md
Last active January 17, 2026 03:29
Personal CISSP Study Notes

CISSP Notes

CIA Triad

  • Confidentiality
    • Resources should be protected from unauthorized access
    • Prioritized by governments
    • Concepts
      • Sensitivity
        • How harmful is disclosure
  • Discretion
% perf stat ./tsx_per_core
Aborts: 73381
No reason: 57535
reason 0: 0
reason 1: 15833
reason 2: 15833
reason 3: 13
reason 4: 0
reason 5: 0
81597398 68933303 85476712 72654716 76819140 72119787 77728188 74167801 75244800 72119632 75951739 72606078 74035109 70998737 89185152 58165171 86098994 83338241 88201758 81982602 77964219 77861602 75642915 79207346 73514808 79929374 74429694 71508632 0 0 0 0
@george-hawkins
george-hawkins / arm64.md
Last active May 27, 2025 15:47
Running virtualized x86_64 and emulated arm64 Ubuntu cloud images using QEMU

QEMU arm64 cloud server emulation

This is basically a rehash of an original post on CNXSoft - all credit (particularly for the Virtio device arguments used below) belongs to the author of that piece.

Download the latest uefi1.img image. E.g. ubuntu-16.04-server-cloudimg-arm64-uefi1.img from https://cloud-images.ubuntu.com/releases/16.04/release/

Download the UEFI firmware image QEMU_EFI.fd from https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/

Determine your current username and get your current ssh public key:

Activation Key: 54703-98224-69173-57729-64687
File Installation Key: 60915-54893-59227-06046-00879-23758-40953-46389-00580-22272-43569-01202-13854