Skip to content

Instantly share code, notes, and snippets.

View markhc's full-sized avatar
🏠
Working from home

markhc markhc

🏠
Working from home
  • Brazil
View GitHub Profile
NTSTATUS enumerate_handles(ENUM_HANDLE_CALLBACK callback)
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
PVOID buffer = NULL;
ULONG bufferSize = 0;
do {
status = NtQuerySystemInformation((SYSTEM_INFORMATION_CLASS)16/*SystemHandleInformation*/, buffer, bufferSize, &bufferSize);
if(!NT_SUCCESS(status)) {
if(status == STATUS_INFO_LENGTH_MISMATCH) {
HANDLE get_handle_to_process(LPWSTR process)
{
HANDLE hProcess = NULL;
enumerate_handles([&](PSYSTEM_HANDLE_TABLE_ENTRY_INFO handle) {
if(GetCurrentProcessId() != handle->UniqueProcessId) return STATUS_UNSUCCESSFUL;
BOOL found = FALSE;
PVOID buffer = NULL;
@markhc
markhc / uc.css
Last active September 25, 2016 03:19
*.yazzn {
box-sizing: border-box;
}
@media screen and (min-width: 999px) {
code.hljs.javascript {
border-radius: 5px;
max-width: 640px;
max-width: calc(100vw - 347px);
max-height: 700px;
@markhc
markhc / vec.hpp
Last active September 17, 2017 15:52
#pragma once
#include <cstdint>
#include <array>
#include <string>
template<typename T, uint32_t D>
class vec
{
public:
NTSTATUS KapFindKernelPattern(
_In_ PUCHAR Pattern,
_In_ PUCHAR Mask,
_In_ ULONG PatternLength,
_Out_ PVOID* Result
)
{
PIMAGE_NT_HEADERS NtHeaders;
PIMAGE_SECTION_HEADER FirstSection;
@markhc
markhc / Lexer.cpp
Last active June 6, 2019 18:56
Lexer code
#include "Lexer.hpp"
namespace sage
{
namespace detail
{
// ----------------------------------------------------------------------------
inline char getCharAndAdvance(const char*& ptr)
{
return *ptr++;
#include "SafeHandles/SafeHandle.hpp"
#include "windows.hpp"
class SafeFileHandle //
: public SafeHandle<INVALID_HANDLE_VALUE> //
{
public:
SafeFileHandle(void* handle)
: SafeHandle(handle, &SafeFileHandle::deleter)
@markhc
markhc / CMakeLists.txt
Last active July 16, 2019 13:10
fmtlib + cmake
cmake_minimum_required (VERSION 3.12)
# not strictly needed, but it helps when you forget to pass the CMAKE_TOOLCHAIN_FILE as argument to cmake
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
project(cmake_example CXX)
std::string Board::prettyPrint(bool useUnicodeChars) const
{
std::string_view charPieces[2][6] = {
{
useUnicodeChars ? "\u2659" : "P",
useUnicodeChars ? "\u2657" : "B",
useUnicodeChars ? "\u2658" : "N",
useUnicodeChars ? "\u2656" : "R",
useUnicodeChars ? "\u2655" : "Q",
useUnicodeChars ? "\u2654" : "K",
void fail(beast::error_code ec, char const* what)
{
// TODO: Better error logging
std::cerr << what << ": " << ec.message() << "\n";
}
// -------------------------------------------------------------------------------------------------
Gateway::Gateway(net::io_context& ioc, ssl::context& ctx)
: ws_(net::make_strand(ioc), ctx),
resolver_(net::make_strand(ioc)),
host_("gateway.discord.gg"s),