| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f1c139f commit 5ee9402
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,11 @@ | |||
| 1 | 1 | ||
| 2 | 2 | #include "DebugUtils.h" | |
| 3 | + #include "SEHUtils.h" | ||
| 3 | 4 | ||
| 4 | 5 | // Dump all data - debug purposes | |
| 5 | 6 | ||
| 7 | + | ||
| 8 | + | ||
| 6 | 9 | void DebugUtils::DumpAllData() | |
| 7 | 10 | { | |
| 8 | 11 | cout << endl; | |
@@ -53,7 +56,16 @@ void DebugUtils::TestShellcode(string p_sFilename) | |||
| 53 | 56 | } | |
| 54 | 57 | ||
| 55 | 58 | // Copy shellcode and execute it | |
| 56 | - | ||
| 57 | - memcpy(sc, p, size); | ||
| 58 | - (*(int(*)()) sc)(); | ||
| 59 | + try | ||
| 60 | + { | ||
| 61 | + _set_se_translator(CxxTranslateSehException); | ||
| 62 | + memcpy(sc, p, size); | ||
| 63 | + (*(int(*)()) sc)(); | ||
| 64 | + } | ||
| 65 | + catch (const seh_exception& e) | ||
| 66 | + { | ||
| 67 | + cout << "Error when executing shellcode: " | ||
| 68 | + << e.what() << endl; | ||
| 69 | + } | ||
| 59 | 70 | } | |
| 71 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + #ifndef SEHUTILIS_H | ||
| 2 | + #define SEHUTILIS_H | ||
| 3 | + #include <windows.h> | ||
| 4 | + #include <exception> | ||
| 5 | + | ||
| 6 | + struct seh_exception : public std::exception | ||
| 7 | + { | ||
| 8 | + seh_exception(const char* message, DWORD code) : exception(message), m_code(code) {} | ||
| 9 | + | ||
| 10 | + DWORD Code() const { return m_code; } | ||
| 11 | + | ||
| 12 | + private: | ||
| 13 | + const DWORD m_code; | ||
| 14 | + }; | ||
| 15 | + | ||
| 16 | + void CxxTranslateSehException(unsigned int, EXCEPTION_POINTERS* pointers) | ||
| 17 | + { | ||
| 18 | + DWORD exceptionCode = pointers->ExceptionRecord->ExceptionCode; | ||
| 19 | + const char* msg = nullptr; | ||
| 20 | + | ||
| 21 | + switch (exceptionCode) { | ||
| 22 | + case EXCEPTION_ACCESS_VIOLATION: | ||
| 23 | + msg = "Access violation."; | ||
| 24 | + break; | ||
| 25 | + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: | ||
| 26 | + msg = "Out of bound access."; | ||
| 27 | + break; | ||
| 28 | + case EXCEPTION_ILLEGAL_INSTRUCTION: | ||
| 29 | + msg = "Illegal instruction."; | ||
| 30 | + break; | ||
| 31 | + default: | ||
| 32 | + break; | ||
| 33 | + } | ||
| 34 | + throw seh_exception(msg, exceptionCode); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,6 +134,7 @@ | |||
| 134 | 134 | <FunctionLevelLinking>true</FunctionLevelLinking> | |
| 135 | 135 | <IntrinsicFunctions>true</IntrinsicFunctions> | |
| 136 | 136 | <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 137 | + <ExceptionHandling>Async</ExceptionHandling> | ||
| 137 | 138 | </ClCompile> | |
| 138 | 139 | <Link> | |
| 139 | 140 | <SubSystem>Console</SubSystem> | |
@@ -157,6 +158,7 @@ | |||
| 157 | 158 | <ClInclude Include="DLLBaseAddress.h" /> | |
| 158 | 159 | <ClInclude Include="FunctionCalls.h" /> | |
| 159 | 160 | <ClInclude Include="FunctionOffsetAddress.h" /> | |
| 161 | + <ClInclude Include="SEHUtils.h" /> | ||
| 160 | 162 | <ClInclude Include="stdafx.h" /> | |
| 161 | 163 | <ClInclude Include="StringOffsetAddress.h" /> | |
| 162 | 164 | <ClInclude Include="targetver.h" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,9 @@ | |||
| 63 | 63 | <ClInclude Include="Compile.h"> | |
| 64 | 64 | <Filter>Header Files</Filter> | |
| 65 | 65 | </ClInclude> | |
| 66 | + <ClInclude Include="SEHUtils.h"> | ||
| 67 | + <Filter>Header Files</Filter> | ||
| 68 | + </ClInclude> | ||
| 66 | 69 | </ItemGroup> | |
| 67 | 70 | <ItemGroup> | |
| 68 | 71 | <ClCompile Include="stdafx.cpp"> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments