The main release package of Ashita v3. Contains all the needed files for users to get up and running. Used by the launcher/injector to auto-update as well. http://ashita.atom0s.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AS_Exception.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * Ashita - Copyright (c) 2014 - 2017 atom0s [[email protected]]
  3. *
  4. * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
  5. * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to
  6. * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
  7. *
  8. * By using Ashita, you agree to the above license and its terms.
  9. *
  10. * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were
  11. * made. You must do so in any reasonable manner, but not in any way that suggests the licensor
  12. * endorses you or your use.
  13. *
  14. * Non-Commercial - You may not use the material (Ashita) for commercial purposes.
  15. *
  16. * No-Derivatives - If you remix, transform, or build upon the material (Ashita), you may not distribute the
  17. * modified material. You are, however, allowed to submit the modified works back to the original
  18. * Ashita project in attempt to have it added to the original project.
  19. *
  20. * You may not apply legal terms or technological measures that legally restrict others
  21. * from doing anything the license permits.
  22. *
  23. * No warranties are given.
  24. */
  25. #ifndef __ASHITA_AS_EXCEPTION_H_INCLUDED__
  26. #define __ASHITA_AS_EXCEPTION_H_INCLUDED__
  27. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  28. #pragma once
  29. #endif
  30. #include <Windows.h>
  31. #include <eh.h>
  32. // Missing Status Code Defines
  33. #ifndef STATUS_POSSIBLE_DEADLOCK
  34. #define STATUS_POSSIBLE_DEADLOCK 0xC0000194
  35. #endif
  36. // Macro For Handling Exception Cases
  37. #define CASE(Exception) \
  38. case Exception: \
  39. this->m_Exception = #Exception; \
  40. break;
  41. namespace Ashita
  42. {
  43. namespace Exception
  44. {
  45. class AS_Exception
  46. {
  47. uint32_t m_ExceptionId;
  48. const char* m_Exception;
  49. public:
  50. /**
  51. * Constructor and Deconstructor
  52. */
  53. explicit AS_Exception(uint32_t id)
  54. : m_ExceptionId(id)
  55. , m_Exception(nullptr)
  56. {
  57. switch (this->m_ExceptionId)
  58. {
  59. CASE(EXCEPTION_ACCESS_VIOLATION);
  60. CASE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
  61. CASE(EXCEPTION_BREAKPOINT);
  62. CASE(EXCEPTION_DATATYPE_MISALIGNMENT);
  63. CASE(EXCEPTION_FLT_DENORMAL_OPERAND);
  64. CASE(EXCEPTION_FLT_DIVIDE_BY_ZERO);
  65. CASE(EXCEPTION_FLT_INEXACT_RESULT);
  66. CASE(EXCEPTION_FLT_INVALID_OPERATION);
  67. CASE(EXCEPTION_FLT_OVERFLOW);
  68. CASE(EXCEPTION_FLT_STACK_CHECK);
  69. CASE(EXCEPTION_FLT_UNDERFLOW);
  70. CASE(EXCEPTION_GUARD_PAGE);
  71. CASE(EXCEPTION_ILLEGAL_INSTRUCTION);
  72. CASE(EXCEPTION_IN_PAGE_ERROR);
  73. CASE(EXCEPTION_INT_DIVIDE_BY_ZERO);
  74. CASE(EXCEPTION_INT_OVERFLOW);
  75. CASE(EXCEPTION_INVALID_DISPOSITION);
  76. CASE(EXCEPTION_INVALID_HANDLE);
  77. CASE(EXCEPTION_NONCONTINUABLE_EXCEPTION);
  78. CASE(EXCEPTION_POSSIBLE_DEADLOCK);
  79. CASE(EXCEPTION_PRIV_INSTRUCTION);
  80. CASE(EXCEPTION_SINGLE_STEP);
  81. CASE(EXCEPTION_STACK_OVERFLOW);
  82. default:
  83. this->m_Exception = "Unknown exception occurred.";
  84. break;
  85. }
  86. }
  87. ~AS_Exception(void) { }
  88. public:
  89. /**
  90. * Returns the exception id of the current wrapped exception.
  91. *
  92. * @returns {uint32_t} The exception id.
  93. */
  94. uint32_t GetExceptionId(void) const
  95. {
  96. return this->m_ExceptionId;
  97. }
  98. const char* GetException(void) const
  99. {
  100. return this->m_Exception;
  101. }
  102. };
  103. class ScopedTranslator
  104. {
  105. _se_translator_function m_Function;
  106. public:
  107. /**
  108. * Constructor and Deconstructor
  109. */
  110. ScopedTranslator(void)
  111. {
  112. this->m_Function = ::_set_se_translator(&ScopedTranslator::ScopedTranslatorFunc);
  113. }
  114. ~ScopedTranslator(void)
  115. {
  116. if (this->m_Function != nullptr)
  117. ::_set_se_translator(this->m_Function);
  118. this->m_Function = nullptr;
  119. }
  120. private:
  121. /**
  122. * Exception translation function used to convert a C structured exception to a C++ typed exception.
  123. * (Used to wrap the exception into our custom exception object.)
  124. *
  125. * @param {uint32_t} id - The id of the exception being wrapped.
  126. * @param {EXCEPTION_POINTERS*} pointers - The pointer information of the exception being handled.
  127. */
  128. static void ScopedTranslatorFunc(uint32_t id, struct _EXCEPTION_POINTERS* pointers)
  129. {
  130. UNREFERENCED_PARAMETER(pointers);
  131. throw AS_Exception(id);
  132. }
  133. };
  134. }; // namespace Exception
  135. }; // namespace Ashita
  136. #endif // __ASHITA_AS_EXCEPTION_H_INCLUDED__