This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sys/stat.h> | |
int main (int /*argc*/, char* argv[]) | |
{ | |
struct stat fileInfo; | |
if (stat (argv[1], &fileInfo) == 0) { | |
std::cout << "The file's size is: " << fileInfo.st_size << | |
" bytes" << std::endl; | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <process.h> | |
#include <windows.h> | |
CRITICAL_SECTION g_cs; | |
static unsigned int ThreadMain (void* /*context*/) | |
{ | |
EnterCriticalSection (&g_cs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ntifs.h> | |
#include <ntddk.h> | |
#include <ntstrsafe.h> | |
#define MFTPF_DEV_SYMLINK_NAME L"MFTPrefetch" | |
#define MFTPF_DEVICE 0x8000 | |
#define IOCTL_MFTPF_PREFETCH_MFT CTL_CODE (MFTPF_DEVICE, 0x800, METHOD_NEITHER, FILE_ANY_ACCESS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with MSVC. Target x86, then target x64. | |
// See what happens (run without a debugger attached). | |
#include <cstdint> | |
#include <iostream> | |
#include <windows.h> | |
LONG WINAPI MyUEF (PEXCEPTION_POINTERS pExp) | |
{ | |
std::cout << "Unhandled exception with code " << std::hex << | |
pExp->ExceptionRecord->ExceptionCode << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <werapi.h> | |
extern "C" { | |
__declspec(dllexport) HRESULT WINAPI OutOfProcessExceptionEventCallback ( | |
PVOID /*pContext*/, | |
const PWER_RUNTIME_EXCEPTION_INFORMATION /*pExceptionInformation*/, | |
BOOL* pbOwnershipClaimed, | |
PWSTR pwszEventName, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with MSVC. | |
#include <windows.h> | |
#include <winnt.h> | |
#include <cstdio> | |
#pragma warning(disable:4717) | |
LONG WINAPI StackOverflowHandler (PEXCEPTION_POINTERS pExp) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size_t __chkstk (size_t stackSpaceSize) | |
{ | |
// Calculate what the stack pointer would be, if the caller of | |
// __chkstk simply made its stack allocation instead of | |
// calling __chkstk. | |
// | |
// 0x18: 0x10 for 2 saved registers (used by __chkstk), plus | |
// 0x8 for the saved return address (__chkstk was call'd) | |
uintptr_t adjustedSP = __rsp + 0x18 - stackSpaceSize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ... */ | |
PEXCEPTION_RECORDS pExc = __rax; | |
if (pExc->ExceptionCode == EXCEPTION_STACK_OVERFLOW || | |
(pExc->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && | |
pExc.ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT)) | |
{ | |
return E_NOTIMPL; | |
} | |
/* ... */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with MSVC, *Release* configuration | |
#include <iostream> | |
#include <new> | |
#include <windows.h> | |
LONG WINAPI MyUEF (PEXCEPTION_POINTERS pExp) | |
{ | |
if (pExp->ExceptionRecord->ExceptionCode == STATUS_HEAP_CORRUPTION) { | |
std::cout << "Heap corruption detected!" << std::endl; |
OlderNewer