Handling C++ & __try exceptions without the need of built-in handlers.

Overview

manual_exception_handling

this handles exceptions inside the module its specified to manage without needing previous handlers for the exception a good use case would be using this inside a manually mapped module

IMPORTANT
as a manually mapped module, if you remain inside a module that already has exception handling you will have to
run memory::remove_inverted_func_table() with the parameter being the base address of the module with exception handling in order
to allow you to get exception handling

WHY THIS WORKS - __try & __except
reversed by BlackBone's dev DarthTon he found that by placing your module inside the global LdrpInvertedFunctionTable you can obtain
exception handling without having to handle it inside VEH, however i made sure this was the case by placing VEH that would go through
the handlers of the module told to be handled by memory::enable_exceptions and determine if there is a handler for the exception
being sent to the VEH

i took hints from the ehdata.h file and some basic memory research to see how gathering all the necessary information for the loop
to be successful, heres a simple breakdown of what it does:

exception_table[i] -> unwind_info -> frame_count & exception_data_ptr -> (exception address inside handler) && (is a Exception HANDLER or a Unhandled HANDLER) ->
frames[ii] -> exception_frame_offset -> exception_frame & frame_start_offset & frame_end_offset -> (exception address inside frame) ->
SetLastError & jmp to exception_frame

WHY THIS WORKS - c++
this wasn't very reversed or looked into by people but without the extra details ill just go directly into why this works
i place an IAT (Import Address Table) hook on RaiseException which is called to handle c++ exceptions, the function that does is called
__CxxThrowException and can be found under the symbols for any compiled module, this function is called with the same exception that
can be used to identify c++ exceptions in the VEH and this exception code can be found under the definition EH_EXCEPTION_NUMBER which is
inside ehdata.h

by using this i can go through the call stack of RaiseException and, making sure to check the callstack is for the most recent exception, i
can see if any of the functions in the callstack have a handler by going through the exception_table, after checking if there is a handler
i then call the language_handler discovered by looking for the function entry via RtlLookupFunctionEntry as well as RtlVirtualUnwind
after all of this is done i call the language handler to make sure it does get called and handles the exception properly, even if the c++
exception handling code fails

call_stack[i] -> exception_table[ii] -> unwind_info -> (exception address inside handler) && (is a Exception HANDLER or a Unhandled HANDLER) ->
function_entry & handler_data & establisher_frame & language_handler -> return language_handler(necessary data)

FINAL NOTES
this should work for any exceptions inside the current module, but this is untested to work with exceptions coming from exterior modules that should be handled
inside this module, ex. calling a function that triggers __except and should be handled inside the current module
You might also like...
A tool to collect the exceptions that can reach a C++ function

Exceptions Reporter This tool tries to answer this r/cpp question for a tool to find out, for a given function in my code base, which exceptions it ma

GlslViewer is a flexible console-base OpenGL Sandbox to display 2D/3D GLSL shaders without the need of an UI
GlslViewer is a flexible console-base OpenGL Sandbox to display 2D/3D GLSL shaders without the need of an UI

GlslViewer is a flexible console-base OpenGL Sandbox to display 2D/3D GLSL shaders without the need of an UI

This is a software renderer for Dear ImGui. I built it not out of a specific need, but because it was fun
This is a software renderer for Dear ImGui. I built it not out of a specific need, but because it was fun

Dear ImGui software renderer This is a software renderer for Dear ImGui. I built it not out of a specific need, but because it was fun. The goal was t

BakePKG is a package archive that can install itself without without a package manager.

BakePKG A bad way of packaging applications. Introduction BakePKG is a package archive that can install itself without without a package manager. The

Qt without moc: set of macros to use Qt without needing moc

About This (header-only) library can be used to create an application using Qt, without the need of the moc (MetaObject Compiler). It uses a different

:hocho: Strictly RFC 3986 compliant URI parsing and handling library written in C89; moved from SourceForge to GitHub

uriparser uriparser is a strictly RFC 3986 compliant URI parsing and handling library written in C89 ("ANSI C"). uriparser is cross-platform, fast, su

Epoxy is a library for handling OpenGL function pointer management for you

Epoxy is a library for handling OpenGL function pointer management for you. It hides the complexity of dlopen(), dlsym(), glXGetProcAddress(), eglGetP

Epoxy is a library for handling OpenGL function pointer management for you

Epoxy is a library for handling OpenGL function pointer management for you. It hides the complexity of dlopen(), dlsym(), glXGetProcAddress(), eglGetP

Dear IMGUI + Render + Window handling, amalgamation in two files ready to use
Dear IMGUI + Render + Window handling, amalgamation in two files ready to use

imgui-app Imgui-app is an amalgamation of two amazing projects Dear Imgui and Sokol libraries into two files to make it very easy to start working wit

A lightweight C++11-compatible error-handling mechanism
A lightweight C++11-compatible error-handling mechanism

Result is a modern, simple, and light-weight error-handling alternative to exceptions with a rich feature-set.

Python envelope for the popular C library libjpeg for handling JPEG files.

jpeglib Python envelope for the popular C library libjpeg for handling JPEG files. libjpeg offers full control over compression and decompression and

A simple SIP server (proxy) for handling VoIP calls based on SIP using C++

Sip Server A simple sip server for handling VoIP calls based on sip protocol. Features Registration Of Users The server supports registration process.

A forward proxy module for CONNECT request handling

name This module provides support for the CONNECT method request. This method is mainly used to tunnel SSL requests through proxy servers. Table of Co

A template C project using CMAKE, logging library and basic memory handling.

C Project template Aim of this Repository is to create a template repository for C executable projects with following properties: Cmake project Loggin

Wayfire plugin for handling touchpad gestures globally in a layer-shell surface

wf-globalgestures Global touchpad gestures plugin for Wayfire: implements a special protocol (also in this repo) that lets clients request that a part

Either and Maybe monads for better error-handling in C++ ↔️

neither A functional implementation of Either in C++14. buckaroo add github.com/loopperfect/neither Examples Handling Unsafe Code auto unsafe = [] {

C++17 & C++ 20 error-handling and utility extensions.

C++ 17 & C++ 20 error-handling and utility extensions. Overview STX is a collection of libraries and utilities designed to make working with C++ easie

C++14 asynchronous allocation aware futures (supporting then, exception handling, coroutines and connections)
C++14 asynchronous allocation aware futures (supporting then, exception handling, coroutines and connections)

Continuable is a C++14 library that provides full support for: lazy async continuation chaining based on callbacks (then) and expression templates, ca

Owner
null
This project aims to facilitate debugging a kernel driver in windows by adding support for a code change on the fly without reboot/unload, and more!

BSOD Survivor Tired of always telling yourself when you got a BSOD that what if I could just return to the caller function which caused the BSOD, and

Ido Westler 157 Nov 12, 2022
Tool based in nodes to build GLSL shaders without any programming knowledge written in C using OpenGL and GLFW.

FNode Tool based in nodes to build GLSL shaders without any programming knowledge written in C using OpenGL and GLFW (raylib library). It contains a c

Víctor Fisac 81 Nov 19, 2022
Anime browser built with AniList APIs, showcasing clean Flutter BLoC architecture

Anime browser built with AniList APIs. The purpose of this project is to showcase clean Flutter application architecture with BLoC design pattern.

Peter A. Bizjak 23 Nov 5, 2022
Example library and blog that explain how JSI modules are built from scratch in React Native

react-native-simple-jsi This is an example library that explains how anyone can build jsi modules from scratch in React Native. This code is written a

Ammar Ahmed 127 Nov 19, 2022
a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.

UNITS A compile-time, header-only, dimensional analysis library built on c++14 with no dependencies. Get in touch If you are using units.h in producti

Nic Holthaus 803 Dec 1, 2022
✔️The smallest header-only GUI library(4 KLOC) for all platforms

Welcome to GUI-lite The smallest header-only GUI library (4 KLOC) for all platforms. 中文 Lightweight ✂️ Small: 4,000+ lines of C++ code, zero dependenc

null 6.5k Dec 4, 2022
HIBA is a system built on top of regular OpenSSH certificate-based authentication that allows to manage flexible authorization of principals on pools of target hosts without the need to push customized authorized_users files periodically.

HIBA is a system built on top of regular OpenSSH certificate-based authentication that allows to manage flexible authorization of principals on pools of target hosts without the need to push customized authorized_users files periodically.

Google 328 Nov 18, 2022
Robust multi-prompt delimited control and effect handlers in C/C++

libmprompt Note: The library is under development and not yet complete. This library should not be used in production code. Latest release: v0.2, 2021

Koka Language and Related Tools 92 Nov 18, 2022
jvm-monitor is a lightweight monitoring tool that logs all the local variables whenever exceptions occur.

jvm-monitor jvm-monitor is a Java agent attached to a Java VM (virtual machine), which logs all the local variables when exceptions occur. Rationales

Barosl Lee 13 Nov 21, 2021
Replacements to standard numeric types which throw exceptions on errors

safe_numerics Arithmetic operations in C++ are NOT guaranteed to yield a correct mathematical result. This feature is inherited from the early days of

Boost.org 191 Nov 11, 2022