Rizin
unix-like reverse engineering framework and cli tools
common_windows.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2022 GustavoLCR
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include "common_windows.h"
5 
6 #define EXCEPTION_ACCESS_VIOLATION 0xC0000005
7 #define EXCEPTION_DATATYPE_MISALIGNMENT 0x80000002
8 #define EXCEPTION_BREAKPOINT 0x80000003
9 #define EXCEPTION_SINGLE_STEP 0x80000004
10 #define EXCEPTION_ARRAY_BOUNDS_EXCEEDED 0xC000008C
11 #define EXCEPTION_FLT_DENORMAL_OPERAND 0xC000008D
12 #define EXCEPTION_FLT_DIVIDE_BY_ZERO 0xC000008E
13 #define EXCEPTION_FLT_INEXACT_RESULT 0xC000008F
14 #define EXCEPTION_FLT_INVALID_OPERATION 0xC0000090
15 #define EXCEPTION_FLT_OVERFLOW 0xC0000091
16 #define EXCEPTION_FLT_STACK_CHECK 0xC0000092
17 #define EXCEPTION_FLT_UNDERFLOW 0xC0000093
18 #define EXCEPTION_INT_DIVIDE_BY_ZERO 0xC0000094
19 #define EXCEPTION_INT_OVERFLOW 0xC0000095
20 #define EXCEPTION_PRIV_INSTRUCTION 0xC0000096
21 #define EXCEPTION_IN_PAGE_ERROR 0xC0000006
22 #define EXCEPTION_ILLEGAL_INSTRUCTION 0xC000001D
23 #define EXCEPTION_NONCONTINUABLE_EXCEPTION 0xC0000025
24 #define EXCEPTION_STACK_OVERFLOW 0xC00000FD
25 #define EXCEPTION_INVALID_DISPOSITION 0xC0000026
26 #define EXCEPTION_GUARD_PAGE 0x80000001
27 #define EXCEPTION_INVALID_HANDLE 0xC0000008
28 #define EXCEPTION_POSSIBLE_DEADLOCK 0xC0000194
29 #define CONTROL_C_EXIT 0x40010005
30 #define DBG_CONTROL_BREAK 0x40010008
31 #define STATUS_UNWIND_CONSOLIDATE 0x80000029
32 
34  switch (exception_code) {
47  return RZ_DEBUG_REASON_FPU;
53  return RZ_DEBUG_REASON_STEP;
54  default:
55  return RZ_DEBUG_REASON_TRAP;
56  }
57 }
58 
59 static const char *get_exception_name(ut32 ExceptionCode) {
60 #define EXCEPTION_STR(x) \
61  case x: return #x
62  switch (ExceptionCode) {
89  case 0x6BA: return "FILE_DIALOG_EXCEPTION";
90  case 0x406D1388: return "MS_VC_EXCEPTION";
91  default:
92  return "Unknown";
93  }
94 #undef EXCEPTION_STR
95 }
96 
97 bool windows_is_exception_fatal(ut32 exception_code) {
98  switch (exception_code) {
109  return true;
110  default:
111  return false;
112  }
113 }
114 
115 void windows_print_exception_event(ut32 pid, ut32 tid, ut32 exception_code, bool second_chance) {
116  bool is_fatal = windows_is_exception_fatal(exception_code);
117  RZ_LOG_INFO("(%" PFMT32u ") %s Exception %04X (%s) in thread %" PFMT32u "\n",
118  pid,
119  is_fatal ? "Fatal" : "Non-fatal",
120  exception_code, get_exception_name(exception_code),
121  tid);
122  if (second_chance) {
123  RZ_LOG_WARN("A second-chance exception has ocurred!\n");
124  }
125  if (is_fatal) {
126  RZ_LOG_INFO("Use 'dce' continue into exception handler\n");
127  }
128 }
#define EXCEPTION_SINGLE_STEP
Definition: common_windows.c:9
#define EXCEPTION_NONCONTINUABLE_EXCEPTION
#define EXCEPTION_GUARD_PAGE
#define EXCEPTION_FLT_STACK_CHECK
#define EXCEPTION_STACK_OVERFLOW
#define EXCEPTION_POSSIBLE_DEADLOCK
#define CONTROL_C_EXIT
#define EXCEPTION_INT_DIVIDE_BY_ZERO
#define EXCEPTION_IN_PAGE_ERROR
#define EXCEPTION_FLT_UNDERFLOW
#define EXCEPTION_INT_OVERFLOW
#define EXCEPTION_INVALID_HANDLE
#define STATUS_UNWIND_CONSOLIDATE
#define DBG_CONTROL_BREAK
#define EXCEPTION_INVALID_DISPOSITION
#define EXCEPTION_FLT_OVERFLOW
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: common_windows.c:7
#define EXCEPTION_FLT_DENORMAL_OPERAND
RzDebugReasonType windows_exception_to_reason(ut32 exception_code)
#define EXCEPTION_FLT_INEXACT_RESULT
#define EXCEPTION_ILLEGAL_INSTRUCTION
#define EXCEPTION_ACCESS_VIOLATION
Definition: common_windows.c:6
static const char * get_exception_name(ut32 ExceptionCode)
#define EXCEPTION_BREAKPOINT
Definition: common_windows.c:8
#define EXCEPTION_FLT_INVALID_OPERATION
void windows_print_exception_event(ut32 pid, ut32 tid, ut32 exception_code, bool second_chance)
#define EXCEPTION_STR(x)
#define EXCEPTION_PRIV_INSTRUCTION
bool windows_is_exception_fatal(ut32 exception_code)
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
uint32_t ut32
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
RzDebugReasonType
Definition: rz_debug.h:89
@ RZ_DEBUG_REASON_STEP
Definition: rz_debug.h:98
@ RZ_DEBUG_REASON_ILLEGAL
Definition: rz_debug.h:102
@ RZ_DEBUG_REASON_BREAKPOINT
Definition: rz_debug.h:94
@ RZ_DEBUG_REASON_TRAP
Definition: rz_debug.h:111
@ RZ_DEBUG_REASON_FPU
Definition: rz_debug.h:114
@ RZ_DEBUG_REASON_SEGFAULT
Definition: rz_debug.h:93
@ RZ_DEBUG_REASON_DIVBYZERO
Definition: rz_debug.h:101
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define PFMT32u
Definition: rz_types.h:409