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)
477 if (
pfn ==
nullptr )
480 QASSERT(10183,
seg !=
nullptr);
513 if (
pfn !=
nullptr )
542inline jump_pattern_t::jump_pattern_t(
544 const char (*_depends)[4],
546 : modifying_r32_spoils_r64(true),
549 in_linear_flow(false),
555 regs.resize(last_reg + 1);
559inline bool jump_pattern_t::equal_ops_dtype(
561 const op_t ®)
const
563 if ( !equal_ops(op, reg) )
570 if ( modifying_r32_spoils_r64 && op.
dtype == dt_dword )
573 if ( !is_narrower(extend_dtype(op), reg.
dtype) )
583 return dt2 < dt_2bit && dt1 < dt2;
585 return dt2 < dt_2bit || dt1 < dt2;
589inline int jump_pattern_t::get_dtype_nbits(
op_dtype_t dtype)
593 case dt_byte:
return 8;
594 case dt_word:
return 16;
595 case dt_dword:
return 32;
596 case dt_qword:
return 64;
597 case dt_7bit:
return 7;
598 case dt_6bit:
return 6;
599 case dt_5bit:
return 5;
600 case dt_4bit:
return 4;
601 case dt_3bit:
return 3;
602 case dt_2bit:
return 2;
608inline void jump_pattern_t::check_spoiled_not_reg(
612 uint32 feature = insn.get_canon_feature(PH);
615 for (
uint i = 0; i < maxop; ++i )
618 && insn.ops[i].type !=
o_void
619 && insn.ops[i].type !=
o_reg )
621 set_spoiled(_regs, insn.ops[i]);
627inline void jump_pattern_t::track(
int reg,
int r_i,
op_dtype_t dtype)
629 regs[r_i].type =
o_reg;
631 regs[r_i].dtype = dtype;
633inline void jump_pattern_t::trackop(
const op_t &op,
int r_i)
639inline bool jump_pattern_t::is_equal(
int reg,
int r_i,
op_dtype_t dtype)
645 return is_equal(op, r_i);
647inline bool jump_pattern_t::is_equal(
const op_t &op,
int r_i)
652 stop_matching =
true;
655 return equal_ops_dtype(op, regs[r_i]);
659inline bool jump_pattern_t::same_value(
const op_t &op,
int r_i)
661 return same_value_jpt(
this, op, r_i);
665inline bool jump_pattern_t::track_value_until_address(
op_t *op,
ea_t ea)
667 return track_value_until_address_jpt(
this, op, ea);
675 for (
size_t i = 0; i < _regs.
size(); ++i )
681 for (
size_t i = 0; i < _regs.
size(); ++i )
682 if ( equal_ops(_regs[i], op) )
689template<
class State,
class Ctrl>
695 if ( visited_end ==
nullptr )
721 ctrl.process_delay_slot(ea,
true);
741 if ( prev_ea != BADADDR )
784template<
class State,
class Ctrl>
789 if ( visited_end ==
nullptr )
807template<
class State,
class Ctrl>
819 regs = w->second.regs;
830template<
class State,
class Ctrl>
833 visited_t::iterator v =
visited.upper_bound(ea);
839 if ( ea > v->second )
flags64_t idaapi get_flags32(ea_t ea)
Get only 32 low bits of flags.
Definition bytes.hpp:296
idaman ea_t ida_export prev_not_tail(ea_t ea)
Get address of previous non-tail byte.
A function is a set of continuous ranges of addresses with characteristics.
Definition funcs.hpp:85
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:2250
size_t size(void) const
Get the number of elements in the qvector.
Definition pro.h:2423
Describes a program segment.
Definition segment.hpp:69
idaman func_t *ida_export get_func(ea_t ea)
Get pointer to function structure by address.
bool func_contains(func_t *pfn, ea_t ea)
Does the given function contain the given address?
Definition funcs.hpp:305
THREAD_SAFE bool idaapi is_func(flags64_t F)
Is function start?
Definition bytes.hpp:1969
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:913
THREAD_SAFE constexpr bool idaapi has_xref(flags64_t F)
Does the current byte have cross-references to it?
Definition bytes.hpp:928
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:997
idaman segment_t *ida_export getseg(ea_t ea)
Get pointer to segment by linear 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:7301
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:110
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:7006
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:329
unsigned int uint32
unsigned 32 bit value
Definition pro.h:348
uint8 op_dtype_t
Definition pro.h:460
uint64 ea_t
Definition pro.h:421
unsigned int uint
unsigned 32 bit value
Definition pro.h:339
qvector< ea_t > eavec_t
vector of addresses
Definition pro.h:2764
uint64 flags64_t
64-bit flags for each address
Definition pro.h:5009
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:505
ea_t * find_visited(ea_t ea)
Definition jumptable.hpp:831
cref_t prev_insn()
Definition jumptable.hpp:690
bool only_near
Definition jumptable.hpp:430
no_regs_t & regs
Definition jumptable.hpp:428
cref_t get_waiting()
Definition jumptable.hpp:808
ea_t cur_ea
Definition jumptable.hpp:427
uint max_insn_cnt
Definition jumptable.hpp:431
const segment_t * seg
Definition jumptable.hpp:436
uint insn_cnt
Definition jumptable.hpp:439
func_t * pfn
Definition jumptable.hpp:435
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:493
waiting_t waiting
Definition jumptable.hpp:453
cref_t skip_block()
Definition jumptable.hpp:785
bool check_bounds() const
Definition jumptable.hpp:511
ea_t start_ea
Definition jumptable.hpp:437
Definition jumptable.hpp:521
simple_bfi_t(ea_t ea)
Definition jumptable.hpp:531
no_regs_t regs_
Definition jumptable.hpp:528
static void combine_regs(no_regs_t *, const no_regs_t &, ea_t)
Definition jumptable.hpp:533
backward_flow_iterator_t< no_regs_t, simple_bfi_t > base_t
Definition jumptable.hpp:525
static void process_delay_slot(ea_t &, bool)
Definition jumptable.hpp:534
Information about a switch statement.
Definition nalt.hpp:710
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.