Skip to content

Commit 0f3f10f

Browse files
committed
feat(seh): basic implementation, for some reason __except not being hit
1 parent 5a5edbb commit 0f3f10f

12 files changed

+455
-273
lines changed

CodeFunctions.cpp

Lines changed: 170 additions & 188 deletions
Large diffs are not rendered by default.

CodeFunctions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <sstream>
1010
#include <iostream>
1111
#include "AOB.h"
12-
#include "UtilityFunctions.h"
1312
#include "Memory.h"
1413

1514
extern HANDLE codeHeap;
@@ -29,5 +28,3 @@ int luaExposeCode(lua_State* L);
2928
int luaHookCode(lua_State* L);
3029

3130
int luaCallMachineCode(lua_State* L);
32-
33-
int convertTableToByteStream(lua_State* L, std::stringstream* s);

Exceptions.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "Exceptions.h"
2+
3+
4+
const char errorReport[1000] = {};
5+
static const char* const errorReportTooLong = "error report is too longer, longer than 1000 characters";
6+
7+
int errorFilterAndReporter(unsigned int code, struct _EXCEPTION_POINTERS* ep)
8+
{
9+
std::stringstream errorReportBuilder;
10+
errorReportBuilder << "Exception occurred: code: 0x" << std::hex << code << " at 0x" << std::hex << ep->ExceptionRecord->ExceptionAddress;
11+
std::string r = errorReportBuilder.str();
12+
const char* data = r.c_str();
13+
size_t size = strnlen_s(data, 1000);
14+
if (size < 1000) {
15+
// memset((void*)errorReport, 0, 1000);
16+
memcpy((void*)errorReport, data, size + 1);
17+
}
18+
else {
19+
memcpy((void*)errorReport, (void*)errorReportTooLong, strnlen_s(errorReportTooLong, 1000));
20+
}
21+
return EXCEPTION_EXECUTE_HANDLER;
22+
}

Exceptions.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include "framework.h"
4+
#include <string>
5+
#include <sstream>
6+
7+
#define RPS_HANDLE_SEH errorFilterAndReporter(GetExceptionCode(), GetExceptionInformation())
8+
#define RPS_LUA_SEH luaL_error(L, "%s", errorReport)
9+
#define RPS_LUA_SEH_X(x) luaL_error(L, "%s while executing 0x%X", errorReport, x)
10+
#define RPS_LUA_SEH_ADDRESS luaL_error(L, "%s while executing 0x%X", errorReport, address)
11+
12+
extern const char errorReport[1000];
13+
int errorFilterAndReporter(unsigned int code, struct _EXCEPTION_POINTERS* ep);

0 commit comments

Comments
 (0)