98#define DECLARE_JUMP_PATTERN_HELPERS(decl)\
99decl void ida_export check_spoiled_jpt(const jump_pattern_t *_this, tracked_regs_t *_regs); \
100decl bool ida_export match_jpt(jump_pattern_t *_this);\
101decl bool ida_export same_value_jpt(jump_pattern_t *_this, const op_t &op, int r_i);\
102decl bool ida_export track_value_until_address_jpt(jump_pattern_t *_this, op_t *op, ea_t ea);\
103decl void ida_export combine_regs_jpt(jump_pattern_t *_this, tracked_regs_t *dst, const tracked_regs_t &src, ea_t ea);\
104decl void ida_export mark_switch_insns_jpt(const jump_pattern_t *_this, int last, int);\
105decl bool ida_export set_moved_jpt(const jump_pattern_t *_this, const op_t &dst, const op_t &src, tracked_regs_t &_regs, op_dtype_t real_dst_dtype, op_dtype_t real_src_dtype);
117 bool modifying_r32_spoils_r64;
120 typedef bool (jump_pattern_t::*check_insn_t)(
void);
121 inline jump_pattern_t(
123 const char (*depends)[4],
138 check_insn_t check[NINS];
154 #define JPT_NEAR 0x20
156 const char (*depends)[4];
163 void mark_switch_insns(
int last = NINS - 1,
int nlowcase = 0)
const
165 mark_switch_insns_jpt(
this, last, nlowcase);
189 virtual void process_delay_slot(
ea_t &,
bool )
const {}
199 cc_inc_ncases = 0x01,
200 cc_check_max_ncases = 0x02,
208 virtual bool equal_ops(
const op_t &x,
const op_t &y)
const
238 check_spoiled_jpt(
this, _regs);
250 inline void track(
int reg,
int r_i,
op_dtype_t dtype);
251 inline void trackop(
const op_t &op,
int r_i);
252 inline bool is_spoiled(
int r_i) {
return regs[r_i].type ==
o_void; }
253 inline bool is_equal(
int reg,
int r_i,
op_dtype_t dtype);
254 inline bool is_equal(
const op_t &op,
int r_i);
255 inline bool same_value(
const op_t &op,
int r_i);
256 inline bool track_value_until_address(
op_t *op,
ea_t ea);
258 virtual bool jpi0(
void) = 0;
259 virtual bool jpi1(
void) {
return false; }
260 virtual bool jpi2(
void) {
return false; }
261 virtual bool jpi3(
void) {
return false; }
262 virtual bool jpi4(
void) {
return false; }
263 virtual bool jpi5(
void) {
return false; }
264 virtual bool jpi6(
void) {
return false; }
265 virtual bool jpi7(
void) {
return false; }
266 virtual bool jpi8(
void) {
return false; }
267 virtual bool jpi9(
void) {
return false; }
268 virtual bool jpia(
void) {
return false; }
269 virtual bool jpib(
void) {
return false; }
270 virtual bool jpic(
void) {
return false; }
271 virtual bool jpid(
void) {
return false; }
272 virtual bool jpie(
void) {
return false; }
273 virtual bool jpif(
void) {
return false; }
275 virtual bool pre_jpi(
int ) {
return true; }
277 bool match(
const insn_t &_insn) { insn = _insn;
return match_jpt(
this); }
280 virtual ~jump_pattern_t() {}
306 return set_moved_jpt(
this, dst, src, _regs, real_dst_dtype, real_src_dtype);
315 combine_regs_jpt(
this, dst, src, ea);
320 bool follow_tree(
ea_t ea,
int n);
321 bool same_value_impl(
const op_t &op,
int r_i);
322 bool track_value_until_address_impl(
op_t *op,
ea_t ea);
324 inline bool equal_ops_dtype(
const op_t &op,
const op_t ®)
const;
335 static inline int get_dtype_nbits(
op_dtype_t dtype);
340 inline void check_spoiled_not_reg(
342 uint maxop = UA_MAXOP)
const;
381 const char *name =
nullptr);
391 bool ignore_refs =
false);
420template<
class State,
class Ctrl>
461 uint max_insn_cnt_ = 0)
540inline jump_pattern_t::jump_pattern_t(
542 const char (*_depends)[4],
544 : modifying_r32_spoils_r64(true),
547 in_linear_flow(false),
553 regs.resize(last_reg + 1);
557inline bool jump_pattern_t::equal_ops_dtype(
559 const op_t ®)
const
561 if ( !equal_ops(op, reg) )
568 if ( modifying_r32_spoils_r64 && op.
dtype == dt_dword )
571 if ( !is_narrower(extend_dtype(op), reg.
dtype) )
581 return dt2 < dt_2bit && dt1 < dt2;
583 return dt2 < dt_2bit || dt1 < dt2;
587inline int jump_pattern_t::get_dtype_nbits(
op_dtype_t dtype)
591 case dt_byte:
return 8;
592 case dt_word:
return 16;
593 case dt_dword:
return 32;
594 case dt_qword:
return 64;
595 case dt_7bit:
return 7;
596 case dt_6bit:
return 6;
597 case dt_5bit:
return 5;
598 case dt_4bit:
return 4;
599 case dt_3bit:
return 3;
600 case dt_2bit:
return 2;
606inline void jump_pattern_t::check_spoiled_not_reg(
610 uint32 feature = insn.get_canon_feature(PH);
613 for (
uint i = 0; i < maxop; ++i )
616 && insn.ops[i].type !=
o_void
617 && insn.ops[i].type !=
o_reg )
619 set_spoiled(_regs, insn.ops[i]);
625inline void jump_pattern_t::track(
int reg,
int r_i,
op_dtype_t dtype)
627 regs[r_i].type =
o_reg;
629 regs[r_i].dtype = dtype;
631inline void jump_pattern_t::trackop(
const op_t &op,
int r_i)
637inline bool jump_pattern_t::is_equal(
int reg,
int r_i,
op_dtype_t dtype)
643 return is_equal(op, r_i);
645inline bool jump_pattern_t::is_equal(
const op_t &op,
int r_i)
650 stop_matching =
true;
653 return equal_ops_dtype(op, regs[r_i]);
657inline bool jump_pattern_t::same_value(
const op_t &op,
int r_i)
659 return same_value_jpt(
this, op, r_i);
663inline bool jump_pattern_t::track_value_until_address(
op_t *op,
ea_t ea)
665 return track_value_until_address_jpt(
this, op, ea);
673 for (
size_t i = 0; i < _regs.
size(); ++i )
679 for (
size_t i = 0; i < _regs.
size(); ++i )
680 if ( equal_ops(_regs[i], op) )
687template<
class State,
class Ctrl>
693 if ( visited_end ==
nullptr )
719 ctrl.process_delay_slot(ea,
true);
739 if ( prev_ea != BADADDR )
782template<
class State,
class Ctrl>
787 if ( visited_end ==
nullptr )
805template<
class State,
class Ctrl>
817 regs = w->second.regs;
828template<
class State,
class Ctrl>
831 visited_t::iterator v =
visited.upper_bound(ea);
837 if ( ea > v->second )
flags64_t idaapi get_flags32(ea_t ea)
Get only 32 low bits of flags.
Definition bytes.hpp:274
idaman ea_t ida_export prev_not_tail(ea_t ea)
Get address of previous non-tail byte.
Operand of an instruction.
Definition ua.hpp:170
uint16 reg
number of register (o_reg)
Definition ua.hpp:256
uval_t value
operand value (o_imm) or outer displacement (o_displ+OF_OUTER_DISP).
Definition ua.hpp:270
optype_t type
Type of operand (see Operand types)
Definition ua.hpp:178
op_dtype_t dtype
Type of operand value (see Operand value types).
Definition ua.hpp:225
Reimplementation of vector class from STL.
Definition pro.h:2262
size_t size(void) const
Get the number of elements in the qvector.
Definition pro.h:2494
THREAD_SAFE bool idaapi is_func(flags64_t F)
Is function start?
Definition bytes.hpp:2010
THREAD_SAFE constexpr bool idaapi is_flow(flags64_t F)
Does the previous instruction exist and pass execution flow to the current byte?
Definition bytes.hpp:896
THREAD_SAFE constexpr bool idaapi has_xref(flags64_t F)
Does the current byte have cross-references to it?
Definition bytes.hpp:912
idaman ea_t ida_export get_func_start(ea_t ea)
Get start address of the function containing 'ea'.
bool function_contains(ea_t func_ea, ea_t ea)
Does the function at func_ea contain ea?
Definition funcs.hpp:1121
const optype_t o_reg
General Register (al,ax,es,ds...).
Definition ua.hpp:83
const optype_t o_void
No Operand.
Definition ua.hpp:82
idaman size_t n
Definition pro.h:1000
idaman bool ida_export get_segment_info(segment_info_t *out, ea_t ea, int flags=0)
Fill segment_info_t structure for segment at the specified address.
cref_t
CODE xref types.
Definition xref.hpp:49
@ fl_JN
Jump Near.
Definition xref.hpp:59
@ fl_U
unknown – for compatibility with old versions.
Definition xref.hpp:50
@ fl_F
Ordinary flow: used to specify execution flow to the next instruction.
Definition xref.hpp:61
@ fl_JF
Jump Far.
Definition xref.hpp:58
const tinfo_t & type
Definition hexrays.hpp:7698
THREAD_SAFE bool has_cf_chg(uint32 feature, uint opnum)
Does an instruction with the specified feature modify the i-th operand?
Definition idp.hpp:112
idaman int ida_export check_flat_jump_table(switch_info_t *si, ea_t jump_ea, int is_pattern_res=JT_SWITCH)
idaman bool ida_export check_for_table_jump(switch_info_t *si, const insn_t &insn, is_pattern_t *const patterns[], size_t qty, table_checker_t *check_table=nullptr, const char *name=nullptr)
idaman ea_t ida_export get_jtable_target(ea_t jump_ea, const switch_info_t &si, int i)
idaman ea_t ida_export find_defjump_from_table(ea_t jump_ea, const switch_info_t &si)
int table_checker_t(switch_info_t *si, ea_t jump_ea, int is_pattern_res, procmod_t *pm)
Definition jumptable.hpp:355
int is_pattern_t(switch_info_t *si, const insn_t &insn, procmod_t *procmod)
Definition jumptable.hpp:352
qvector< op_t > tracked_regs_t
Definition jumptable.hpp:97
@ JT_SWITCH
Definition jumptable.hpp:349
@ JT_NONE
Definition jumptable.hpp:349
@ JT_CALL
Definition jumptable.hpp:349
idaman void ida_export trim_jtable(switch_info_t *si, ea_t jump_ea, bool ignore_refs=false)
idaman bool ida_export find_jtable_size(switch_info_t *si)
DECLARE_JUMP_PATTERN_HELPERS(idaman) class jump_pattern_t
Definition jumptable.hpp:107
bool ok
Definition kernwin.hpp:7410
void(idaapi *range_marker)(ea_t ea
Pointer to range marker function (for idaviews and hexviews) This pointer is initialized by setup_ran...
Definitions of various information kept in netnodes.
This is the first header included in the IDA project.
int bool
Definition pro.h:333
unsigned int uint32
unsigned 32 bit value
Definition pro.h:352
uint8 op_dtype_t
Definition pro.h:464
uint64 ea_t
Definition pro.h:425
unsigned int uint
unsigned 32 bit value
Definition pro.h:343
qvector< ea_t > eavec_t
vector of addresses
Definition pro.h:2838
uint64 flags64_t
64-bit flags for each address
Definition pro.h:5106
Definition jumptable.hpp:447
State regs
Definition jumptable.hpp:448
uint insn_cnt
Definition jumptable.hpp:449
state_t()
Definition jumptable.hpp:450
visited_t visited
Definition jumptable.hpp:443
std::map< ea_t, ea_t > visited_t
Definition jumptable.hpp:442
simple_bfi_t & ctrl
Definition jumptable.hpp:429
std::map< ea_t, state_t > waiting_t
Definition jumptable.hpp:452
static void combine_insn_cnt(uint *dst, uint src)
Definition jumptable.hpp:503
ea_t * find_visited(ea_t ea)
Definition jumptable.hpp:829
cref_t prev_insn()
Definition jumptable.hpp:688
ea_t func_ea
Definition jumptable.hpp:435
bool only_near
Definition jumptable.hpp:430
no_regs_t & regs
Definition jumptable.hpp:428
cref_t get_waiting()
Definition jumptable.hpp:806
range_t seg
Definition jumptable.hpp:436
ea_t cur_ea
Definition jumptable.hpp:427
uint max_insn_cnt
Definition jumptable.hpp:431
uint insn_cnt
Definition jumptable.hpp:439
ea_t cur_end
Definition jumptable.hpp:438
backward_flow_iterator_t(ea_t start_ea_, State &start_regs, Ctrl &ctrl_, bool only_near_, uint max_insn_cnt_=0)
Definition jumptable.hpp:456
ea_t get_cur_end() const
Definition jumptable.hpp:491
waiting_t waiting
Definition jumptable.hpp:453
cref_t skip_block()
Definition jumptable.hpp:783
bool check_bounds() const
Definition jumptable.hpp:509
ea_t start_ea
Definition jumptable.hpp:437
Definition jumptable.hpp:519
Base class for an range.
Definition range.hpp:35
simple_bfi_t(ea_t ea)
Definition jumptable.hpp:529
no_regs_t regs_
Definition jumptable.hpp:526
static void combine_regs(no_regs_t *, const no_regs_t &, ea_t)
Definition jumptable.hpp:531
backward_flow_iterator_t< no_regs_t, simple_bfi_t > base_t
Definition jumptable.hpp:523
static void process_delay_slot(ea_t &, bool)
Definition jumptable.hpp:532
Information about a switch statement.
Definition nalt.hpp:699
Structure to enumerate all xrefs.
Definition xref.hpp:196
bool first_to(ea_t _to, int flags=XREF_FLOW)
Get xref to given address (store in from)
Definition xref.hpp:237
ea_t from
the referencing address - filled by first_to(),next_to()
Definition xref.hpp:197
uchar type
type of the last returned reference (cref_t & dref_t)
Definition xref.hpp:201
bool next_to()
Get next xref to address provided to first_to()
Definition xref.hpp:241
Functions that deal with the disassembling of program instructions.