IDA C++ SDK 9.2
Loading...
Searching...
No Matches
tryblks.hpp
Go to the documentation of this file.
1/*
2 * Interactive disassembler (IDA).
3 * Copyright (c) 2016-2025 Hex-Rays
4 * ALL RIGHTS RESERVED.
5 *
6 * Module independent exception description
7 */
8
9#ifndef TRYBLKS_HPP
10#define TRYBLKS_HPP
11
28
29// We use end_ea=BADADDR if the exact boundaries are unknown of any range.
30
31//----------------------------------------------------------------------------
32// An exception handler clause (the body of __except or catch statement)
34{
35 sval_t disp; // displacement to the stack region of the guarded region.
36 // if it is valid, it is fpreg relative.
37 // -1 means unknown.
38 int fpreg; // frame register number used in handler. -1 means none.
39
40 try_handler_t() : disp(-1), fpreg(-1) {}
41 void clear(void)
42 {
44 disp = -1;
45 fpreg = -1;
46 }
47};
49
50//----------------------------------------------------------------------------
51// __except() {} statement
52struct seh_t : public try_handler_t
53{
54 rangevec_t filter; // boundaries of the filter callback. if filter is empty,
55 ea_t seh_code; // then use seh_code
56#define SEH_CONTINUE BADADDR // EXCEPTION_CONTINUE_EXECUTION (-1)
57#define SEH_SEARCH ea_t(0) // EXCEPTION_CONTINUE_SEARCH (0) (alias of __finally)
58#define SEH_HANDLE ea_t(1) // EXCEPTION_EXECUTE_HANDLER (1)
59 void clear(void)
60 {
62 filter.clear();
63 seh_code = SEH_CONTINUE;
64 }
65};
67
68//----------------------------------------------------------------------------
69// catch() {} statement
70struct catch_t : public try_handler_t
71{
72 sval_t obj; // fpreg relative displacement to the exception object. -1 if unknown.
73 sval_t type_id; // the type caught by this catch. -1 means "catch(...)"
74#define CATCH_ID_ALL sval_t(-1) // catch(...)
75#define CATCH_ID_CLEANUP sval_t(-2) // a cleanup handler invoked if exception occures
76
77 catch_t() : obj(-1), type_id(-1) {}
78};
81
82//----------------------------------------------------------------------------
83class tryblk_t : public rangevec_t // block guarded by try/__try {...} statements
84{
85#ifndef SWIG
86 char reserve[qmax(sizeof(catchvec_t), sizeof(seh_t))]; // seh_t or catchvec_t
87#endif
88 uchar cb; // size of tryblk_t
89 uchar kind; // one of the following kinds
90#define TB_NONE 0 // empty
91#define TB_SEH 1 // MS SEH __try/__except/__finally
92#define TB_CPP 2 // C++ language try/catch
93
94public:
95 uchar level; // nesting level, calculated by get_tryblks()
96
97 // C++ try/catch block (TB_CPP)
98 catchvec_t &cpp() { return *(( catchvec_t *)reserve); }
99 const catchvec_t &cpp() const { return *((const catchvec_t *)reserve); }
100
101 // SEH __except/__finally case (TB_SEH)
102 seh_t &seh() { return *(( seh_t *)reserve); }
103 const seh_t &seh() const { return *((const seh_t *)reserve); }
104
105 tryblk_t() : rangevec_t(), cb(sizeof(*this)), kind(TB_NONE), level(0) { reserve[0] = '\0'; }
107 tryblk_t(const tryblk_t &r) : rangevec_t(), kind(TB_NONE) { *this = r; }
108 uchar get_kind(void) const { return kind; }
109 bool empty(void) const { return kind == TB_NONE || size() == 0; }
110 bool is_seh(void) const { return kind == TB_SEH; }
111 bool is_cpp(void) const { return kind == TB_CPP; }
112
113
114 //-------------------------------------------------------------------------
116 {
117 if ( this != &r ) // don't copy yourself
118 {
119 if ( kind != TB_NONE )
120 clear();
121 kind = r.kind;
122 level = r.level;
124
125 if ( kind == TB_SEH )
126 new (reserve) seh_t(r.seh());
127 else if ( kind == TB_CPP )
128 new (reserve) catchvec_t(r.cpp());
129 }
130 return *this;
131 }
132
133 //-------------------------------------------------------------------------
134 void clear(void)
135 {
136 if ( kind == TB_CPP )
137 cpp().~catchvec_t();
138 else if ( kind == TB_SEH )
139 seh().~seh_t();
140 kind = TB_NONE;
141 }
142
143 //-------------------------------------------------------------------------
145 {
146 if ( kind != TB_SEH )
147 {
148 clear();
149 new (reserve) seh_t;
150 kind = TB_SEH;
151 }
152 else
153 {
154 seh().clear();
155 }
156 return seh();
157 }
158
159 //-------------------------------------------------------------------------
161 {
162 if ( kind != TB_CPP )
163 {
164 clear();
165 new (reserve) catchvec_t;
166 kind = TB_CPP;
167 }
168 else
169 {
170 cpp().clear();
171 }
172 return cpp();
173 }
174};
177
184
185idaman size_t ida_export get_tryblks(tryblks_t *tbv, const range_t &range);
186
189
190idaman void ida_export del_tryblks(const range_t &range);
191
192
196
197idaman int ida_export add_tryblk(const tryblk_t &tb);
198
201#define TBERR_OK 0
202#define TBERR_START 1
203#define TBERR_END 2
204#define TBERR_ORDER 3
205#define TBERR_EMPTY 4
206#define TBERR_KIND 5
207#define TBERR_NO_CATCHES 6
208#define TBERR_INTERSECT 7
210
214
215idaman ea_t ida_export find_syseh(ea_t ea);
216
217
220#define TBEA_TRY 0x01
221#define TBEA_CATCH 0x02
222#define TBEA_SEHTRY 0x04
223#define TBEA_SEHLPAD 0x08
224#define TBEA_SEHFILT 0x10
225#define TBEA_ANY 0x1f
226#define TBEA_FALLTHRU 0x20
228
232idaman bool ida_export is_ea_tryblks(ea_t ea, uint32 flags);
233
234
235#endif // TRYBLKS_HPP
Reimplementation of vector class from STL.
Definition pro.h:2250
void clear(void)
Definition pro.h:2439
qvector< range_t > & operator=(const qvector< range_t > &x)
Definition pro.h:2448
size_t size(void) const
Definition pro.h:2423
Definition tryblks.hpp:84
uchar get_kind(void) const
Definition tryblks.hpp:108
const seh_t & seh() const
Definition tryblks.hpp:103
uchar level
Definition tryblks.hpp:95
tryblk_t & operator=(const tryblk_t &r)
Definition tryblks.hpp:115
tryblk_t(const tryblk_t &r)
Definition tryblks.hpp:107
void clear(void)
Definition tryblks.hpp:134
seh_t & seh()
Definition tryblks.hpp:102
seh_t & set_seh(void)
Definition tryblks.hpp:144
bool is_seh(void) const
Definition tryblks.hpp:110
bool empty(void) const
Definition tryblks.hpp:109
~tryblk_t()
Definition tryblks.hpp:106
tryblk_t()
Definition tryblks.hpp:105
bool is_cpp(void) const
Definition tryblks.hpp:111
const catchvec_t & cpp() const
Definition tryblks.hpp:99
catchvec_t & set_cpp(void)
Definition tryblks.hpp:160
catchvec_t & cpp()
Definition tryblks.hpp:98
unsigned int uint32
unsigned 32 bit value
Definition pro.h:348
adiff_t sval_t
signed value used by the processor.
Definition pro.h:446
uint64 ea_t
Definition pro.h:421
unsigned char uchar
unsigned 8 bit value
Definition pro.h:337
Definition tryblks.hpp:71
catch_t()
Definition tryblks.hpp:77
sval_t type_id
Definition tryblks.hpp:73
sval_t obj
Definition tryblks.hpp:72
Base class for an range.
Definition range.hpp:35
Vector of range_t instances.
Definition range.hpp:93
Definition tryblks.hpp:53
ea_t seh_code
Definition tryblks.hpp:55
void clear(void)
Definition tryblks.hpp:59
rangevec_t filter
Definition tryblks.hpp:54
Definition tryblks.hpp:34
void clear(void)
Definition tryblks.hpp:41
try_handler_t()
Definition tryblks.hpp:40
int fpreg
Definition tryblks.hpp:38
sval_t disp
Definition tryblks.hpp:35
DECLARE_TYPE_AS_MOVABLE(try_handler_t)
qvector< tryblk_t > tryblks_t
Definition tryblks.hpp:176
idaman bool ida_export is_ea_tryblks(ea_t ea, uint32 flags)
Check if the given address ea is part of tryblks description.
idaman ea_t ida_export find_syseh(ea_t ea)
Find the start address of the system eh region including the argument.
idaman size_t ida_export get_tryblks(tryblks_t *tbv, const range_t &range)
qvector< catch_t > catchvec_t
Definition tryblks.hpp:80
idaman void ida_export del_tryblks(const range_t &range)
Delete try block information in the specified range.
idaman int ida_export add_tryblk(const tryblk_t &tb)
Add one try block information.