Instantly share code, notes, and snippets.

View LICENSE
Copyright [year] [fullname]
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the following
conditions are met:
1. The above copyright notice, this list of conditions and the following
disclaimer must appear in all copies.
2. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
View iathook.c
// PageProtectAdjustExecute and VirtualProtectSameExecute are Copyright (c) Microsoft Corporation
// They are originally from Detours, which is MIT licensed
#define PAGE_EXECUTE_ALL (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)
#define PAGE_NO_EXECUTE_ALL (PAGE_NOACCESS | PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY)
#define PAGE_ATTRIBUTES (~(PAGE_EXECUTE_ALL | PAGE_NO_EXECUTE_ALL))
static DWORD PageProtectAdjustExecute(DWORD dwOldProtect, DWORD dwNewProtect)
{
bool const fOldExecute = ((dwOldProtect & PAGE_EXECUTE_ALL) != 0);
View dllmain_avoid_deadlock.c
typedef NTSTATUS(NTAPI *PFN_RTLLEAVECRITICALSECTION)(PRTL_CRITICAL_SECTION);
PFN_RTLLEAVECRITICALSECTION g_pfnRtlLeaveCriticalSection;
__forceinline void acquire_lock(long *lock)
{
while ( InterlockedCompareExchange(lock, 1, 0) )
YieldProcessor();
}
View hex_dump.c
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef _WIN64
#define ui3264toa_s _ui64toa_s
#else
#define ui3264toa_s _ultoa_s
#endif