Skip to content

Instantly share code, notes, and snippets.

View pps83's full-sized avatar

Pavel P pps83

View GitHub Profile
#ifdef _WIN32 // inet_pton is available from Vista only (based on inet_pton.c from wireshark)
#define NS_INADDRSZ_ 4
#define NS_IN6ADDRSZ_ 16
#define NS_INT16SZ_ 2
static int inet_pton4(const char *src, unsigned char *dst)
{
char saw_digit = 0, octets = 0, ch;
unsigned char tmp[NS_INADDRSZ_], *tp = tmp;
@pps83
pps83 / DoSuspendThread.cpp
Created February 15, 2018 21:31
suspend threads in the current process
#include <windows.h>
#include <tlhelp32.h>
// Pass 0 as the targetProcessId to suspend threads in the current process
void DoSuspendThread(DWORD targetProcessId, DWORD targetThreadId)
{
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (h != INVALID_HANDLE_VALUE)
{
THREADENTRY32 te;
@pps83
pps83 / WriteMinidumpForException.cpp
Last active February 7, 2018 07:11
WriteMinidumpForException
#include <Windows.h>
#include <stdio.h>
// fullDump enables MiniDumpWithFullMemory, and results in dmp files to be over 100MB in size (as opposed to default which is only 100KB).
// With fullDump Visual Studio is able to display proper backtrace for unhandled c++ exception. Without fullDump WinDBG has to be used.
static int WriteMinidumpForException(EXCEPTION_POINTERS* e, bool fullDump)
{
HMODULE dbghelp = LoadLibraryA("DbgHelp.dll"); // Note: no matching FreeLibrary
if (!dbghelp)
return EXCEPTION_CONTINUE_SEARCH;